diff --git a/doc/develop/en/logger.mc b/doc/develop/en/logger.mc new file mode 100644 index 000000000..812ccac4f --- /dev/null +++ b/doc/develop/en/logger.mc @@ -0,0 +1,18 @@ +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 \ No newline at end of file diff --git a/include/misc.php b/include/misc.php index 562481a5e..16e068cea 100644 --- a/include/misc.php +++ b/include/misc.php @@ -698,22 +698,22 @@ function attribute_contains($attr, $s) } /** - * @brief Logging function for Hubzilla. + * @brief Logging function for Streams. * - * Logging output is configured through Hubzilla's system config. The log file + * Logging output is configured through Streams system config. The log file * is set in system logfile, log level in system loglevel and to enable logging * set system debugging. * * Available constants for log level are LOGGER_NORMAL, LOGGER_TRACE, LOGGER_DEBUG, * LOGGER_DATA and LOGGER_ALL. * - * Since PHP5.4 we get the file, function and line automatically where the logger - * was called, so no need to add it to the message anymore. * * @param string $msg Message to log * @param int $level A log level * @param int $priority - compatible with syslog */ + + function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {