streams/doc/develop/en/logger.mc
Ray 63689451f2 logger updates
Updates logger comments and adds logger.mc document
2023-02-17 08:55:48 -05:00

18 lines
No EOL
2 KiB
MonkeyC

This is a PHP function called `logger()` that logs messages with various levels of severity to a log file.
Located in the `[basedir]/include/misc.php` file.
The function takes three parameters:
* **$msg**: the message to be logged.
* **$level**: an optional parameter that specifies the level of severity of the message. The default level is **LOGGER_NORMAL**.
* **$priority**: an optional parameter that specifies the priority of the message. The default priority is **LOG_INFO**.
The function first checks whether the _install.log_ file is writable and the current module is _setup_. If so, it sets the **$debugging** flag to true, the **$logfile** to _install.log_, and the **$loglevel** to **LOGGER_ALL**. Otherwise, it reads the **$debugging**, **$loglevel**, and **$logfile** values from the configuration file.
The function then checks whether logging is enabled and whether the level of severity of the message is lower than or equal to the configured logging level. If logging is not enabled or the message severity is too low, the function simply returns without doing anything.
If logging is enabled, the function constructs the log message string by formatting the message with the current date and time, the priority of the message, a unique log ID, and the file name, line number, and function name where the logging call was made. It then creates an array of log information, including the filename, log level, message, priority, and whether the message was successfully logged, and calls the logger hook to allow plugins to modify the log information or perform additional logging. If the logged key in the **$pluginfo** array is not set to _true_ by the hook, the function appends the log message to the log file specified in the configuration.
View the results at **https://[baseurl]/admin/logs/**
Overall, this function provides a flexible and extensible way to log messages to a file with various levels of severity and priority. The use of a hook also allows plugins to modify or augment the logging behavior