From 3cc7c812e81404ad4a28b845fe61626d079be6f6 Mon Sep 17 00:00:00 2001 From: Max Nuding <max.nuding@icloud.com> Date: Tue, 13 May 2025 07:13:04 +0200 Subject: [PATCH] add more logging options --- src/APnutI.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/APnutI.php b/src/APnutI.php index dcd1893..6f0bdca 100644 --- a/src/APnutI.php +++ b/src/APnutI.php @@ -16,6 +16,8 @@ use APnutI\Exceptions\PollAccessRestrictedException; use APnutI\Meta; use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; +use Monolog\Handler\StreamHandler; +use Monolog\Handler\SyslogHandler; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -78,7 +80,10 @@ class APnutI ?string $app_name = null, ?string $redirect_uri = null, ?string $log_path = null, - $log_level = null + string|int|null $log_level = null, + bool $use_rotating_file_handler = true, + bool $use_stream_handler = false, + bool $use_syslog_handler = false, ) { if (!empty($app_name)) { $this->app_name = $app_name; @@ -93,8 +98,18 @@ class APnutI : new Logger($this->app_name); $this->token_session_key = $this->app_name . 'access_token'; $this->token_redirect_after_auth = $this->app_name . 'redirect_after_auth'; - $handler = new RotatingFileHandler($log_path, 5, $log_level, true); - $this->logger->pushHandler($handler); + if ($use_rotating_file_handler) { + $handler = new RotatingFileHandler($log_path, 5, $log_level, true); + $this->logger->pushHandler($handler); + } + if ($use_stream_handler) { + $handler = new StreamHandler($log_path, $log_level, true); + $this->logger->pushHandler($handler); + } + if ($use_syslog_handler) { + $handler = new SyslogHandler($this->app_name, \LOG_USER, $log_level, true); + $this->logger->pushHandler($handler); + } $this->server_token = null; $this->logger->debug('__construct API'); if (isset($_SESSION[$this->token_session_key])) {