llms_log( mixed $message, string $handle = 'llms' )
Log arbitrary messages to a log file
Parameters Parameters
- $message
-
(mixed) (Required) Data to log.
- $handle
-
(string) (Optional) Allow creation of multiple log files by handle.
Default value: 'llms'
Return Return
(boolean)
Source Source
File: includes/functions/llms.functions.log.php
function llms_log( $message, $handle = 'llms' ) {
/**
* Filter a log data before it's written to the logger.
*
* This hook filters the log message in its raw format which may be a string, object, or array. To
* filter the final log message after string conversion, use `llms_log_message_string`.
*
* @since 4.12.0
*
* @see llms_log_message_string
*
* @param mixed $message Data to log.
* @param string $handle Allow creation of multiple log files by handle.
*/
$message = apply_filters( 'llms_log_message', $message, $handle );
$ret = false;
$fh = fopen( llms_get_log_path( $handle ), 'a' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen
// Open the file (creates it if it doesn't already exist).
if ( $fh ) {
$message = is_array( $message ) || is_object( $message ) ? print_r( $message, true ) : $message; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- This is intentional.
/**
* Filter a log message before it's written to the logger.
*
* This hook filters the log message in its final string format To filter the log message
* before string conversion, use `llms_log_message`.
*
* @since 6.4.0
*
* @see llms_log_message
*
* @param string $message Log message string.
* @param string $handle Allow creation of multiple log files by handle.
*/
$message = apply_filters( 'llms_log_message_string', $message, $handle );
$ret = fwrite( $fh, gmdate( 'Y-m-d H:i:s' ) . ' - ' . $message . "\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
fclose( $fh ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
}
return $ret ? true : false;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.7.5 | Unknown. |
| 1.0.0 | Introduced. |