smsq/includes/logging.php

44 lines
900 B
PHP
Raw Permalink Normal View History

2017-11-15 05:23:00 +01:00
<?php
/*
* Configuration :
* // Log file
* $log_file='/path/to/app.log';
*
* // Log level (DEBUG / INFO / WARNING / ERROR)
* $log_level='INFO';
*/
// Log file descriptor (Do not change !!!)
$_log_file_fd=null;
// Log Levels
$_log_levels=array(
'DEBUG' => 0,
'INFO' => 1,
'WARNING' => 2,
'ERROR' => 3,
);
function logging($level,$message) {
global $log_file, $_log_file_fd, $_log_levels, $log_level;
if (!array_key_exists($level, $_log_levels)) $level=='INFO';
$level_id=$_log_levels[$level];
if (!array_key_exists($log_level, $_log_levels)) $log_level=='INFO';
$log_level_id=$_log_levels[$log_level];
if ($level_id<$log_level_id) return true;
if(is_null($_log_file_fd)) {
$_log_file_fd=fopen($log_file,'a');
}
$msg=date('Y/m/d H:i:s').' - '.$_SERVER['REQUEST_URI'].' - '.$_SERVER['REMOTE_ADDR']." - $level - $message\n";
fwrite($_log_file_fd,$msg);
return true;
}