Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions log.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,28 @@
//! Custom logger
class Log {

// default format string
const DEFAULT_FORMAT = 'r';

protected
//! File name
$file;
$file,
//! format string
$format;

/**
* Write specified text to log file
* @return string
* @param $text string
* @param $format string
**/
function write($text,$format='r') {
function write($text,$format=FALSE) {
$fw=Base::instance();
$current_format = (!$format) ? $this->format : $format;
foreach (preg_split('/\r?\n|\r/',trim($text)) as $line)
$fw->write(
$this->file,
date($format).
date($current_format).
(isset($_SERVER['REMOTE_ADDR'])?
(' ['.$_SERVER['REMOTE_ADDR'].
(($fwd=filter_var($fw->get('HEADERS.X-Forwarded-For'),
Expand All @@ -60,12 +66,14 @@ function erase() {
/**
* Instantiate class
* @param $file string
* @param $format string
**/
function __construct($file) {
function __construct($file,$format=FALSE) {
$fw=Base::instance();
if (!is_dir($dir=$fw->LOGS))
mkdir($dir,Base::MODE,TRUE);
$this->file=$dir.$file;
$this->format = (!$format) ? self::DEFAULT_FORMAT : $format;
}

}