-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathYooMoneyLogger.php
50 lines (39 loc) · 1.21 KB
/
YooMoneyLogger.php
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
<?php
class YooMoneyLogger
{
const MESSAGE_TYPE = 3;
const LEVEL_INFO = 'info';
const LEVEL_WARNING = 'warning';
const LEVEL_ERROR = 'error';
public static function info($message)
{
self::log(self::LEVEL_INFO, $message);
}
public static function error($message)
{
self::log(self::LEVEL_ERROR, $message);
}
public static function warning($message)
{
self::log(self::LEVEL_ERROR, $message);
}
public static function log($level, $message)
{
$path = variable_get('file_public_path', conf_path() .'/files');
$filePath = $path.'/ym-checkout-debug.log';
$isDebugEnabled = variable_get('yoomoney_api_debug', 0);
if ($isDebugEnabled) {
if ( ! file_exists($filePath)) {
touch($filePath);
chmod($filePath, 0644);
}
$messageFormatted = self::formatMessage($level, $message);
error_log($messageFormatted, self::MESSAGE_TYPE, $filePath);
}
}
private static function formatMessage($level, $message)
{
$date = date('Y-m-d H:i:s');
return sprintf("[%s] [%s] Message: %s \r\n", $date, $level, $message);
}
}