Compare commits

..

No commits in common. "b2abbaa10c888cb9b6320b2149d42fc35c33405b" and "c55e29d1fa6caef6018dd6e17e511f2d949b6079" have entirely different histories.

View file

@ -19,12 +19,6 @@ class Log {
*/ */
protected static $file_fd = null; protected static $file_fd = null;
/**
* PHP error_log() fallback if no filepath configured or fail to open log file
* @var bool
*/
protected static $error_log_fallback = true;
/* /*
* Log Levels * Log Levels
* @var array(string,int) * @var array(string,int)
@ -83,9 +77,6 @@ class Log {
else else
self :: $filepath = App::get('log.file_path'); self :: $filepath = App::get('log.file_path');
// PHP error_log() fallback
self :: $error_log_fallback = App::get('log.error_log_fallback', true, 'bool');
// Set log level // Set log level
self :: set_level($level?$level:App::get('log.level')); self :: set_level($level?$level:App::get('log.level'));
@ -133,20 +124,6 @@ class Log {
set_exception_handler(array('EesyPHP\\Log', 'exception')); set_exception_handler(array('EesyPHP\\Log', 'exception'));
} }
/**
* Get remote IP address
* @return string
*/
public static function get_remote_addr(){
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
if (array_key_exists('REMOTE_ADDR', $_SERVER))
return $_SERVER["REMOTE_ADDR"];
if (array_key_exists('HTTP_CLIENT_IP', $_SERVER))
return $_SERVER["HTTP_CLIENT_IP"];
return '';
}
/** /**
* Log a message * Log a message
* @param string $level The message level (key of self :: $levels) * @param string $level The message level (key of self :: $levels)
@ -161,8 +138,6 @@ class Log {
if (self :: $levels[$level] < self :: $levels[self :: $level]) return true; if (self :: $levels[$level] < self :: $levels[self :: $level]) return true;
if(self :: $filepath && is_null(self :: $file_fd)) { if(self :: $filepath && is_null(self :: $file_fd)) {
self :: $file_fd = fopen(self :: $filepath, 'a'); self :: $file_fd = fopen(self :: $filepath, 'a');
if (self :: $file_fd)
self :: error('Fail to open log file (%s)', self :: $filepath);
} }
// Extra arguments passed, format message using sprintf // Extra arguments passed, format message using sprintf
@ -185,7 +160,7 @@ class Log {
$msg = array( $msg = array(
date('Y/m/d H:i:s'), date('Y/m/d H:i:s'),
$_SERVER['REQUEST_URI'], $_SERVER['REQUEST_URI'],
self :: get_remote_addr(), $_SERVER['REMOTE_ADDR'],
); );
if (Auth::enabled()) if (Auth::enabled())
$msg[] = (Auth::user()?Auth::user():'anonymous'); $msg[] = (Auth::user()?Auth::user():'anonymous');
@ -195,8 +170,6 @@ class Log {
} }
if (self :: $file_fd) if (self :: $file_fd)
fwrite(self :: $file_fd, $msg); fwrite(self :: $file_fd, $msg);
elseif (self :: $error_log_fallback)
error_log($msg);
if ($level == 'FATAL') if ($level == 'FATAL')
if (!is_null(self :: $fatal_error_handler)) if (!is_null(self :: $fatal_error_handler))