Skip to content

Commit

Permalink
Add logLevel option
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtak-CZ committed Oct 5, 2013
1 parent ee069f7 commit 4621a0c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ newrelic:
license: yourLicenseCode #optional
disable: YES #optional - force disable
actionKey: action # default - optional - action parameter name
logLevel: #defaults
- critical
- error

# optional options with default values
rum:
Expand Down
8 changes: 7 additions & 1 deletion src/VrtakCZ/NewRelic/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Extension extends \Nette\Config\CompilerExtension

/** @var array */
public $defaults = array(
'logLevel' => array(
\Nette\Diagnostics\Logger::ERROR,
\Nette\Diagnostics\Logger::CRITICAL,
),
'rum' => array(
'autoEnable' => TRUE,
),
Expand Down Expand Up @@ -90,7 +94,9 @@ public function afterCompile(ClassType $class)
}

// Logger
$initialize->addBody('$newRelicLogger = new \VrtakCZ\NewRelic\Logger;');
$initialize->addBody('$newRelicLogger = new \VrtakCZ\NewRelic\Logger(?);', array(
array_unique($config['logLevel'])
));
$initialize->addBody('\Nette\Diagnostics\Debugger::$logger = $newRelicLogger;');

// Options
Expand Down
12 changes: 10 additions & 2 deletions src/VrtakCZ/NewRelic/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

class Logger extends \Nette\Diagnostics\Logger
{
public function __construct()
/** @var array */
private $logLevel;

/**
* @param array
*/
public function __construct(array $logLevel)
{
$oldLogger = Debugger::$logger;
static::$emailSnooze =& $oldLogger::$emailSnooze;
$this->mailer =& $oldLogger->mailer;
$this->directory =& $oldLogger->directory;
$this->email =& $oldLogger->email;

$this->logLevel = $logLevel;
}

/**
Expand All @@ -24,7 +32,7 @@ public function log($message, $priority = self::INFO)
{
$res = parent::log($message, $priority);

if (in_array($priority, array(self::ERROR, self::CRITICAL))) {
if (in_array($priority, $this->logLevel)) {
if (is_array($message)) {
$message = implode(' ', $message);
}
Expand Down

0 comments on commit 4621a0c

Please sign in to comment.