-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from rantonmattei/monologger
Made a 'create' factory method instead of inheriting from \Monolog\Lo…
- Loading branch information
Showing
2 changed files
with
19 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,11 @@ | |
/** | ||
* Module class that manages Monolog Logger object | ||
* @see Monolog\Logger | ||
* @see Monolog\Registry | ||
* | ||
* @todo remove inheritance. There is no need to extend Logger | ||
* @author Raphael Antonmattei <[email protected]> | ||
*/ | ||
class MonoLogger extends Logger | ||
class MonoLogger | ||
{ | ||
/** | ||
* Config class that holds options for all registered loggers | ||
|
@@ -24,7 +24,7 @@ class MonoLogger extends Logger | |
protected static $config = null; | ||
|
||
/** | ||
* Instantiate a new MonoLogger object | ||
* Create a new Logger object and push it to the registry | ||
* | ||
* @see Monolog\Logger::__construct | ||
* | ||
|
@@ -34,8 +34,10 @@ class MonoLogger extends Logger | |
* @param callable[] $processors Optional array of processors | ||
* | ||
* @throws \InvalidArgumentException: if no name is given | ||
* | ||
* @return Monolog\Logger newly created Logger | ||
*/ | ||
public function __construct( | ||
public static function createLogger( | ||
$name, | ||
array $handlers = array(), | ||
array $processors = array() | ||
|
@@ -45,8 +47,10 @@ public function __construct( | |
throw new \InvalidArgumentException('Logger name is required.'); | ||
} | ||
|
||
parent::__construct($name, $handlers, $processors); | ||
Registry::addLogger($this); | ||
$logger = new Logger($name, $handlers, $processors); | ||
Registry::addLogger($logger); | ||
|
||
return $logger; | ||
} | ||
|
||
/** | ||
|
@@ -58,7 +62,7 @@ public function __construct( | |
*/ | ||
public static function getLogger($name) | ||
{ | ||
return Registry::hasLogger($name) ? Registry::getInstance($name) : new MonoLogger($name); | ||
return Registry::hasLogger($name) ? Registry::getInstance($name) : self::createLogger($name); | ||
} | ||
|
||
/** | ||
|
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