-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.php
84 lines (72 loc) · 1.64 KB
/
log.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
<?php
/**
* @module log
* @version 2018.10.21, 00:24
*
* Logging module.
*
* ---
* Igor Lilliputten
* mailto: igor at lilliputten dot ru
* http://lilliputten.ru/
*
* Ivan Pushkin
* mailto: iv dot pushk at gmail dot com
*/
/*{{{ Global variables */
$_LOG_FILE = 'log.txt'; // default log file name
$_LOG_ENABLED = false; // set to 'true' for enabling logging
/*}}}*/
function _LOG_INIT ()/*{{{*/
{
global $CONFIG, $_LOG_ENABLED, $_LOG_FILE;
if ( !empty($CONFIG['log']) ) {
$_LOG_ENABLED = true;
}
if ( !empty($CONFIG['logFile']) ) {
$_LOG_FILE = $CONFIG['logFile'];
}
if ( !empty($CONFIG['setTimezone']) ) {
date_default_timezone_set($CONFIG['setTimezone']);
}
if ( !empty($CONFIG['logClear']) ) {
_LOG_CLEAR();
}
if ( !empty($CONFIG['verbose']) ) {
_LOG_VAR('CONFIG', $CONFIG);
}
}/*}}}*/
function _LOG_CLEAR ()/*{{{*/
{
global $_LOG_FILE;
if ( !empty($GLOBALS['_LOG_ENABLED']) ) {
if ( is_file($_LOG_FILE) ) {
unlink($_LOG_FILE);
}
}
}/*}}}*/
function _LOG ($s)/*{{{*/
{
if ( !empty($GLOBALS['_LOG_ENABLED']) ) {
$datetime = date('Y.m.d H:i:s');
file_put_contents($GLOBALS['_LOG_FILE'], $datetime."\t".$s."\n", FILE_APPEND | LOCK_EX);
flush();
}
}/*}}}*/
function _LOG_VAR ($s,$p)/*{{{*/
{
_LOG($s.': '.var_export($p,true));
}/*}}}*/
function _ERROR ($s)/*{{{*/
{
_LOG('ERROR: '.$s);
}/*}}}*/
function _DEBUG ($s)/*{{{*/
{
global $CONFIG;
_LOG('DEBUG: '.$s);
}/*}}}*/
function _DEBUG_VAR ($s,$p)/*{{{*/
{
_DEBUG($s.': '.var_export($p,true)); // print_r($p,true));
}/*}}}*/