From 6c7838a8f689aa1cea660145dcb16cfafa78f15c Mon Sep 17 00:00:00 2001 From: "vladimir.panivko" Date: Tue, 20 Feb 2024 18:12:02 +0100 Subject: [PATCH] Fix error logging to syslog Fix notice in examples --- Log/syslog.php | 2 +- examples/composite.php | 6 +++--- examples/console.php | 2 +- examples/display.php | 2 +- examples/error_log.php | 2 +- examples/file.php | 2 +- examples/firebug.php | 2 +- examples/mail.php | 2 +- examples/null.php | 2 +- examples/observer_mail.php | 2 +- examples/pear_error_handler.php | 2 +- examples/php_error_handler.php | 2 +- examples/sql.php | 2 +- examples/sqlite.php | 4 ++-- examples/syslog.php | 2 +- examples/win.php | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Log/syslog.php b/Log/syslog.php index 6d4f3c0..bbd15ab 100755 --- a/Log/syslog.php +++ b/Log/syslog.php @@ -108,7 +108,7 @@ public function __construct( } $this->id = md5(microtime().random_int(0, mt_getrandmax())); - $this->name = $name; + $this->name = (int)$name; $this->ident = $ident; $this->mask = Log::MAX($level); } diff --git a/examples/composite.php b/examples/composite.php index 08f436e..8b2cf30 100644 --- a/examples/composite.php +++ b/examples/composite.php @@ -2,10 +2,10 @@ require_once 'Log.php'; -$console = &Log::singleton('console', '', 'TEST'); -$file = &Log::singleton('file', 'out.log', 'TEST'); +$console = Log::singleton('console', '', 'TEST'); +$file = Log::singleton('file', 'out.log', 'TEST'); -$composite = &Log::singleton('composite'); +$composite = Log::singleton('composite'); $composite->addChild($console); $composite->addChild($file); diff --git a/examples/console.php b/examples/console.php index 9462f9c..9f2f352 100644 --- a/examples/console.php +++ b/examples/console.php @@ -2,7 +2,7 @@ require_once 'Log.php'; -$logger = &Log::singleton('console', '', 'ident'); +$logger = Log::singleton('console', '', 'ident'); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/display.php b/examples/display.php index f5f297b..806cff3 100755 --- a/examples/display.php +++ b/examples/display.php @@ -6,7 +6,7 @@ 'error_prepend' => '', 'error_append' => '' ]; -$logger = &Log::singleton('display', '', '', $conf, PEAR_LOG_DEBUG); +$logger = Log::singleton('display', '', '', $conf, PEAR_LOG_DEBUG); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/error_log.php b/examples/error_log.php index 446435b..d046206 100644 --- a/examples/error_log.php +++ b/examples/error_log.php @@ -2,7 +2,7 @@ require_once 'Log.php'; -$logger = &Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'ident'); +$logger = Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'ident'); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/file.php b/examples/file.php index ebd64c3..a28ed41 100755 --- a/examples/file.php +++ b/examples/file.php @@ -3,7 +3,7 @@ require_once 'Log.php'; $conf = ['mode' => 0600, 'timeFormat' => '%X %x']; -$logger = &Log::singleton('file', 'out.log', 'ident', $conf); +$logger = Log::singleton('file', 'out.log', 'ident', $conf); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/firebug.php b/examples/firebug.php index 616b7c2..dc1c779 100755 --- a/examples/firebug.php +++ b/examples/firebug.php @@ -2,7 +2,7 @@ require_once 'Log.php'; -$logger = &Log::singleton( +$logger = Log::singleton( 'firebug', '', 'PHP', diff --git a/examples/mail.php b/examples/mail.php index 2c565c4..8c9e746 100755 --- a/examples/mail.php +++ b/examples/mail.php @@ -3,7 +3,7 @@ require_once 'Log.php'; $conf = ['subject' => 'Important Log Events']; -$logger = &Log::singleton('mail', 'webmaster@example.com', 'ident', $conf); +$logger = Log::singleton('mail', 'webmaster@example.com', 'ident', $conf); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/null.php b/examples/null.php index deb8076..5895adf 100644 --- a/examples/null.php +++ b/examples/null.php @@ -2,7 +2,7 @@ require_once 'Log.php'; -$logger = &Log::singleton('null'); +$logger = Log::singleton('null'); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/observer_mail.php b/examples/observer_mail.php index f750f23..ec63ac3 100644 --- a/examples/observer_mail.php +++ b/examples/observer_mail.php @@ -19,7 +19,7 @@ public function __construct($priority, $conf) $this->pattern = $conf['pattern']; } - public function notify($event) + public function notify($event): void { if (preg_match($this->pattern, $event['message']) != 0) { mail($this->to, $this->subject, $event['message']); diff --git a/examples/pear_error_handler.php b/examples/pear_error_handler.php index 988f95e..8d7b5b0 100644 --- a/examples/pear_error_handler.php +++ b/examples/pear_error_handler.php @@ -19,7 +19,7 @@ function errorHandler($error) $logger->log($message, $error->code); } -$logger = &Log::singleton('console', '', 'ident'); +$logger = Log::singleton('console', '', 'ident'); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler'); PEAR::raiseError('This is an information log message.', PEAR_LOG_INFO); diff --git a/examples/php_error_handler.php b/examples/php_error_handler.php index 5ee8bfb..aa8abd6 100644 --- a/examples/php_error_handler.php +++ b/examples/php_error_handler.php @@ -28,7 +28,7 @@ function errorHandler($code, $message, $file, $line) $priority); } -$logger = &Log::singleton('console', '', 'ident'); +$logger = Log::singleton('console', '', 'ident'); set_error_handler('errorHandler'); trigger_error('This is an information log message.', E_USER_NOTICE); diff --git a/examples/sql.php b/examples/sql.php index a6a1d93..88b07d5 100755 --- a/examples/sql.php +++ b/examples/sql.php @@ -3,7 +3,7 @@ require_once 'Log.php'; $conf = ['dsn' => 'pgsql://jon@localhost+unix/logs']; -$logger = &Log::singleton('sql', 'log_table', 'ident', $conf); +$logger = Log::singleton('sql', 'log_table', 'ident', $conf); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/sqlite.php b/examples/sqlite.php index 222da6a..b25bebf 100755 --- a/examples/sqlite.php +++ b/examples/sqlite.php @@ -4,11 +4,11 @@ /* Creating a new database connection. */ $conf = ['filename' => 'log.db', 'mode' => 0666, 'persistent' => true]; -$logger =& Log::factory('sqlite', 'log_table', 'ident', $conf); +$logger = Log::factory('sqlite', 'log_table', 'ident', $conf); $logger->log('logging an event', PEAR_LOG_WARNING); /* Using an existing database connection. */ $db = sqlite_open('log.db', 0666, $error); -$logger =& Log::factory('sqlite', 'log_table', 'ident', $db); +$logger = Log::factory('sqlite', 'log_table', 'ident', $db); $logger->log('logging an event', PEAR_LOG_WARNING); sqlite_close($db); diff --git a/examples/syslog.php b/examples/syslog.php index 288e81c..ea5ce27 100644 --- a/examples/syslog.php +++ b/examples/syslog.php @@ -2,7 +2,7 @@ require_once 'Log.php'; -$logger = &Log::singleton('syslog', LOG_LOCAL0, 'ident'); +$logger = Log::singleton('syslog', LOG_LOCAL0, 'ident'); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); } diff --git a/examples/win.php b/examples/win.php index 4971f12..b515d96 100755 --- a/examples/win.php +++ b/examples/win.php @@ -3,7 +3,7 @@ require_once 'Log.php'; $conf = ['title' => 'Sample Log Output']; -$logger = &Log::singleton('win', 'LogWindow', 'ident', $conf); +$logger = Log::singleton('win', 'LogWindow', 'ident', $conf); for ($i = 0; $i < 10; $i++) { $logger->log("Log entry $i"); }