Commit 6c3bed97 by irul

add maximum level of logging to write to logs

1 parent d2114b77
......@@ -20,6 +20,14 @@ class Logger
private $log_handle = null; // Handle to the default log file.
private $_user_log_handle = null; // Handle to the developer specified log file.
private static $log_level = null; // The maximum level of logging to write to logs
private static $log_level_integers = [
'debug' => 8,
'info' => 7,
'warn' => 5,
'error' => 4
]; // Map logging levels to syslog specifications, there's room for the other levels
/**
* This method checks if there is an instance available. If yes it returns its handle otherwise
* create a new instance and return it's handle.
......@@ -32,8 +40,9 @@ class Logger
*
* @static
* */
public static function get_logger($log_path = null, $log_file = null)
public static function get_logger($log_path = null, $log_file = null, $log_level = 'debug')
{
self::$log_level = ($log_level == 'warning') ? 'warn' : $log_level;
if (is_null($log_path)) {
if (!(isset(self::$logger)) || (is_null(self::$logger))) {
self::$logger = new self();
......@@ -160,6 +169,9 @@ class Logger
* */
public function do_write($log_string, $log_source, $log_level = 'debug')
{
if (self::$log_level_integers[$log_level] > self::$log_level_integers[self::$log_level]){
return;
}
$log_string = sprintf("%s [%s] %s -- %s", date(DATESTRING_FULL), str_pad(strtoupper($log_level), 5), $log_string, $log_source);
$log_string = $log_string . PHP_EOL;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!