|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* This source file is subject to the GNU General Public License (GPL 3) |
|
7
|
|
|
* that is bundled with this package in the file LICENSE.txt |
|
8
|
|
|
* |
|
9
|
|
|
* DISCLAIMER |
|
10
|
|
|
* |
|
11
|
|
|
* Do not edit or add to this file if you wish to upgrade Payone to newer |
|
12
|
|
|
* versions in the future. If you wish to customize Payone for your |
|
13
|
|
|
* needs please refer to http://www.payone.de for more information. |
|
14
|
|
|
* |
|
15
|
|
|
* @category Payone |
|
16
|
|
|
* @package Payone_Protocol |
|
17
|
|
|
* @subpackage Logger |
|
18
|
|
|
* @copyright Copyright (c) 2012 <[email protected]> - www.noovias.com |
|
19
|
|
|
* @author Matthias Walter <[email protected]> |
|
20
|
|
|
* @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3) |
|
21
|
|
|
* @link http://www.noovias.com |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* This class is a default Implementation for Log4php |
|
26
|
|
|
* |
|
27
|
|
|
* it is used to Log Messages to files and is injected by default |
|
28
|
|
|
* |
|
29
|
|
|
* <pre class="prettyprint"> |
|
30
|
|
|
* $config = array( |
|
31
|
|
|
'filename' => 'payone/exception.log', |
|
32
|
|
|
'max_file_size' => '500KB', |
|
33
|
|
|
'max_file_count' => 10, |
|
34
|
|
|
); |
|
35
|
|
|
* $logger = new Payone_Protocol_Logger_Log4php(); |
|
36
|
|
|
* $logger->log('MESSAGE'); |
|
37
|
|
|
* </pre> |
|
38
|
|
|
* |
|
39
|
|
|
* @category Payone |
|
40
|
|
|
* @package Payone_Protocol |
|
41
|
|
|
* @subpackage Logger |
|
42
|
|
|
* @copyright Copyright (c) 2012 <[email protected]> - www.noovias.com |
|
43
|
|
|
* @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3) |
|
44
|
|
|
* @link http://www.noovias.com |
|
45
|
|
|
*/ |
|
46
|
|
|
class Payone_Protocol_Logger_Log4php |
|
47
|
|
|
implements Payone_Protocol_Logger_Interface |
|
48
|
|
|
{ |
|
49
|
|
|
const KEY = 'p1_log4php'; |
|
50
|
|
|
const LOGGER_APPENDER_NAME = 'Payone_Logger_Log4php_File'; |
|
51
|
|
|
|
|
52
|
|
|
/** @var Payone_Log4php_Logger */ |
|
53
|
|
|
protected $logger = null; |
|
54
|
|
|
|
|
55
|
|
|
/** @var string */ |
|
56
|
|
|
protected $key = self::KEY; |
|
57
|
|
|
|
|
58
|
|
|
/** @var array */ |
|
59
|
|
|
protected $config = array( |
|
60
|
|
|
'filename' => '', |
|
61
|
|
|
'max_file_size' => '1MB', |
|
62
|
|
|
'max_file_count' => 20, |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $config |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __construct(array $config = array()) |
|
70
|
|
|
{ |
|
71
|
|
|
if (count($config)) { |
|
72
|
|
|
$this->setConfig(array_merge($this->getConfig(), $config)); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param $message |
|
78
|
|
|
* @param string $level |
|
79
|
|
|
* @return boolean |
|
80
|
|
|
*/ |
|
81
|
|
|
public function log($message, $level = self::LEVEL_INFO) |
|
82
|
|
|
{ |
|
83
|
|
|
$fileName = $this->getConfigValue('filename'); |
|
84
|
|
|
if (empty($fileName)) { |
|
85
|
|
|
return FALSE; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$sFullLogMessage = date('[Y-m-d H:i:s] ').strtoupper($level).' - '.$message.PHP_EOL; |
|
89
|
|
|
error_log($sFullLogMessage, 3, $fileName); |
|
90
|
|
|
|
|
91
|
|
|
return true; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getKey() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->key; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param array $config |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setConfig(array $config) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->config = $config; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getConfig() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->config; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param string $key |
|
120
|
|
|
* @return mixed|null |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getConfigValue($key = '') |
|
123
|
|
|
{ |
|
124
|
|
|
if (array_key_exists($key, $this->config)) { |
|
125
|
|
|
return $this->config[$key]; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return null; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param string $key |
|
133
|
|
|
* @param $value |
|
134
|
|
|
*/ |
|
135
|
|
|
public function setConfigValue($key, $value) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->config[$key] = $value; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|