-
Notifications
You must be signed in to change notification settings - Fork 0
/
fz_log.php
52 lines (41 loc) · 1.3 KB
/
fz_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
<?php
/**
* @file
* This file log the messages of Filez.
*
* Long description.
*
* @package FileZ
*/
define ('FZ_LOG_DEBUG', 'debug');
define ('FZ_LOG_ERROR', 'error');
define ('FZ_LOG_CRON', 'cron');
define ('FZ_LOG_CRON_ERROR', 'cron-error');
function fz_log ($message, $type = null, $vars = null) {
if ($type == FZ_LOG_DEBUG && option ('debug') !== true)
return;
if ($type !== null)
$type = '-'.$type;
$message = trim ($message);
if ($vars !== null)
$message .= var_export ($vars, true)."\n";
$message = str_replace("\n", "\n ", $message);
$message = '['.strftime ('%F %T').'] '
.str_pad ('['.$_SERVER["REMOTE_ADDR"].']', 18)
.$message."\n";
if (fz_config_get ('app', 'log_dir') !== null) {
$log_file = fz_config_get ('app', 'log_dir').'/filez'.$type.'.log';
if (file_put_contents ($log_file, $message, FILE_APPEND) === false) {
trigger_error('Can\'t open log file ('.$log_file.')', E_USER_WARNING);
}
}
if (option ('debug') === true)
debug_msg ($message);
}
function debug_msg ($message) {
$messages = option ('debug_msg');
if (! is_array ($messages))
$messages = array ();
$messages [] = $message;
option ('debug_msg', $messages);
}