From f71b81fe6b3c2e2fbaab290fd82bba9632095e7d Mon Sep 17 00:00:00 2001 From: Jean Paul Galea Date: Thu, 10 Sep 2015 20:17:22 +0200 Subject: [PATCH] Refactor. - init variables as class property, no need to init in construct. - set scopes on private properties, and public methods. --- ykval-log.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/ykval-log.php b/ykval-log.php index ba332f1..f6d949a 100644 --- a/ykval-log.php +++ b/ykval-log.php @@ -29,31 +29,32 @@ class Log { - function __construct($name='ykval') + private $log_levels = array( + LOG_EMERG => 'LOG_EMERG', + LOG_ALERT => 'LOG_ALERT', + LOG_CRIT => 'LOG_CRIT', + LOG_ERR => 'LOG_ERR', + LOG_WARNING => 'LOG_WARNING', + LOG_NOTICE => 'LOG_NOTICE', + LOG_INFO => 'LOG_INFO', + LOG_DEBUG => 'LOG_DEBUG', + ); + + private $fields = array(); + + public function __construct ($name = 'ykval') { $this->name = $name; - $this->fields = array(); - - $this->LOG_LEVELS = array( - LOG_EMERG => 'LOG_EMERG', - LOG_ALERT => 'LOG_ALERT', - LOG_CRIT => 'LOG_CRIT', - LOG_ERR => 'LOG_ERR', - LOG_WARNING => 'LOG_WARNING', - LOG_NOTICE => 'LOG_NOTICE', - LOG_INFO => 'LOG_INFO', - LOG_DEBUG => 'LOG_DEBUG' - ); openlog('ykval', LOG_PID, LOG_LOCAL0); } - function addField($name, $value) + public function addField($name, $value) { $this->fields[$name] = $value; } - function log($priority, $message, $arr=null) + public function log ($priority, $message, $arr=null) { if (is_array($arr)) { foreach($arr as $key => $value){ @@ -70,7 +71,7 @@ class Log } syslog($priority, - $this->LOG_LEVELS[$priority] . ':' . + $this->log_levels[$priority] . ':' . $this->name . ':' . $msg_fields . $message);