Redirect Tinkerwell Logging at Runtime

3 years ago

ihsanberahim

Tinkerwell basically using default Laravel logging channel if it is not specified. So, here how to redirect them all to custom channel at runtime.

Code

config([
    'logging.channels.tinkerwell' => [
        'driver' => 'single',
        'path' => storage_path('logs/tinkerwell.log'),
        'level' => 'debug',
        'days' => 30,
    ],
]);

config(['logging.default' => 'tinkerwell']);

Illuminate\Support\Facades\Log::info(now());

file_get_contents(storage_path() . '/logs/tinkerwell.log');

Output

=> """
   [2020-04-09 04:20:38] local.INFO: 2020-04-09 04:20:38  \n
   [2020-04-09 04:20:50] local.INFO: 2020-04-09 04:20:50  \n
   [2020-04-09 04:21:25] local.INFO: 2020-04-09 04:21:24  \n
   """
Video course: PHP Package Development