Laravel stderr channel logs on Docker don't work - php

I have a straightforward application with php Laravel with the following channel configured for logs:
'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
I've made sure the env variables LOG_CHANNEL and LOG_LEVEL are properly configured. Though docker doesn't output anything. Is there anyone that could give me more feedback on how to debug? Thanks so much

I'm using this and everything is working :
'stderr' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stdout',
'level' => 'debug',
],
],
Hope you found your solution !

Related

The Laravel log path has not been updated

I changed the path to the larval log in the config folder, but the logs are not updated in project.log. PHP-fpm to start the service and in that config file also have updated the files it is not working can you help with this please see my below code.
return [
'default' => env('LOG_CHANNEL', 'stack'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravelkd.log'),
'level' => 'debug',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravelkd.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',
],
],
'rollbar' => [
'driver' => 'monolog',
'handler' => \Rollbar\Laravel\MonologHandler::class,
'access_token' => env('ROLLBAR_TOKEN'),
'level' => 'debug',
],
];

Separate Log Files Laravel 8

I am trying to have Error messages and debug messages write to separate log files, laravel.log for error messages and debug.log for debug messages. As of now, debug messages are not writing to the error log, which is good but error messages are still writing to the debug log.
here is the config from logging.php:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'syslog'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'error',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel-'.php_sapi_name().'-'.$processName.'.log'),
'level' => 'debug',
'days' => 7,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'syslog' => [
'driver' => 'single',
'level' => 'debug',
'path' => storage_path('logs/debug.log'),
],
'errorlog' => [
'driver' => 'errorlog',
'path' => storage_path('logs/laravel.log'),
'level' => 'error',
],
],
];
And when I am writing a debug message, I write to the specific channel:
Log::channel('syslog')->debug($message);
I want to stop error messages from writing to debug.log, and only write to laravel.log
Thanks!
Okay I figured this out for anyone who may need it in the future!
So Laravel's stack channel contains any other channel that you want to be active; and the default channel when writing something like Log::debug('message');
will look like this:
'default' => env('LOG_CHANNEL', 'stack')
With my configuration from above, changing the default to 'single', which I have set as the error level will look like this:
'default' => env('LOG_CHANNEL', 'single')
Just be sure to log to specific channels when logging( I built a helper function for this ) and you will be good!

Laravel: add `stdout` stream for logging

I want to add stdout stream for logging in conjunction with storage/logs/laravel.log file in my Laravel app.
So, I've added new stdout channel to config/logging.php file like this:
'channels' => [
...
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'stdout' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'with' => [
'stream' => 'php://stdout',
],
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'formatter' => env('LOG_STDERR_FORMATTER'),
'with' => [
'stream' => 'php://stderr',
],
],
...
]
Is it correct? How can I monitor or check the work of php://stdout or php://stderr streams of my app from terminal? Unfortunately, I can't find any reliable example yet.

How to save custom log file in laravel 5.6?

I'm totally new to laravel, I am using laravel 5.6. and I am trying to create custom logging file. I googled but could not find.
I made here a chanel in config/logging.php:
'userLogin' => [
'driver' => 'daily',
'path' => storage_path('logs/user.log'),
'level' => 'info',
],
and used it in my controller:
use Log;
Log::channel('userLogin')->info('A transaction has been made!');
but it not writing to file at all.
Your code looks correct. I would guess that this is a permissions issue related to your log file. Try changing the log file to the default laravel log file: storage_path('logs/laravel.log'). If this solves the problem, then the problem is either that the logs/user.log file does not yet exist and your system wants to you to create it manually, or the file does exist but does not have proper permissions. Since I don't know your file system, etc. I can't give explicit instructions for setting permissions but I'd be happy to help if you get to that point.
this is my logging config
<?php
use Monolog\Handler\StreamHandler;
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env('LOG_CHANNEL', 'stack'),
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'singleInfo', 'singleAlert', 'singleWarning', 'singleCritical', 'singleEmergency'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'singleInfo' => [
'driver' => 'single',
'path' => storage_path('logs/info.log'),
'level' => 'info',
],
'singleAlert' => [
'driver' => 'single',
'path' => storage_path('logs/alert.log'),
'level' => 'alert',
],
'singleWarning' => [
'driver' => 'single',
'path' => storage_path('logs/warning.log'),
'level' => 'warning',
],
'singleCritical' => [
'driver' => 'single',
'path' => storage_path('logs/critical.log'),
'level' => 'critical',
],
'singleEmergency' => [
'driver' => 'single',
'path' => storage_path('logs/emergency.log'),
'level' => 'emergency',
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 0,
],
'slack' => [
'driver' => 'slack',
'url' => env('LOG_SLACK_WEBHOOK_URL'),
'username' => 'Laravel Log',
'emoji' => ':boom:',
'level' => 'critical',
],
'stderr' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'with' => [
'stream' => 'php://stderr',
],
],
'syslog' => [
'driver' => 'syslog',
'level' => 'debug',
],
'errorlog' => [
'driver' => 'errorlog',
'level' => 'debug',
],
],
];

How to save session in redis with cakephp 3.0?

Hello guy's I newbie in cakephp 3.0. I know little bit cakephp 2.0. I configured my redis with cakephp 2.0 with this help of url But I don't know how to configure in cakephp 3.0 please help me
Since Cakephp 4 is out, I am currently studying it (which seems exists in Cakphp 3 as well) and seems like there is a way to do it. Not tested yet.
Following this: https://book.cakephp.org/4/en/development/sessions.html#cache-sessions
app.php
'Session' => [
'defaults' => 'cache', //Use the Cache class to save session
'handler' => [
'config' => 'session'
]
],
Following this link: https://book.cakephp.org/4/en/core-libraries/caching.html#redisengine-options
app.php
/*
* Configure the cache adapters.
*/
'Cache' => [
'session' => [
'className' => RedisEngine::class,
//`port` The port your Redis server is running on.
//`host` The host your Redis server is running on.
//`database` The database number to use for connection.
//`password` Redis server password.
//`persistent` Should a persistent connection be made to Redis.
//`timeout` Connection timeout for Redis.
//`unix_socket` Path to a unix socket for Redist.
],
],
I am going to test this out later on and make update if needed, but it really seems promising.
Update 2020-05-20: Tested, it work fine
You would set your session to use cache sessions inside the app.php file:
'Session' => [
'defaults' => 'cache'
]
Then, you would set your cache to redis:
'Cache' => [
'default' => [
'className' => 'Redis',
],
]
In vendor\cakephp\cakephp\src\Network\Session.php
you can see the default type of session.
They are listed as php, cake,cache , database.
$defaults = [
'php' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
]
],
'cake' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
]
],
'cache' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
'handler' => [
'engine' => 'CacheSession',
'config' => 'default'
]
],
'database' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
'session.serialize_handler' => 'php',
],
'handler' => [
'engine' => 'DatabaseSession'
]
]
]
Here is cache using default config of Cache. Maybe you want to use defualt as a File Cache.
In app.php
create a new cache config
'redis' => [
'className' => 'Redis',
'server'=>'127.0.0.1',
'port'=>6379
],
Then you can use your new cache config here.
'Session' => [
'cookie' => 'herewego',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
'handler' => [
'engine' => 'CacheSession',
'config' => 'redis'
]
],

Categories