Created
October 9, 2012 21:38
Revisions
-
jaimerodas revised this gist
Oct 11, 2012 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ <? // Logger class Log { protected $path; protected $format = 'Y-m-d H:i:s'; -
jaimerodas created this gist
Oct 9, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ <? // // Logger // class Log { protected $path; protected $format = 'Y-m-d H:i:s'; protected $enabled = TRUE; public function __construct($p) { $this->path = $p.'/Logs/'; if ( ! is_dir($this->path) OR ! is_writable($this->path)) { $this->enabled = FALSE; } } public function write($msg) { if ($this->enabled === FALSE) { return FALSE; } $filepath = $this->path.date('Y-m-d').'.txt'; $message = ''; echo $msg."\n"; if ( ! file_exists($filepath)) { $newfile = TRUE; $message .= "Registro de ".date('Y-m-d')."\n\n"; } if ( ! $fp = @fopen($filepath, 'a')) { return FALSE; } $message .= date($this->format).' --> '.$msg."\n"; flock($fp, LOCK_EX); fwrite($fp, $message); flock($fp, LOCK_UN); fclose($fp); if (isset($newfile) && $newfile === TRUE) { @chmod($filepath, FILE_WRITE_MODE); } return TRUE; } }