[英]Change filename on custom monolog file
I use a rotating monolog handler 我使用旋转的独白处理程序
monolog:
channels: ['import']
handlers:
import_client:
level: debug
type: rotating_file
max_files: 10
path: '%kernel.logs_dir%/import.log'
channels: [import_client]
All works fine except I don't like the filename. 除了我不喜欢文件名之外,其他所有方法都正常。 I get
import-2018-02-22.log
. 我得到
import-2018-02-22.log
。
Does it exist a way to change this format? 是否存在更改此格式的方法?
I would like the filename to be like import-"date(YmdHis)".log
. 我希望文件名像
import-"date(YmdHis)".log
。
Is possible to rewrite the filename format? 可以重写文件名格式吗? Did you have any solutions ?
您有什么解决方案吗?
The RotatingFileHandler Logs records to a file and creates one logfile per day . RotatingFileHandler将记录记录到文件并每天创建一个日志文件。 It will also delete files older than $maxFiles.
它还将删除早于$ maxFiles的文件。 You should use logrotate for high profile setups though, this is just meant as a quick and dirty solution.
但是,您应该将logrotate用于高配置设置,这仅是一种快速而肮脏的解决方案。
As you can see in the original RotatingFileHandler : you could possibly change the rotate dateformat 如您在原始RotatingFileHandler中所看到的:您可以更改旋转日期格式
public function setFilenameFormat($filenameFormat, $dateFormat)
But I don't see any configuration option in the symfony monolog reference . 但是我在symfony monolog参考中看不到任何配置选项。 You could call a service using
您可以使用以下方式致电服务
services:
app.custom_rotating_service:
# ...
calls:
- method: setFilenameFormat
arguments:
- 'yourFilenameFormat'
- 'Ymd'
It seems to me you would get into soemthing complex for no added value of a date format. 在我看来,如果没有日期格式的附加值,您会陷入麻烦。
TLDR TLDR
我找到了解决方案,需要在配置处理程序中添加一个新参数:
date_format: 'YmdHms'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.