Repository navigation
Expand file tree
/
Copy pathProcessor.php
More file actions
96 lines (86 loc) · 2.35 KB
/
Copy pathProcessor.php
File metadata and controls
96 lines (86 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* This file is part of the Koded package.
*
* (c) Mihail Binev <mihail@kodeart.com>
*
* Please view the LICENSE distributed with this source code
* for the full copyright and license information.
*
*/
namespace Koded\Logging\Processors;
/**
* Abstract class Processor for creating a concrete logger implementations.
*
*/
abstract class Processor
{
/**
* @var int Packed integer for all log levels. If not specified, all levels
* are included (by default)
*/
protected int $levels = -1;
/**
* @var string The log message format.
*/
protected string $format = 'timestamp [levelname] message';
/**
* @var string Keeps all formatted log messages in this property.
*/
protected string $formatted = '';
/**
* @param array $settings
*/
public function __construct(array $settings)
{
$this->levels = (int)($settings['levels'] ?? $this->levels);
$this->format = (string)($settings['format'] ?? $this->format);
}
/**
* Receive update from the Log instance.
* This is where the messages are filtered and processed.
*
* @param array{level: int, levelname: string, message: string, timestamp: string} $message
* The message to be processed
*
* @return void
*/
public function update(array $message): void
{
if (($message['level'] ?? -1) & $this->levels) {
$this->process($message);
}
}
/**
* The concrete implementation of the log processor where
* the message is filtered and delivered.
*
* @param array $message
*
* @return void
*/
abstract protected function process(array $message): void;
/**
* Returns all enabled log levels for the processor object.
* See Logger interface constants for all available levels.
*
* -1 Enable all log levels
* 0 Disable logging, the log processor should not be loaded at all
* 1-128 Power of 2 number, for specific log levels
*
* @return int A packed integer for bitwise comparison
*/
public function levels(): int
{
return $this->levels;
}
/**
* Returns all messages as formatted string.
*
* @return string
*/
public function formatted(): string
{
return $this->formatted;
}
}