有没有办法将数据记录到laravel 5中的另一个文件?不是标准的吗?例如,我想使用这样的东西:
Log::info("Some log data", '/path/to/custom/file.log');
或者至少是否有可能根据日志类型划分日志文件。
Log::info("Some log data");
Log::error("Another log data");
这样信息和错误日志将转到不同的日志文件。
谢谢您的帮助。
Log::useFiles(base_path() . '/path/to/custom/file.log', 'info');
Log::info('Do log this another PATH');
date_default_timezone_set('Asia/Dhaka');
$data = date('Y-m-d');
$time = date('h-A');
Log::useFiles(base_path() . '/log/'.$data.'/'.$time.'-'info.log', 'info');
Log::info('Do log this another PATH');
在此示例中,每个日期创建一个文件夹,其中包含每小时的单独日志
您还可以更改单个日志路径和名称。
将以下代码行添加到:bootstrap>>app.php
very bottom above of return $app
;
# SINGLE LOG
$app->configureMonologUsing(function($monolog) use ($app) {
$handler = new Monolog\Handler\StreamHandler($app->storagePath().'/logs/YOUR_SINGLE_LOG_NAME.log');
$handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
$monolog->pushHandler($handler);
});
请参阅https://laravel.com/docs/5.2/errors#configuration,特别是Custom Monolog配置部分。
按照这些指示覆盖默认配置,然后按照这些directions to configure Monolog handlers。
应该是这样的:
$app->configureMonologUsing(function($monolog) {
$monolog->pushHandler(new StreamHandler(__DIR__.'/my_app.log', Logger::DEBUG));
});
应该让你朝着正确的方向前进。