Skip to content
Snippets Groups Projects
Verified Commit 93e2eaf5 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

Merge branch 'devel'

parents 88deb535 06f8e198
No related branches found
Tags 1.0.1
No related merge requests found
Pipeline #9011 failed with stages
in 28 seconds
......@@ -11,20 +11,25 @@ class WpdbLogger implements \Psr\Log\LoggerInterface {
private const MAX_LOG_SIZE = 30;
/** @var string[] */
private $log;
private $log = [];
/** @var string */
private $log_name;
public function __construct( string $log_name ) {
$this->log_name = $log_name;
$this->log = json_decode( get_option( $this->log_name, '[]' ) );
if ( ! \is_array( $this->log ) ) {
$this->log = [];
}
}
public function log( $level, $message, array $context = [] ) {
if ( empty( $this->log ) ) {
$this->log = json_decode(
get_option(
$this->log_name,
'[]'
)
);
}
$this->log[] = date( 'Y-m-d G:i:s' ) . sprintf( ': %s', $message );
if ( \count( $this->log ) > self::MAX_LOG_SIZE ) {
array_shift( $this->log );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment