Stream current log to storage folder - laravel

I am running my Laravel 7 application for testing purposes on a shared host.
My logging.php configuration looks like the following:
<?php
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;
return [
'default' => env('LOG_CHANNEL', 'single'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'error',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'papertrail' => [
'driver' => 'monolog',
'level' => 'debug',
'handler' => SyslogUdpHandler::class,
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
],
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];
I only get the log file from the day before in my storage folder. However, I would like to get the logs that are created when the application runs, like a log stream.
Any suggestions how to do this?
I appreciate your replies!

so far, I am new to logs too. The two lines below can be added to any controller
use Log; #on top along with the other 'use' statements
this 2nd line would be inserted as needed:
Log::info('File: '. __FILE__. ' This would get logged on file: storage/laravel.log');
The result is appended onto laravel.log and would be similar to:
[2020-07-11 05:08:38] local.INFO: File: C:\<someFolders>\laravel\vendor\laravel\framework\src\Illuminate\Routing\Route.php This would get logged on file: storage/laravel.log
'hope it helps.

Related

Laravel stack with custom channel not working

I'm running Laravel 6 and I'm trying to log into default stack file and new relic log.
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 5,
],
'newrelic' => [
'driver' => 'custom',
'via' => NewRelicLogger::class,
]
]
Both env LOG_CHANNEL=stack and LOG_CHANNEL=newrelic are work normally.
When I update the stack's channels to 'channels' => ['daily', 'newrelic'] and env use LOG_CHANNEL=stack, it only logs to the file and my custom channel "newrelic" doesn't log anything.

Integration laravel 7 log to slack

I tried to integration error log laravel to slack notification. But when i tested to send log it can't send massage to slack. I followed this tutorial https://panjeh.medium.com/send-laravel-6-log-to-slack-notification-573a6d95a14e. And I've tested on route too
Here is it the config.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single','slack'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'warning',
],
Here is it the route to test
Route::get('slack', function() {
Log::error('Test');
return 'Slack notif';
});
I've got the url too and have it put in .env LOG_SLACK_WEBHOOK_URL=
You can change default log channels to slack.So you have to set
LOG_CHANNEL=stack
Also you can specify channels. Instead of changing channels
Log::channel('slack')->inf("test");
or you can do
Log::stack(['daily', 'slack'])->info("test");
or you can specify channels inside daily array.So that no need to change anythink
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'slack'],
'ignore_exceptions' => false,
],

logging permission in laravel

As mentioned in laravel doc https://laravel.com/docs/8.x/logging i used permission in logging.php configuration as follows
'single' => [
'driver' => 'single',
'tap' => [App\Providers\JsonFormatter::class],
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'permission' => 0777,
],
'daily' => [
'driver' => 'daily',
'tap' => [App\Providers\JsonFormatter::class],
'path' => storage_path('logs/'.php_sapi_name().'/laravel.log'),
'level' => 'debug',
'permission' => 0777,
'days' => 1,
],
then I deleted all previous logs and then stored then logs again but every linked directory has drwxr-xr-x these permissions. Am I doing something wrong here?

Setting up multiple log directories in Stripe

I have my logging set up like this in Laravel:
'default' => env('LOG_CHANNEL', 'stack'),
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
'permission' => 0666,
],
This creates logs for each day in storage/logs.
Now, what I want to do, is send only the log messages from my scheduled tasks to a separate log directory altogether. For example, to storage/logs/cron. But I want to keep the other messages in the current setup.
How do I make this happen? I've tried creating a new channel in config but it still logs the messages in the same files.
You can create a new channel in config/logging.php. Ie:
'cronjob' => [
'driver' => 'single',
'path' => storage_path('logs/cronjob.log'),
'level' => 'debug',
],
And then you can use it in your command (or anywhere) adding the channel method:
Log::channel('cronjob')->info('Command started. ');
If you want to log exceptions use a try/catch:
try {
// ...
} catch (\Exception $exception) {
Log::channel('cronjob')->error($exception);
}

Laravel's log loggs empty errors

I'm attempting to deploy my Laravel application, however, I'm currently encountering difficulties. The site doesn't work properly, the page name is correctly displayed in the tab and the alt text of my loader.gif is displayed, however, nothing at all happens. Attempting to tackle this problem, I found out that Laravel logs empty errors:
-- needed pastebin since SO told me my code wasn't properly formatted (despite the code being perfect as it is) -- https://pastebin.com/S9vBg5aW
just like that. Each time I re-access the webpage the errors are expanded by a certain number of errors. I only recently upgraded from Laravel 5.5 to 5.6.
Laravel 5.6 comes with different channels for logging.
in your .env
LOG_CHANNEL=stack
create a file in config/logging.php
paste the below given code.
<?php
return [
'default' => env('LOG_CHANNEL', 'stack'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 7,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];
for More informations
https://laravel.com/docs/5.6/logging
Hope this helps

Resources