How Do I Disable A Log Channel On Local And Testing Environment
In my application I have these log channels:
'general' => [
'driver' => 'single',
'path' => storage_path('logs/general.log'),
'level' => 'debug',
],
'jobs' => [
'driver' => 'stack',
'channels' => [
'general',
'slack'
],
],
'slack' => [
'driver' => 'slack',
'url' => /*Censored Hook URL*/,
'username' => 'MyApp',
'emoji' => ':gear:',
'level' => 'debug',
],
When I log in job
channel I want not to log into slack
log when on local or testing environment in order to avoid having duplicate and extremely unwanted logs on the shared log channel on the slack.
So how I can specify the environments that the slack
channel will be able to write logs. A dirty approach is to specify manually which logs will write in to via this snippet of code:
if(!App::environment(['local','testing')){
Log::channel('jobs')->info('Blah blah blah');
} else {
Log::channel('general')->info('Blah blah blah');
}
But using the code above, I am afraid that will turn my codebase into a diffucult-to-read-one. So do you know an elegant solution in order to process my logs?
Answer
You could simply split jobs
into 2 entrys, example jobs
and jobs_without_slack
, let jobs
be as is and jobs_without_slack
will be configured without slack
in it's channels
. Then use different .env.xy
files for testing (.env.testing
), local, develop (.env.develop
) and so on and set the LOG_CHANNEL
to the correct logging, so you do not need to change a line of code in your logic ;)
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms