Skip to content

Commit

Permalink
Allow broadcasting to a specific log channel (#40)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
bsdnomad and Namoshek authored May 15, 2023
1 parent 0669643 commit b059586
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/mqtt-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
// 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,
Expand Down
5 changes: 5 additions & 0 deletions src/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ protected function createConnection(string $name): MqttClientContract
$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);
Expand Down

0 comments on commit b059586

Please sign in to comment.