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

fix: prevent reading log unless we need write it

parent cb0dc2a9
Branches devel
No related tags found
No related merge requests found
Pipeline #8994 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