1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2018 |
6
|
|
|
* @package MW |
7
|
|
|
* @subpackage Logger |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MW\Logger; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Log messages using Zend\Log. |
16
|
|
|
* |
17
|
|
|
* @package MW |
18
|
|
|
* @subpackage Logger |
19
|
|
|
*/ |
20
|
|
|
class Zend2 extends \Aimeos\MW\Logger\Base implements \Aimeos\MW\Logger\Iface |
21
|
|
|
{ |
22
|
|
|
private $logger = null; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Initializes the logger object. |
27
|
|
|
* |
28
|
|
|
* @param \Zend\Log\Logger $logger Zend logger object |
29
|
|
|
*/ |
30
|
|
|
public function __construct( \Zend\Log\Logger $logger ) |
31
|
|
|
{ |
32
|
|
|
$this->logger = $logger; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Writes a message to the configured log facility. |
38
|
|
|
* |
39
|
|
|
* @param string|array|object $message Message text that should be written to the log facility |
40
|
|
|
* @param integer $priority Priority of the message for filtering |
41
|
|
|
* @param string $facility Facility for logging different types of messages (e.g. message, auth, user, changelog) |
42
|
|
|
* @throws \Aimeos\MW\Logger\Exception If an error occurs in Zend_Log |
43
|
|
|
* @see \Aimeos\MW\Logger\Base for available log level constants |
44
|
|
|
*/ |
45
|
|
|
public function log( $message, $priority = \Aimeos\MW\Logger\Base::ERR, $facility = 'message' ) |
46
|
|
|
{ |
47
|
|
|
try |
48
|
|
|
{ |
49
|
|
|
if( !is_scalar( $message ) ) { |
50
|
|
|
$message = json_encode( $message ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->logger->log( $priority, '<' . $facility . '> ' . $message ); |
54
|
|
|
} |
55
|
|
|
catch( \Zend\Log\Exception\InvalidArgumentException $ze ) { |
56
|
|
|
throw new \Aimeos\MW\Logger\Exception( $ze->getMessage() ); |
57
|
|
|
} |
58
|
|
|
catch( \Zend\Log\Exception\RuntimeException $ze ) { |
59
|
|
|
throw new \Aimeos\MW\Logger\Exception( $ze->getMessage() ); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |