Pluf Framework

Pluf Framework Commit Details


Date:2010-02-17 14:27:58 (14 years 10 months ago)
Author:Loic d'Anterroches
Branch:develop, master
Commit:e24114fca6452b3cfb832a2bb0f43a15c082d63d
Parents: 873517a31a26c473f20160c4f37f18a18039e7ad
Message:Improved the logging lib with better levels and some utility functions.

Changes:

File differences

src/Pluf/Log.php
5252
5353
5454
55
56
57
58
59
60
61
62
63
5564
5665
5766
5867
5968
60
61
69
70
71
72
6273
6374
6475
......
6879
6980
7081
71
72
82
83
84
85
7386
7487
7588
......
7790
7891
7992
80
93
8194
82
95
8396
8497
8598
......
89102
90103
91104
92
105
93106
94107
95108
......
102115
103116
104117
105
118
106119
107120
108121
......
152165
153166
154167
168
169
170
171
172
173
174
175
176
177
155178
156179
157180
......
192215
193216
194217
218
219
220
221
222
223
224
225
226
227
195228
196229
197230
......
244277
245278
246279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
247345
248346
249347
......
255353
256354
257355
258
356
259357
260358
261359
* the writers are then called to write the data later.
*/
public static $stack = array();
/**
* A simple storage to track stats.
*
* A good example is to store stats and at the end of the request,
* push the info back in the log. You can for example store the
* total time doing SQL or other things like that.
*/
public static $store = array();
/**
* Different log levels.
*/
const ALL = 1;
const DEBUG = 5;
const INFO = 6;
const DEBUG = 3;
const INFO = 4;
const PERF = 5;
const EVENT = 6;
const WARN = 7;
const ERROR = 8;
const FATAL = 9;
* Used to reverse the log level to the string.
*/
public static $reverse = array(1 => 'ALL',
5 => 'DEBUG',
6 => 'INFO',
3 => 'DEBUG',
4 => 'INFO',
5 => 'PERF',
6 => 'EVENT',
7 => 'WARN',
8 => 'ERROR',
9 => 'FATAL');
/**
* Current log level.
*
* By default, set to 6, which is the INFO level.
* By default, logging is not enabled.
*/
public static $level = 6;
public static $level = 10;
/**
* Current message in the assert log.
/**
* Current level of the message in the assert log.
*/
public static $assert_level = 6;
public static $assert_level = 10;
/**
* Log the information in the stack.
private static function _log($level, $message)
{
if (self::$level >= $level and self::$level != 10) {
if (self::$level <= $level and self::$level != 10) {
self::$stack[] = array(microtime(true), $level, $message);
if (!Pluf::f('log_delayed', false)) {
self::flush();
self::_log(self::INFO, $message);
}
public static function perf($message)
{
self::_log(self::PERF, $message);
}
public static function event($message)
{
self::_log(self::EVENT, $message);
}
public static function warn($message)
{
self::_log(self::WARN, $message);
self::_alog(self::INFO, $message);
}
public static function aperf($message)
{
self::_alog(self::PERF, $message);
}
public static function aevent($message)
{
self::_alog(self::EVENT, $message);
}
public static function awarn($message)
{
self::_alog(self::WARN, $message);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_CALLBACK, 'Pluf_Log_assert');
}
/**
* Increment a key in the store.
*
* It automatically creates the key as needed.
*
* @param $key Key to increment
* @param $amount Amount to increase (1)
*/
public static function inc($key, $amount=1)
{
if (!isset(Pluf_Log::$store[$key])) {
Pluf_Log::$store[$key] = 0;
}
Pluf_Log::$store[$key] += $amount;
}
/**
* Set a key in the store.
*
* @param $key Key to set
* @param $value Value to set
*/
public static function set($key, $value)
{
Pluf_Log::$store[$key] = $value;
}
/**
* Get a key from the store.
*
* @param $key Key to set
* @param $value Default value (null)
*/
public static function get($key, $value=null)
{
return (isset(Pluf_Log::$store[$key]))
? Pluf_Log::$store[$key] : $value;
}
/**
* Start the time to track.
*
* @param $key Tracker
*/
public static function stime($key)
{
Pluf_Log::$store['time_tracker_'.$key] = microtime(true);
}
/**
* End the time to track.
*
* @param $key Tracker
* @param $total Tracker to store the total (null)
* @return float Time for this track
*/
public static function etime($key, $total=null)
{
$t = microtime(true) - Pluf_Log::$store['time_tracker_'.$key];
if ($total) {
Pluf_Log::inc('time_tracker_'.$total, $t);
}
return $t;
}
}
/**
*/
function Pluf_Log_assert($file, $line, $code)
{
if (Pluf_Log::$level >= Pluf_Log::$assert_level and
if (Pluf_Log::$level <= Pluf_Log::$assert_level and
Pluf_Log::$level != 10) {
Pluf_Log::$stack[] = array(
microtime(true),
src/Pluf/Log/File.php
5151
5252
5353
54
54
5555
5656
5757
foreach ($stack as $elt) {
$out[] = date(DATE_ISO8601, (int) $elt[0]).' '.
Pluf_Log::$reverse[$elt[1]].': '.
(string) $elt[2];
json_encode($elt[2]);
}
$fp = fopen($file, 'a');
flock($fp, LOCK_EX); // Blocking call.

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.06672s using 13 queries.