blob: caec463f02e98a2ee813159ea5859a8721e1ef3e (
plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<?php
namespace PicoFeed\Logging;
use DateTime;
use DateTimeZone;
/**
* Logging class.
*
* @author Frederic Guillot
*/
class Logger
{
/**
* List of messages.
*
* @static
*
* @var array
*/
private static $messages = array();
/**
* Default timezone.
*
* @static
*
* @var string
*/
private static $timezone = 'UTC';
/**
* Enable or disable logging.
*
* @static
*
* @var bool
*/
public static $enable = false;
/**
* Enable logging.
*
* @static
*/
public static function enable()
{
self::$enable = true;
}
/**
* Add a new message.
*
* @static
*
* @param string $message Message
*/
public static function setMessage($message)
{
if (self::$enable) {
$date = new DateTime('now', new DateTimeZone(self::$timezone));
self::$messages[] = '['.$date->format('Y-m-d H:i:s').'] '.$message;
}
}
/**
* Get all logged messages.
*
* @static
*
* @return array
*/
public static function getMessages()
{
return self::$messages;
}
/**
* Remove all logged messages.
*
* @static
*/
public static function deleteMessages()
{
self::$messages = array();
}
/**
* Set a different timezone.
*
* @static
*
* @see http://php.net/manual/en/timezones.php
*
* @param string $timezone Timezone
*/
public static function setTimeZone($timezone)
{
self::$timezone = $timezone ?: self::$timezone;
}
/**
* Get all messages serialized into a string.
*
* @static
*
* @return string
*/
public static function toString()
{
return implode(PHP_EOL, self::$messages).PHP_EOL;
}
}
|