Skip to content

Commit b059586

Browse files
bsdnomadNamoshek
andauthored
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 <[email protected]>
1 parent 0669643 commit b059586

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

config/mqtt-client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
// with the log level as configured.
5656
'enable_logging' => env('MQTT_ENABLE_LOGGING', true),
5757

58+
// Which logging channel to use for logs produced by the MQTT client.
59+
// If left empty, the default log channel or stack is being used.
60+
'log_channel' => env('MQTT_LOG_CHANNEL', null),
61+
5862
// Defines which repository implementation shall be used. Currently,
5963
// only a MemoryRepository is supported.
6064
'repository' => MemoryRepository::class,

src/ConnectionManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,15 @@ protected function createConnection(string $name): MqttClientContract
139139
$cleanSession = (bool) Arr::get($config, 'use_clean_session', true);
140140
$repository = Arr::get($config, 'repository', Repository::class);
141141
$loggingEnabled = (bool) Arr::get($config, 'enable_logging', true);
142+
$logChannel = Arr::get($config, 'log_channel', null);
142143

143144
$settings = $this->buildConnectionSettings(Arr::get($config, 'connection_settings', []));
144145
$repository = $this->application->make($repository);
145146
$logger = $loggingEnabled ? $this->application->make('log') : null;
147+
148+
if($logger && $logChannel) {
149+
$logger = $logger->channel($logChannel);
150+
}
146151

147152
$client = new MqttClient($host, $port, $clientId, $protocol, $repository, $logger);
148153
$client->connect($settings, $cleanSession);

0 commit comments

Comments
 (0)