Created
August 31, 2016 11:44
-
-
Save dimitrystd/1bc0dd3b1fbc0ece11b41b19bd24cc27 to your computer and use it in GitHub Desktop.
Example how to change WP Connector logger configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @link https://www.smartling.com | |
* @since 1.0.0 | |
* @package smartling-logger-extender | |
* Plugin Name: Smartling Logger Extender | |
* Plugin URI: http://nourl.com | |
* Description: Demo plugin which demonstrates how to add external logger to Smartling Wordpress Connector | |
* Version: 1.0 | |
* Author: Smartling | |
* Author URI: https://www.smartling.com | |
* License: GPL-2.0+ | |
* Network: true | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
*/ | |
add_action('plugins_loaded', function () { | |
add_action( | |
'smartling_before_init', | |
function ($di) { | |
$logger = $di->get('logger'); | |
$smartlingPluginPath = $di->getParameter('plugin.dir'); | |
$errorLogFileName = $smartlingPluginPath . '/logs/error-logfile'; | |
// Write only error log entries to the new file | |
$handler = new \Monolog\Handler\StreamHandler($errorLogFileName, 'ERROR'); | |
// Use formatter defined in smartling plugin "inc/config/logger.yml" | |
$handler->setFormatter($di->get('fileLoggerLineFormatter')); | |
$logger->pushHandler($handler); | |
// Add dummy log entry | |
$logger->error('Test error message at ' . date("h:i:sa")); | |
} | |
); | |
}, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment