Last active
October 24, 2017 09:43
-
-
Save ruizfrontend/4b15b8ee6a4b3164603c to your computer and use it in GitHub Desktop.
Silex monolog dual configuration
This file contains hidden or 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 | |
// general settings | |
error_reporting(0); | |
ErrorHandler::register(false); | |
$app->register(new Silex\Provider\MonologServiceProvider(), array( | |
'monolog.logfile' => './log.log' | |
)); | |
// in debug mode add log to file | |
if($app['debug'] && isset($app['config']['log']) && $app['config']['log'] != false) { | |
error_reporting(-1); | |
ErrorHandler::register(); | |
$app['monolog.log'] = $app->share(function ($app) { | |
// base handler | |
$log = new $app['monolog.logger.class']('log'); | |
$log->pushHandler($app['monolog.handler']); | |
return $log; | |
}); | |
// Log app init | |
$app['monolog.log']->addDebug('----BOOTSTRAPING APP----'); | |
} | |
// Log to the cloud for notificacions | |
$app['monolog.cloud'] = $app->share(function ($app) { | |
$log = new $app['monolog.logger.class']('cloud'); | |
// Set the format | |
$output = "%channel%.%level_name%: %message%"; | |
$formatter = new LineFormatter($output); | |
// Setup the logger | |
$syslogHandler = new SyslogUdpHandler("XXX.papertrailapp.com", XXX); | |
$syslogHandler->setFormatter($formatter); | |
$log->pushHandler($syslogHandler); | |
return $log; | |
}); | |
// some examples | |
$app['monolog.log']->addError('Log an error to the logfile'); | |
$app['monolog.log']->addWarning('Log a warning to the logfile'); | |
$app['monolog.cloud']->addError('Log an error to the cloud'); | |
$app['monolog']->addError('Log an error everywhere'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment