Skip to content

Commit e22b8f3

Browse files
committed
feature: Added ability to exlude commands from loggin
1 parent 2ffe507 commit e22b8f3

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

config/commandlogger.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@
1717
/**
1818
* Database table name.
1919
*/
20-
'db_table' => 'commands_log'
20+
'db_table' => 'commands_log',
21+
22+
/**
23+
* Array of commands that should be excluded for logging
24+
*/
25+
'exclude' => []
2126
];

src/Logger.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ class Logger
1919
public function init()
2020
{
2121
Event::listen(CommandFinished::class, function ($event) {
22-
$timeFinished = microtime(true);
22+
$signature = $event->command;
2323

24-
$executionTime = round($timeFinished - LARAVEL_START, 2);
24+
// filter commands according to config
25+
if (!in_array($signature, config('commandlogger.exclude'))) {
26+
$timeFinished = microtime(true);
2527

26-
$memoryPeak = memory_get_peak_usage(true) / 1048576;
28+
$executionTime = round($timeFinished - LARAVEL_START, 2);
2729

28-
foreach (config('commandlogger.channels') as $channelClass) {
29-
app($channelClass)->handleLog($event->command, $executionTime, (int)$memoryPeak, gethostname());
30+
$memoryPeak = memory_get_peak_usage(true) / 1048576;
31+
32+
foreach (config('commandlogger.channels') as $channelClass) {
33+
app($channelClass)->handleLog($signature, $executionTime, (int)$memoryPeak, gethostname());
34+
}
3035
}
3136
});
3237
}

0 commit comments

Comments
 (0)