<?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->setHandlers([$handler]);
			
			// Add dummy log entry
            $logger->error('Test error message at ' . date("h:i:sa"));
        }
    );
}, 1);