-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoggerService.php
executable file
·96 lines (81 loc) · 2.85 KB
/
LoggerService.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
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
use Psr\Log\LogLevel;
class LoggerService implements Psr\Log\LoggerInterface
{
private $folder = '';
public function makeFolder($path = '') {
if($path == '') {
return false;
}
if (!file_exists($path)) {
mkdir($path, 0755, true);
}
}
public function setPatch($path) {
self::makeFolder($path);
$this->folder = $path;
}
/**
* @inheritDoc
*/
public function emergency(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::EMERGENCY . ': ' . var_export($context, true) . "\n" . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function alert(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::ALERT . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function critical(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::CRITICAL . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function error(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::ERROR . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function warning(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::WARNING . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function notice(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::NOTICE . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function info(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::INFO . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function debug(array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d H:i:s') . ' ' . LogLevel::DEBUG . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
/**
* @inheritDoc
*/
public function log($level, $message, array $context = array())
{
file_put_contents($this->folder . 'log'.date('Y:m:d').'.txt', date('Y:m:d') . ' ' . $level . ': ' . $message . ': ' . var_export($context, true) . "\n", FILE_APPEND);
}
}