Console (logger) - graphidev/WOK GitHub Wiki
The Console class allow you to register some logs, event for notices, deprecated elements, debug or errors. It does not require any construct method. Console has only static methods which can be called in any time.
Logs registration
By default, the logs are registered in /var/logs. They are register according to there type : error, fatal, debug and deprecated logs are registered in separates files. The other are registered in the default.log file.
A new directory is created each day with the following name : /YYYY-MM-DD
Predefined log types
There are 6 different log types (they are defined as constants LOG_XXX):
- DEFAULT & NOTICE : default log
- DEBUG : Used to debug the program
- DEPRECATED : Note the developpers that some codes should not be used anymore
- WARNING : Error log but where the running script should not stop
- ERROR : Really important error
Furthermore, there is a special log type called "FATAL". The defined type is keeped but a specific log file will be created. This type will be called when the class stop the running script and called a 503 Response.
Methods
Please note that logs are added to a queue. They are registered at the end of the bootstrap script. IF you exit the script before, the logs will not be registered at all.
Each log is saved with the following structure :
[:time] [:type] :log
Console::log
The default log method allow you to call any kind of log. Specific log methods will works in the same way.
Warning : If the CONSOLE_HANDLER_LEVEL is not set to false, the console will handle PHP errors. That's why it is adivised to use native PHP function trigger_error() instead of the console methods (they will automatically be called)
Console::log($log, $type = self::LOG_DEFAULT, $exit = false);
- $log (string) : note about the current log.
- $type (string) : the log type (use a default constant or a custom type)
- $exit (boolean) : Is the running script must be stopped. if true, a 503 Response will be called
Note that the stopping the running script will register a FATAL log.
Specifics logs methods
Console::debug($log, $exit = false);
Console::notice($log);
Console::deprecated($log);
Console::warning($log);
Console::error($log);
Console::fatal($log);
The error method will no stop the running script. It only generate an error log
The fatal method will always generate and ERROR log and stop the running script
Send logs by e-mail
It is now a parameter that you can found in the settings.php file.