Skip to content

Commit 6f3433d

Browse files
committed
Update README.md
1 parent 65a4ab2 commit 6f3433d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Add the new driver type in your `config/logging.php` configuration
1818
'via' => KABBOUCHI\LoggerDiscordChannel\DiscordLogger::class,
1919
'webhook' => 'https://discordapp.com/api/webhooks/.....',
2020
'level' => 'DEBUG',
21-
'role_id' => null, // role to tag in the error
21+
'role_id' => null, // role to tag in the error,
22+
'environment' => 'production', // or ['production', 'staging', 'local']
2223
],
2324
],

src/DiscordLogger.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66

77
class DiscordLogger
88
{
9-
/**
10-
* Create a custom Monolog instance.
11-
*
12-
* @param array $config
13-
* @return \Monolog\Logger
14-
*/
15-
public function __invoke(array $config)
16-
{
17-
$log = new Logger('discord');
18-
$log->pushHandler(new DiscordHandler($config['webhook'], config('app.name'), null, $config['level'] ?? 'DEBUG', true, $config['role_id'] ?? null));
9+
/**
10+
* Create a custom Monolog instance.
11+
*
12+
* @param array $config
13+
* @return \Monolog\Logger
14+
*/
15+
public function __invoke(array $config)
16+
{
17+
$log = new Logger('discord');
1918

20-
return $log;
21-
}
19+
if (app()->environment($config['environment'] ?? 'production')) {
20+
$log->pushHandler(new DiscordHandler($config['webhook'], config('app.name'), null, $config['level'] ?? 'DEBUG', true, $config['role_id'] ?? null));
21+
}
22+
23+
return $log;
24+
}
2225
}
2326

0 commit comments

Comments
 (0)