1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137:
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2013-09-13
*/
namespace Net\Bazzline\Component\PsrAndLog4PhpAdapter;
use Exception;
use Logger;
use LoggerLevel;
use Psr\Log\LoggerInterface;
/**
* Class Log4PhpToPsrLoggerAdapter
*
* @package Net\Bazzline\Component\PsrAndLog4PhpAdapter
*/
class Log4PhpToPsrLoggerAdapter extends Logger
{
/** @var LoggerInterface */
private $psrLogger;
/**
* Log4PhpToPsrLoggerAdapter constructor.
*
* @param LoggerInterface $psrLogger
*/
public function injectPsrLogger(LoggerInterface $psrLogger)
{
$this->psrLogger = $psrLogger;
}
/**
* Log a message object with the TRACE level.
*
* @param mixed $message message
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function trace($message, $throwable = null)
{
$this->log(LoggerLevel::getLevelTrace(), $message, $throwable);
}
/**
* Log a message object with the DEBUG level.
*
* @param mixed $message message
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function debug($message, $throwable = null)
{
$this->log(LoggerLevel::getLevelDebug(), $message, $throwable);
}
/**
* Log a message object with the INFO Level.
*
* @param mixed $message message
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function info($message, $throwable = null)
{
$this->log(LoggerLevel::getLevelInfo(), $message, $throwable);
}
/**
* Log a message with the WARN level.
*
* @param mixed $message message
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function warn($message, $throwable = null)
{
$this->log(LoggerLevel::getLevelWarn(), $message, $throwable);
}
/**
* Log a message object with the ERROR level.
*
* @param mixed $message message
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function error($message, $throwable = null)
{
$this->log(LoggerLevel::getLevelError(), $message, $throwable);
}
/**
* Log a message object with the FATAL level.
*
* @param mixed $message message
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function fatal($message, $throwable = null)
{
$this->log(LoggerLevel::getLevelFatal(), $message, $throwable);
}
/**
* Log a message using the provided logging level.
*
* @param LoggerLevel $level The logging level.
* @param mixed $message Message to log.
* @param Exception $throwable Optional throwable information to include
* in the logging event.
*/
public function log(LoggerLevel $level, $message, $throwable = null)
{
switch ($level->toInt()) {
case LoggerLevel::TRACE:
case LoggerLevel::DEBUG:
$this->psrLogger->debug($message);
break;
case LoggerLevel::INFO:
$this->psrLogger->info($message);
break;
case LoggerLevel::WARN:
$this->psrLogger->warning($message);
break;
case LoggerLevel::ERROR:
$this->psrLogger->error($message);
break;
case LoggerLevel::FATAL:
$this->psrLogger->emergency($message);
break;
}
}
}