Skip to content

Commit

Permalink
Upgrade logger utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jjsaunier committed Mar 20, 2017
1 parent f288d6a commit cff3d31
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Utils/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public static function attachSentry(LoggerFactory $factory, $callbackUrl, $debug
$sentryHandler = new RavenHandler($ravenClient, \Monolog\Logger::ERROR);
$sentryHandler->setFormatter(new LineFormatter('%message% %context% %extra%\n'));
$factory->addHandler($sentryHandler);
$factory->getLogger('app')->pushHandler($sentryHandler);

$decoratedLogger = $factory->getLogger('app');

if($decoratedLogger instanceof \Monolog\Logger){
$decoratedLogger->pushHandler($sentryHandler);
}
}

/**
Expand All @@ -43,7 +48,12 @@ public static function attachSlack(LoggerFactory $factory, $token, $channel, $us

$slackHandler = new SlackHandler($token, $channel, $username, true, null, \Monolog\Logger::ERROR, true, false, true);
$factory->addHandler($slackHandler);
$factory->getLogger('app')->pushHandler($slackHandler);

$decoratedLogger = $factory->getLogger('app');

if($decoratedLogger instanceof \Monolog\Logger){
$decoratedLogger->pushHandler($slackHandler);
}
}

/**
Expand All @@ -56,9 +66,14 @@ public static function attachNewRelic(LoggerFactory $factory, $appName, $debug)
if(true === $debug || !extension_loaded('newrelic')){
return;
}

$newRelicHandler = new NewRelicHandler(\Monolog\Logger::ERROR, true, $appName, true);
$factory->addHandler($newRelicHandler);
$factory->getLogger('app')->pushHandler($newRelicHandler);

$decoratedLogger = $factory->getLogger('app');

if($decoratedLogger instanceof \Monolog\Logger){
$factory->getLogger('app')->pushHandler($newRelicHandler);
}
}
}

0 comments on commit cff3d31

Please sign in to comment.