WooCommerce Code Reference

Search results

WC_Log_Handler_DB extends WC_Log_Handler

Handles log entries by writing to database.

Table of Contents

handle() Handle a log entry. bool
add() Add a log entry to chosen file. bool
flush() Clear all logs from the DB. bool
clear() Clear entries for a chosen handle/source. bool
delete() Delete selected logs from DB. bool
delete_logs_before_timestamp() Delete all logs older than a defined timestamp. mixed
get_log_source() Get appropriate source based on file name. string
format_time() Formats a timestamp for use in log messages. string
format_entry() Builds a log entry text from level, timestamp and message. string

Methods

handle()

Handle a log entry.

public handle( $timestamp : int , $level : string , $message : string , $context : array ) : bool
Parameters
$timestamp : int

Log timestamp.

$level : string

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

$message : string

Log message.

$context : array

{ Additional information for log handlers.

@type string $source Optional. Source will be available in log table.
             If no source is provided, attempt to provide sensible default.

}

Tags
see

for default source.

Return values
bool

False if value was not handled and true if value was handled.

add()

Add a log entry to chosen file.

protected static add( $timestamp : int , $level : string , $message : string , $source : string , $context : array ) : bool
Parameters
$timestamp : int

Log timestamp.

$level : string

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

$message : string

Log message.

$source : string

Log source. Useful for filtering and sorting.

$context : array

Context will be serialized and stored in database.

Return values
bool

True if write was successful.

flush()

Clear all logs from the DB.

public static flush( ) : bool
Return values
bool

True if flush was successful.

clear()

Clear entries for a chosen handle/source.

public clear( $source : string ) : bool
Parameters
$source : string

Log source.

Return values
bool

delete()

Delete selected logs from DB.

public static delete( $log_ids : int|string|array ) : bool
Parameters
$log_ids : int|string|array

Log ID or array of Log IDs to be deleted.

Return values
bool

delete_logs_before_timestamp()

Delete all logs older than a defined timestamp.

public static delete_logs_before_timestamp( $timestamp : int ) : mixed
Parameters
$timestamp : int

Timestamp to delete logs before.

Tags
since
Return values
mixed

get_log_source()

Get appropriate source based on file name.

protected static get_log_source( ) : string

Try to provide an appropriate source in case none is provided.

Return values
string

Text to use as log source. "" (empty string) if none is found.

format_time()

Formats a timestamp for use in log messages.

protected static format_time( $timestamp : int ) : string
Parameters
$timestamp : int

Log timestamp.

Return values
string

Formatted time for use in log entry.

format_entry()

Builds a log entry text from level, timestamp and message.

protected static format_entry( $timestamp : int , $level : string , $message : string , $context : array ) : string
Parameters
$timestamp : int

Log timestamp.

$level : string

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

$message : string

Log message.

$context : array

Additional information for log handlers.

Return values
string

Formatted log entry.

Back to the top