From 728fce1b784412b2237cf5aa08ed22e6962501dd Mon Sep 17 00:00:00 2001 From: Aerex Date: Thu, 11 Jun 2020 11:10:45 -0500 Subject: [PATCH] fix: Created log file if files does not exist --- lib/Logger.php | 13 +++++++++++-- lib/Storages/Taskwarrior.php | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Logger.php b/lib/Logger.php index 3d143f2..7386969 100644 --- a/lib/Logger.php +++ b/lib/Logger.php @@ -9,16 +9,25 @@ class Logger { private $configs = ['enabled' => false]; function __construct($configs, $tag) { - if (isset($configs['logger'])) { - $this->configs = $configs['logger']; + if (isset($configs['general']) && isset($configs['general']['logger'])) { + $this->configs = $configs['general']['logger']; } if ($this->configs['enabled']) { + $this->createLoggerFile(); $this->logger = new Monolog($tag); $logLevel = Monolog::getLevels()[$this->configs['level']]; $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) { if ($this->configs['enabled']) { $this->logger->debug($message); diff --git a/lib/Storages/Taskwarrior.php b/lib/Storages/Taskwarrior.php index d694b4c..aeb82fe 100644 --- a/lib/Storages/Taskwarrior.php +++ b/lib/Storages/Taskwarrior.php @@ -17,7 +17,7 @@ class Taskwarrior implements IStorage { public function __construct($console, $configs) { $this->console = $console; - $this->configs = $configs['taskwarrior']; + $this->configs = $configs['storages']['taskwarrior']; $this->logger = new Logger($configs, 'Taskwarrior'); $this->tz = new CarbonTimeZone($configs['general']['timezone']); } @@ -81,7 +81,7 @@ class Taskwarrior implements IStorage { } 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)) {