fix: Created log file if files does not exist

This commit is contained in:
Aerex 2020-06-11 11:10:45 -05:00
parent c302c4653a
commit 728fce1b78
2 changed files with 13 additions and 4 deletions

View File

@ -9,16 +9,25 @@ class Logger {
private $configs = ['enabled' => false]; private $configs = ['enabled' => false];
function __construct($configs, $tag) { function __construct($configs, $tag) {
if (isset($configs['logger'])) { if (isset($configs['general']) && isset($configs['general']['logger'])) {
$this->configs = $configs['logger']; $this->configs = $configs['general']['logger'];
} }
if ($this->configs['enabled']) { if ($this->configs['enabled']) {
$this->createLoggerFile();
$this->logger = new Monolog($tag); $this->logger = new Monolog($tag);
$logLevel = Monolog::getLevels()[$this->configs['level']]; $logLevel = Monolog::getLevels()[$this->configs['level']];
$this->logger->pushHandler(new StreamHandler($this->configs['file'], $logLevel)); $this->logger->pushHandler(new StreamHandler($this->configs['file'], $logLevel));
} }
} }
private function createLoggerFile() {
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']));
}
}
}
public function debug($message) { public function debug($message) {
if ($this->configs['enabled']) { if ($this->configs['enabled']) {
$this->logger->debug($message); $this->logger->debug($message);

View File

@ -17,7 +17,7 @@ class Taskwarrior implements IStorage {
public function __construct($console, $configs) { public function __construct($console, $configs) {
$this->console = $console; $this->console = $console;
$this->configs = $configs['taskwarrior']; $this->configs = $configs['storages']['taskwarrior'];
$this->logger = new Logger($configs, 'Taskwarrior'); $this->logger = new Logger($configs, 'Taskwarrior');
$this->tz = new CarbonTimeZone($configs['general']['timezone']); $this->tz = new CarbonTimeZone($configs['general']['timezone']);
} }
@ -81,7 +81,7 @@ class Taskwarrior implements IStorage {
} }
if (isset($vtodo->DUE)){ if (isset($vtodo->DUE)){
$task['due'] = new Carbon($vtodo->DUE->getDateTime()->format(\DateTime::W3C)); $task['due'] = new Carbon($vtodo->DUE->getDateTime());
} }
if (isset($vtodo->RRULE)) { if (isset($vtodo->RRULE)) {