1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Improved logging options and file-naming.

This commit is contained in:
Cameron
2013-06-01 04:36:58 -07:00
parent ae9769f8b4
commit 693b5bea75
2 changed files with 29 additions and 14 deletions

View File

@@ -640,7 +640,7 @@ class e_admin_log
/** /**
* Save Message stack to File. * Save Message stack to File.
*/ */
private function saveToFile($logTitle='') private function saveToFile($logTitle='', $append=false)
{ {
if($this->logFile == null) if($this->logFile == null)
{ {
@@ -664,10 +664,20 @@ class e_admin_log
$text .= date('Y-m-d H:i:s',$m['time'])." \t".str_pad($m['dislevel'],10," ",STR_PAD_RIGHT)."\t".strip_tags($m['message'])."\n"; $text .= date('Y-m-d H:i:s',$m['time'])." \t".str_pad($m['dislevel'],10," ",STR_PAD_RIGHT)."\t".strip_tags($m['message'])."\n";
} }
$date = date('Y-m-d_H-i-s'); $date = ($append == true) ? date('Y-m-d') : date('Y-m-d_H-i-s').'_'.crc32($text);
$fileName = e_LOG.$date."_".$this->logFile.".log"; $fileName = e_LOG.$date."_".$this->logFile.".log";
if(file_put_contents($fileName,$text)) if($append == true)
{
$app = FILE_APPEND;
}
else
{
$app = null;
}
if(file_put_contents($fileName, $text, $app))
{ {
$this->_allMessages = array(); $this->_allMessages = array();
return $this->logFile; return $this->logFile;
@@ -680,17 +690,17 @@ class e_admin_log
/** /**
* Set and enable logging to a file. * Set and save accumulated log to a file.
* Must be set PRIOR to flushMessages(). (which saves the results) * Use addDebug(), addError() or addSuccess() prior to executing.
* @param name without the extension. (ie. data prefix and .log suffix will be added automatically) * @param string name without the extension. (ie. date prefix and .log suffix will be added automatically)
* @param string Title for use inside the Log file
* @param boolean true = append to file, false = new file each save.
*/ */
public function toFile($name,$logTitle='') public function toFile($name,$logTitle='',$append=false)
{ {
$this->logFile = $name; $this->logFile = $name;
$this->saveToFile($logTitle); $this->saveToFile($logTitle,$append);
$this->logFile = null; $this->logFile = null;
} }

View File

@@ -839,7 +839,8 @@ class e_core_session extends e_session
|| (isset($_GET['e-token']) && !$this->checkFormToken($_GET['e-token']))) || (isset($_GET['e-token']) && !$this->checkFormToken($_GET['e-token'])))
{ {
if(defsettrue('e_DEBUG')) if(defsettrue('e_DEBUG'))
{ {
$details = "USER: ".USERNAME."\n";
$details = "HOST: ".$_SERVER['HTTP_HOST']."\n"; $details = "HOST: ".$_SERVER['HTTP_HOST']."\n";
$details .= "REQUEST_URI: ".$_SERVER['REQUEST_URI']."\n"; $details .= "REQUEST_URI: ".$_SERVER['REQUEST_URI']."\n";
$details .= "e-token (POST): ".$_POST['e-token']."\n"; $details .= "e-token (POST): ".$_POST['e-token']."\n";
@@ -852,8 +853,12 @@ class e_core_session extends e_session
// $details .= print_r($_GET,true); // $details .= print_r($_GET,true);
$details .= "\nPlugins:\n"; $details .= "\nPlugins:\n";
$details .= print_r($pref['plug_installed'],true); $details .= print_r($pref['plug_installed'],true);
e107::getAdminLog()->log_event('Unauthorized access!', $details, E_LOG_FATAL); $log = e107::getAdminLog();
$log->addDebug($details);
$log->toFile('Unauthorized_access','Unauthorized access Log', true);
$log->add('Unauthorized access!', $details, E_LOG_FATAL);
// e107::getAdminLog()->log_event('Unauthorized access!', $details, E_LOG_FATAL);
} }
// do not redirect, prevent dead loop, save server resources // do not redirect, prevent dead loop, save server resources
if($die) die('Unauthorized access!'); if($die) die('Unauthorized access!');