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.
Related
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',
],
];
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 !
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!
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',
],
],
];
I want to run yii2 console command, then I test it with run this ./yii
When I run ./yii I got this response
Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: yii\console\Application::session'
in /var/www/html/myweb/vendor/yiisoft/yii2/base/Component.php:143
Stack trace:
#0 /var/www/html/myweb/vendor/yiisoft/yii2/di/ServiceLocator.php(73): yii\base\Component->__get('session')
#1 /var/www/html/myweb/vendor/kartik-v/yii2-grid/Module.php(62): yii\di\ServiceLocator->__get('session')
Here is my common/config/params-local.php
return [
'uploadPath' => __DIR__ .'/../../uploads/',
'baseurl' => 'http://localhost/myweb/'
];
Here is my common\config\params.php
<?php
return [
'adminEmail' => 'no-reply#myweb.com',
'supportEmail' => 'no-reply#myweb.com',
'user.passwordResetTokenExpire' => 3600,
];
Here is my console\config\params-local.php
<?php
return [
];
Here is my console\config\params.php
<?php
return [
'adminEmail' => 'no-reply#myweb.com',
];
Here is my common\config\main.php
<?php
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'modules' => [
'redactor' => [
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => __DIR__ .'/../../uploads/konten',
'uploadUrl' => '/myweb/uploads/konten',
'imageAllowExtensions'=>['jpg','png','gif']
],
'gridview' => [
'class' => '\kartik\grid\Module',
]
],
];
Here is my common\config\main-local.php
<?php
return [
'language' => 'en-US',
'sourceLanguage' => 'id-ID',
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => 'xxxxx-cppd86jm9qfrt77pc684pau01nilf261.apps.googleusercontent.com',
],
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'authUrl' => 'https://www.facebook.com/dialog/oauth?display=popup',
'clientId'=> 'xxxxxx16917400',
'clientSecret' => 'xxxxxx8d99ff80ce1f713424',
],
],
],
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'pgsql:host=192.168.0.106;dbname=mydb',
'username' => 'dev',
'password' => 'dev123',
'charset' => 'utf8',
'enableSchemaCache' => false,
'schemaMap' => [
'pgsql'=> [
'class'=>'yii\db\pgsql\Schema',
'defaultSchema' => 'public2' //specify your schema here
]
], // PostgreSQL
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#backend/mail',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'iix70.hosting.com',
'username' => 'myuser',
'password' => 'mypass',
'port' => '465',
'encryption' => 'ssl',
],
],
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '../../messages',
'sourceLanguage' => 'id-ID',
'fileMap' => [
'app' => 'app.php',
],
],
],
],
]
];
Looks like something wrong with my script.
Currently i'm using ubuntu.
What should I do next in case to fix that? so it should response with yii command list instead of error.
and what cause these error?
Thanks in advance.
When you add a value to common/config folder files, configurations used in all applications like backend, frontend, console, api and others. So in advanced template, you must just add values which are related to all these applications. Based on documentation common folder is files common to all applications. This picture shows it clearly:
For your problem, as others mentioned, you don't have any session in console, but you added or used this module in common/config/params-local.php and based on introduction of this answer, it will be used in console/config/params-local.php and you get an error :).
Update: Based on your updated question, your common/config/main.php file is:
<?php
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'modules' => [
'redactor' => [
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => __DIR__ .'/../../uploads/konten',
'uploadUrl' => '/myweb/uploads/konten',
'imageAllowExtensions'=>['jpg','png','gif']
],
'gridview' => [
'class' => '\kartik\grid\Module',
]
],
];
gridviw module, implicitly uses session for saving state of sorting. In other side you added this to config folder of common, so based on previous notes, it also will be used in console application. Console doesn't have session (and I think you don't need a grid view in your console :D) and it causes an error. For solving this problem, move this lines
'modules' => [
'redactor' => [
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => __DIR__ .'/../../uploads/konten',
'uploadUrl' => '/myweb/uploads/konten',
'imageAllowExtensions'=>['jpg','png','gif']
],
'gridview' => [
'class' => '\kartik\grid\Module',
]
],
to main.php of frontend or backend folder (based on your situations and use).