LoggerFactory
namespace |
bhenk\logger\build |
predicates |
Cloneable | Instantiable |
Static class to create and stock Loggers
This class delegates the creation of loggers (implementing LoggerInterface) to LoggerCreators that will take an array of parameters as build specification. Parameters can be expressed in a configuration file:
{ancestor directory}/config/log_config.php
This class will look for the directory config as a child of an ancestor directory.
Example of a logger configuration file:
<?php
return [
"req" => [
"channel" => "req",
"filename" => "unit/req.log",
"level" => \Psr\Log\LogLevel::DEBUG,
"max_files" => 2,
"filename_format" => "{filename}-{date}",
"filename_date_format" => "Y-m",
"line_format" => "%datetime% %extra%\n",
],
"log" => [
"channel" => "log",
"log_file" => "unit/logger.log",
"log_max_files" => 5,
"log_level" => \Psr\Log\LogLevel::INFO,
"err_file" => "unit/error.log",
"err_max_files" => 5,
"err_level" => \Psr\Log\LogLevel::ERROR,
"format" => "%level_name% | %datetime% | %message% | %context% %extra%\n",
"date_format" => "Y-m-d H:i:s",
"introspection" => true,
],
"clt" => [
"channel" => "clt",
"level" => \Psr\Log\LogLevel::DEBUG,
"bubble" => false,
"white_line" => true,
"stack_match" => "/(application|src)\/(bhenk|unit)/i",
"date_format" => "H:i:s:u",
"exclamation" => "chips!",
"color_scheme" => "bhenk\logger\handle\ColorSchemeDark",
]
];
All parameters are optional.
Constants
LoggerFactory::CONFIG_DIR
predicates |
public |
The ancestor child directory that is expected to hold the log configuration file
string(6) "config"
LoggerFactory::LOG_CONFIG_FILE
predicates |
public |
The expected configuration filename
string(14) "log_config.php"
Methods
LoggerFactory::getConfigFile
predicates |
public | static |
Get the current configuration filename or false if no configuration file was found
public static function getConfigFile(): string|bool
LoggerFactory::setConfigFile
predicates |
public | static |
Set the configuration file
Loads logger definitions from the configuration file.
public static function setConfigFile(
Parameter #0 [ <required> string $config_file ]
): void
LoggerFactory::getLogger
predicates |
public | static |
Get the Logger of the given type
Will get the Logger from stock or tries to create the specified Logger. If anything goes wrong during creation will output an error message to
{ancestor directory}/logs/logger/factory_error.log
public static function getLogger(
Parameter #0 [ <required> bhenk\logger\build\LoggerTypes $type ]
): LoggerInterface
LoggerFactory::getDefinition
predicates |
public | static |
Get the definition for the given type of logger (if any)
public static function getDefinition(
Parameter #0 [ <required> bhenk\logger\build\LoggerTypes $type ]
): array
LoggerFactory::setDefinition
predicates |
public | static |
Set the definition for a given type of logger
public static function setDefinition(
Parameter #0 [ <required> bhenk\logger\build\LoggerTypes $type ]
Parameter #1 [ <optional> array $definition = [] ]
): void
LoggerFactory::isQuiet
predicates |
public | static |
public static function isQuiet(): bool
LoggerFactory::setQuiet
predicates |
public | static |
Sets whether the factory will output error messages to STDERR when creating loggers
public static function setQuiet(
Parameter #0 [ <required> bool $quiet ]
): void
Sat, 29 Apr 2023 12:38:18 +0000