WC_Log_Handler_DB
extends WC_Log_Handler
in package
Handles log entries by writing to database.
Tags
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
clear()
Clear entries for a chosen handle/source.
public
clear(string $source) : bool
Parameters
- $source : string
-
Log source.
Return values
bool —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
Return values
mixed —flush()
Clear all logs from the DB.
public
static flush() : bool
Return values
bool — True if flush was successful.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
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(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
bool — True 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
string — Formatted 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
string — Formatted 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.