From b059586d08ba700b22e228801f138d9a553d67d6 Mon Sep 17 00:00:00 2001 From: bsdnomad Date: Mon, 15 May 2023 21:04:29 +0300 Subject: [PATCH] Allow broadcasting to a specific log channel (#40) * Allow broadcasting to a specific log channel * Fix check condition * Update src/ConnectionManager.php * Update config/mqtt-client.php --------- Co-authored-by: Namoshek --- config/mqtt-client.php | 4 ++++ src/ConnectionManager.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/config/mqtt-client.php b/config/mqtt-client.php index 8077696..9a2471c 100644 --- a/config/mqtt-client.php +++ b/config/mqtt-client.php @@ -55,6 +55,10 @@ return [ // with the log level as configured. 'enable_logging' => env('MQTT_ENABLE_LOGGING', true), + // Which logging channel to use for logs produced by the MQTT client. + // If left empty, the default log channel or stack is being used. + 'log_channel' => env('MQTT_LOG_CHANNEL', null), + // Defines which repository implementation shall be used. Currently, // only a MemoryRepository is supported. 'repository' => MemoryRepository::class, diff --git a/src/ConnectionManager.php b/src/ConnectionManager.php index 0a887d6..1fa9270 100644 --- a/src/ConnectionManager.php +++ b/src/ConnectionManager.php @@ -139,10 +139,15 @@ class ConnectionManager $cleanSession = (bool) Arr::get($config, 'use_clean_session', true); $repository = Arr::get($config, 'repository', Repository::class); $loggingEnabled = (bool) Arr::get($config, 'enable_logging', true); + $logChannel = Arr::get($config, 'log_channel', null); $settings = $this->buildConnectionSettings(Arr::get($config, 'connection_settings', [])); $repository = $this->application->make($repository); $logger = $loggingEnabled ? $this->application->make('log') : null; + + if($logger && $logChannel) { + $logger = $logger->channel($logChannel); + } $client = new MqttClient($host, $port, $clientId, $protocol, $repository, $logger); $client->connect($settings, $cleanSession);