Skip to content

Commit

Permalink
Merge pull request #50 from jbroadway/Multiple-loggers
Browse files Browse the repository at this point in the history
Delay setting the handler in Logger so each Logger can have its own handler
  • Loading branch information
lux authored Nov 2, 2023
2 parents 5955293 + 831f8a2 commit c0e16a9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Analog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
* @author Johnny Broadway
*/
class Logger implements LoggerInterface {
private $handler = null;

/**
* Converts from PSR-3 log levels to Analog log levels.
*/
Expand Down Expand Up @@ -130,7 +132,7 @@ private function interpolate ($message, array $context = array ()) {
* Sets the Analog log handler.
*/
public function handler ($handler) {
Analog::handler ($handler);
$this->handler = $handler;
}

/**
Expand Down Expand Up @@ -212,6 +214,10 @@ public function log ($level, $message, array $context = array ()) {
* Perform the logging to Analog after the log level has been converted.
*/
private function _log ($level, $message, $context) {
if ($this->handler != null) {
Analog::handler ($this->handler);
}

Analog::log (
$this->interpolate ($message, $context),
$level
Expand Down

0 comments on commit c0e16a9

Please sign in to comment.