Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable instantiating logger with format-string #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;
}

}