|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2021 |
|
7
|
|
|
* @package MW |
|
8
|
|
|
* @subpackage Logger |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Aimeos\MW\Logger; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Base logger class defining required error level constants |
|
17
|
|
|
* |
|
18
|
|
|
* @package MW |
|
19
|
|
|
* @subpackage Logger |
|
20
|
|
|
*/ |
|
21
|
|
|
trait Traits |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Write as message of severity "emergency" to the log. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
27
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
28
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
29
|
|
|
*/ |
|
30
|
|
|
public function emergency( $message, string $facility = 'message' ) : Iface |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->log( $message, Iface::EMERG, $facility ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Write as message of severity "critical" to the log. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
40
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
41
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
42
|
|
|
*/ |
|
43
|
|
|
public function critical( $message, string $facility = 'message' ) : Iface |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->log( $message, Iface::CRIT, $facility ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Write as message of severity "alert" to the log. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
53
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
54
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
55
|
|
|
*/ |
|
56
|
|
|
public function alert( $message, string $facility = 'message' ) : Iface |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->log( $message, Iface::ALERT, $facility ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Write as message of severity "error" to the log. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
66
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
67
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
68
|
|
|
*/ |
|
69
|
|
|
public function error( $message, string $facility = 'message' ) : Iface |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->log( $message, Iface::ERR, $facility ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Write as message of severity "warning" to the log. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
79
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
80
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
81
|
|
|
*/ |
|
82
|
|
|
public function warning( $message, string $facility = 'message' ) : Iface |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->log( $message, Iface::WARN, $facility ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Write as message of severity "notice" to the log. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
92
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
93
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
94
|
|
|
*/ |
|
95
|
|
|
public function notice( $message, string $facility = 'message' ) : Iface |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->log( $message, Iface::NOTICE, $facility ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Write as message of severity "info" to the log. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
105
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
106
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
107
|
|
|
*/ |
|
108
|
|
|
public function info( $message, string $facility = 'message' ) : Iface |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->log( $message, Iface::INFO, $facility ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Write as message of severity "debug" to the log. |
|
116
|
|
|
* |
|
117
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
118
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
119
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
120
|
|
|
*/ |
|
121
|
|
|
public function debug( $message, string $facility = 'message' ) : Iface |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->log( $message, Iface::DEBUG, $facility ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Checks if the given log constant is valid |
|
129
|
|
|
* |
|
130
|
|
|
* @param int $level Log constant |
|
131
|
|
|
* @return mixed Log level |
|
132
|
|
|
* @throws \Aimeos\MW\Logger\Exception If log constant is unknown |
|
133
|
|
|
*/ |
|
134
|
|
|
protected function getLogLevel( int $level ) |
|
135
|
|
|
{ |
|
136
|
|
|
switch( $level ) |
|
137
|
|
|
{ |
|
138
|
|
|
case Iface::EMERG: return 'emergency'; |
|
139
|
|
|
case Iface::ALERT: return 'alert'; |
|
140
|
|
|
case Iface::CRIT: return 'critical'; |
|
141
|
|
|
case Iface::ERR: return 'error'; |
|
142
|
|
|
case Iface::WARN: return 'warning'; |
|
143
|
|
|
case Iface::NOTICE: return 'notice'; |
|
144
|
|
|
case Iface::INFO: return 'info'; |
|
145
|
|
|
case Iface::DEBUG: return 'debug'; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
throw new \Aimeos\MW\Logger\Exception( sprintf( 'Invalid log level constant "%1$d"', $level ) ); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Writes a message to the configured log facility. |
|
154
|
|
|
* |
|
155
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
|
156
|
|
|
* @param int $prio Priority of the message for filtering |
|
157
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
|
158
|
|
|
* @return \Aimeos\MW\Logger\Iface Logger object for method chaining |
|
159
|
|
|
*/ |
|
160
|
|
|
abstract public function log( $message, int $prio = Iface::ERR, string $facility = 'message' ) : Iface; |
|
161
|
|
|
} |
|
162
|
|
|
|