2020-05-28 11:54:21 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Aerex\BaikalStorage;
|
|
|
|
use Monolog\Logger as Monolog;
|
|
|
|
use Monolog\Handler\StreamHandler;
|
|
|
|
|
|
|
|
class Logger {
|
|
|
|
|
|
|
|
private $configs = ['enabled' => false];
|
|
|
|
|
|
|
|
function __construct($configs, $tag) {
|
2020-06-11 11:10:45 -05:00
|
|
|
if (isset($configs['general']) && isset($configs['general']['logger'])) {
|
|
|
|
$this->configs = $configs['general']['logger'];
|
2020-05-28 11:54:21 -05:00
|
|
|
}
|
|
|
|
if ($this->configs['enabled']) {
|
2020-06-11 11:10:45 -05:00
|
|
|
$this->createLoggerFile();
|
2020-05-28 11:54:21 -05:00
|
|
|
$this->logger = new Monolog($tag);
|
|
|
|
$logLevel = Monolog::getLevels()[$this->configs['level']];
|
|
|
|
$this->logger->pushHandler(new StreamHandler($this->configs['file'], $logLevel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 11:43:56 -05:00
|
|
|
public function createLoggerFile() {
|
2020-06-11 11:10:45 -05:00
|
|
|
if (!file_exists($this->configs['file'])) {
|
|
|
|
if (!fopen($this->configs['file'], 'w')) {
|
|
|
|
throw new \Exception(sprintf('Could not create logger file %s', $this->configs['file']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-28 11:54:21 -05:00
|
|
|
public function debug($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->debug($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function info($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->info($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notice($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->notice($message);
|
|
|
|
}
|
|
|
|
}
|
2020-06-27 00:56:44 -05:00
|
|
|
public function warn($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->warning($message);
|
|
|
|
}
|
|
|
|
}
|
2020-05-28 11:54:21 -05:00
|
|
|
|
|
|
|
public function error($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->error($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function critical($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->critical($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function alert($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->alert($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function emergency($message) {
|
|
|
|
if ($this->configs['enabled']) {
|
|
|
|
$this->logger->emergency($message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|