Database
extends AbstractWriter
in package
Database log writer class
Tags
Table of Contents
Properties
- $db : AbstractAdapter|null
- DB adapter
- $limit : string|null
- Log limit, stored as the canonical PSR-3 level string
- $table : string
- Table
Methods
- __construct() : mixed
- Constructor
- getContext() : string
- Get context for log
- getDb() : AbstractAdapter
- Get DB
- getLogLimit() : string|null
- Get log limit
- getTable() : string
- Get table
- hasLogLimit() : bool
- Has log limit
- isWithinLogLimit() : bool
- Check if a log level is within the set log level limit
- setLogLimit() : AbstractWriter
- Set log limit
- setTable() : Database
- Set table
- writeLog() : Database
- Write to the log
- createTable() : void
- Create table in database
- sanitize() : string
- Strip CR/LF from a value before it's written into a delimited/line-based log format, to prevent an embedded newline from forging a fake extra line (or, for writers that build header-style text like Mail's Subject line, a fake extra header).
Properties
$db
DB adapter
protected
AbstractAdapter|null
$db
= null
$limit
Log limit, stored as the canonical PSR-3 level string
protected
string|null
$limit
= null
$table
Table
protected
string
$table
= 'pop_log'
Methods
__construct()
Constructor
public
__construct(AbstractAdapter $db[, string $table = 'pop_log' ]) : mixed
Instantiate the DB writer object
The DB table requires the following fields at a minimum: timestamp DATETIME level VARCHAR name VARCHAR message TEXT, VARCHAR, etc. context TEXT, VARCHAR, etc.
Parameters
- $db : AbstractAdapter
- $table : string = 'pop_log'
getContext()
Get context for log
public
getContext([array<string|int, mixed> $context = [] ]) : string
Parameters
- $context : array<string|int, mixed> = []
Return values
stringgetDb()
Get DB
public
getDb() : AbstractAdapter
Return values
AbstractAdaptergetLogLimit()
Get log limit
public
getLogLimit() : string|null
Return values
string|nullgetTable()
Get table
public
getTable() : string
Return values
stringhasLogLimit()
Has log limit
public
hasLogLimit() : bool
Return values
boolisWithinLogLimit()
Check if a log level is within the set log level limit
public
isWithinLogLimit(string|int $level) : bool
Parameters
- $level : string|int
Return values
boolsetLogLimit()
Set log limit
public
setLogLimit(string|int $level) : AbstractWriter
Accepts either a PSR-3 level string or a legacy severity int (0-7) for backward compatibility; always normalized and stored as the canonical PSR-3 string.
Parameters
- $level : string|int
Return values
AbstractWritersetTable()
Set table
public
setTable(string $table) : Database
Parameters
- $table : string
Tags
Return values
DatabasewriteLog()
Write to the log
public
writeLog(string $level, string $message[, array<string|int, mixed> $context = [] ]) : Database
Parameters
- $level : string
- $message : string
- $context : array<string|int, mixed> = []
Return values
DatabasecreateTable()
Create table in database
protected
createTable() : void
sanitize()
Strip CR/LF from a value before it's written into a delimited/line-based log format, to prevent an embedded newline from forging a fake extra line (or, for writers that build header-style text like Mail's Subject line, a fake extra header).
protected
sanitize(string $value) : string
Parameters
- $value : string