WooCommerce Code Reference

WC_Logger
in package
implements WC_Logger_Interface

WC_Logger class.

Interfaces, Classes and Traits

WC_Logger_Interface
Logger Interface

Table of Contents

$handlers  : array
Stores registered log handlers.
$threshold  : int
Minimum log level this handler will process.
__construct()  : mixed
Constructor for the logger.
add()  : bool
Add a log entry.
alert()  : mixed
Adds an alert level message.
clear()  : bool
Clear entries for a chosen file/source.
clear_expired_logs()  : mixed
Clear all logs older than a defined number of days. Defaults to 30 days.
critical()  : mixed
Adds a critical level message.
debug()  : mixed
Adds a debug level message.
emergency()  : mixed
Adds an emergency level message.
error()  : mixed
Adds an error level message.
info()  : mixed
Adds a info level message.
log()  : mixed
Add a log entry.
notice()  : mixed
Adds a notice level message.
warning()  : mixed
Adds a warning level message.
should_handle()  : bool
Determine whether to handle or ignore log.

Properties

Methods

__construct()

Constructor for the logger.

public __construct([array $handlers = null ][, string $threshold = null ]) : mixed
Parameters
$handlers : array = null

Optional. Array of log handlers. If $handlers is not provided, the filter 'woocommerce_register_log_handlers' will be used to define the handlers. If $handlers is provided, the filter will not be applied and the handlers will be used directly.

$threshold : string = null

Optional. Define an explicit threshold. May be configured via WC_LOG_THRESHOLD. By default, all logs will be processed.

Return values
mixed

add()

Add a log entry.

public add(string $handle, string $message[, string $level = WC_Log_Levels::NOTICE ]) : bool

This is not the preferred method for adding log messages. Please use log() or any one of the level methods (debug(), info(), etc.). This method may be deprecated in the future.

Parameters
$handle : string

File handle.

$message : string

Message to log.

$level : string = WC_Log_Levels::NOTICE

Logging level.

Return values
bool

alert()

Adds an alert level message.

public alert(string $message[, array $context = array() ]) : mixed

Action must be taken immediately. Example: Entire website down, database unavailable, etc.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

clear()

Clear entries for a chosen file/source.

public clear([string $source = '' ]) : bool
Parameters
$source : string = ''

Source/handle to clear.

Return values
bool

clear_expired_logs()

Clear all logs older than a defined number of days. Defaults to 30 days.

public clear_expired_logs() : mixed
Tags
since
3.4.0
Return values
mixed

critical()

Adds a critical level message.

public critical(string $message[, array $context = array() ]) : mixed

Critical conditions. Example: Application component unavailable, unexpected exception.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

debug()

Adds a debug level message.

public debug(string $message[, array $context = array() ]) : mixed

Detailed debug information.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

emergency()

Adds an emergency level message.

public emergency(string $message[, array $context = array() ]) : mixed

System is unusable.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

error()

Adds an error level message.

public error(string $message[, array $context = array() ]) : mixed

Runtime errors that do not require immediate action but should typically be logged and monitored.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

info()

Adds a info level message.

public info(string $message[, array $context = array() ]) : mixed

Interesting events. Example: User logs in, SQL logs.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

log()

Add a log entry.

public log(string $level, string $message[, array $context = array() ]) : mixed
Parameters
$level : string

One of the following: 'emergency': System is unusable. 'alert': Action must be taken immediately. 'critical': Critical conditions. 'error': Error conditions. 'warning': Warning conditions. 'notice': Normal but significant condition. 'info': Informational messages. 'debug': Debug-level messages.

$message : string

Log message.

$context : array = array()

Optional. Additional information for log handlers.

Return values
mixed

notice()

Adds a notice level message.

public notice(string $message[, array $context = array() ]) : mixed

Normal but significant events.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

warning()

Adds a warning level message.

public warning(string $message[, array $context = array() ]) : mixed

Exceptional occurrences that are not errors.

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Parameters
$message : string

Message to log.

$context : array = array()

Log context.

Tags
see
WC_Logger::log
Return values
mixed

should_handle()

Determine whether to handle or ignore log.

protected should_handle(string $level) : bool
Parameters
$level : string

emergency|alert|critical|error|warning|notice|info|debug.

Return values
boolTrue if the log should be handled.