17 private const AVAILABLE_TYPE = [
21 private const SUPPORTED_LEVEL_LIST = [
31 private const MODULE_ID =
'rest';
32 private const OPTION_LEVEL =
'logger_level';
33 private const OPTION_TYPE =
'logger_type';
34 private const OPTION_FILE_PATH =
'logger_file_path';
35 private const OPTION_ACTIVE =
'logger_active';
36 private const OPTION_ACTIVE_VALUE_Y =
'Y';
37 private const OPTION_ACTIVE_VALUE_N =
'N';
38 private const OPTION_SHOW_ARGUMENTS =
'logger_show_args';
39 private const OPTION_SHOW_ARGUMENTS_VALUE_Y =
'Y';
40 private const OPTION_SHOW_ARGUMENTS_VALUE_N =
'N';
43 private static $instance;
49 private $showArguments;
52 private function __construct()
54 $active = Option::get(self::MODULE_ID,self::OPTION_ACTIVE, self::OPTION_ACTIVE_VALUE_N);
55 $this->
isActive = $active === self::OPTION_ACTIVE_VALUE_Y;
56 $this->level = Option::get(self::MODULE_ID,self::OPTION_LEVEL,
'');
57 $this->type = Option::get(self::MODULE_ID,self::OPTION_TYPE, self::TYPE_FILE);
58 $this->path = Option::get(self::MODULE_ID,self::OPTION_FILE_PATH,
'');
59 $showArguments = Option::get(self::MODULE_ID,self::OPTION_SHOW_ARGUMENTS, self::OPTION_SHOW_ARGUMENTS_VALUE_N);
60 $this->showArguments = $showArguments === self::OPTION_SHOW_ARGUMENTS_VALUE_Y;
63 private function __clone()
74 if (self::$instance ===
null)
79 return self::$instance;
88 return $this->isActive;
98 public function setActive(
bool $active =
false): bool
105 ? self::OPTION_ACTIVE_VALUE_Y
106 : self::OPTION_ACTIVE_VALUE_N
121 $this->showArguments = $show;
126 ? self::OPTION_SHOW_ARGUMENTS_VALUE_Y
127 : self::OPTION_SHOW_ARGUMENTS_VALUE_N
140 return in_array($this->level, self::SUPPORTED_LEVEL_LIST,
true) ? $this->level :
'';
152 if (in_array($level, self::SUPPORTED_LEVEL_LIST,
true))
154 $this->level = $level;
155 Option::set(self::MODULE_ID,self::OPTION_LEVEL, $this->level);
170 public function setType($type = self::TYPE_FILE): bool
172 if (in_array($type, self::AVAILABLE_TYPE,
true))
175 Option::set(self::MODULE_ID,self::OPTION_TYPE, $this->type);
204 Option::set(self::MODULE_ID,self::OPTION_FILE_PATH, $this->path);
232 if ($this->
getType() === self::TYPE_FILE)
246 $this->logger->setLevel($this->
getLevel());
247 $this->logger->setFormatter(
253 return $this->logger;