WooCommerce Code Reference

WC_Log_Handler_DB extends WC_Log_Handler

Handles log entries by writing to database.

Tags
class

WC_Log_Handler_DB

version
1.0.0

Table of Contents

clear()  : bool
Clear entries for a chosen handle/source.
delete()  : bool
Delete selected logs from DB.
delete_logs_before_timestamp()  : mixed
Delete all logs older than a defined timestamp.
flush()  : bool
Clear all logs from the DB.
handle()  : bool
Handle a log entry.
add()  : bool
Add a log entry to chosen file.
format_entry()  : string
Builds a log entry text from level, timestamp and message.
format_time()  : string
Formats a timestamp for use in log messages.
get_backtrace()  : array<string|int, mixed>
Get a backtrace that shows where the logging function was called.
get_log_source()  : string
Get appropriate source based on file name.

Methods

delete()

Delete selected logs from DB.

public static delete(int|string|array<string|int, mixed> $log_ids) : bool
Parameters
$log_ids : int|string|array<string|int, mixed>

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(int $timestamp) : mixed
Parameters
$timestamp : int

Timestamp to delete logs before.

Tags
since
3.4.0
Return values
mixed

handle()

Handle a log entry.

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

Log timestamp.

$level : string

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

$message : string

Log message.

$context : array<string|int, mixed>

{ 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
WC_Log_Handler_DB::get_log_source()

for default source.

Return values
boolFalse if value was not handled and true if value was handled.

add()

Add a log entry to chosen file.

protected static add(int $timestamp, string $level, string $message, string $source, array<string|int, mixed> $context) : 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<string|int, mixed>

Context will be serialized and stored in database.

Return values
boolTrue if write was successful.

format_entry()

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

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

Log timestamp.

$level : string

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

$message : string

Log message.

$context : array<string|int, mixed>

Additional information for log handlers.

Return values
stringFormatted log entry.

format_time()

Formats a timestamp for use in log messages.

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

Log timestamp.

Return values
stringFormatted time for use in log entry.

get_backtrace()

Get a backtrace that shows where the logging function was called.

protected static get_backtrace() : array<string|int, mixed>
Return values
array<string|int, 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
stringText to use as log source. "" (empty string) if none is found.