简体   繁体   English

Boost.Log:文件旋转的自定义操作

[英]Boost.Log: custom action on rotation of files

Our application uses Boost.Log (1.63) and it works quite well. 我们的应用程序使用Boost.Log(1.63),并且运行良好。 We are using the rotation/archiving feature and file names with incremeting numbers. 我们正在使用旋转/存档功能和带有递增数字的文件名。

Now we would like to watch the log files for Errors. 现在,我们要查看日志文件中的错误。

The monitoring software our organization uses needs absolute file names, so file names with an incrementing number suffix won't work. 我们组织使用的监视软件需要绝对文件名,因此后缀号递增的文件名将不起作用。

As far as I understand Boost.Log cannot be configured that the actual log file always has a fixed file name and only the archived files have suffixes. 据我了解,Boost.Log无法配置为实际的日志文件始终具有固定的文件名,而只有存档文件具有后缀。 Is this correct? 这个对吗?

The other idea we had was to create an symlink to the actual log file on every file rotation. 我们的另一个想法是在每次文件旋转时创建一个指向实际日志文件的符号链接。 Is there a possibility to add an custom action to each rotation event? 是否可以向每个轮换事件添加自定义操作?

As far as I understand Boost.Log cannot be configured that the actual log file always has a fixed file name and only the archived files have suffixes. 据我了解,Boost.Log无法配置为实际的日志文件始终具有固定的文件名,而只有存档文件具有后缀。 Is this correct? 这个对吗?

Yes, the file name is generated by the sink backend when the file is first opened for writing. 是的,文件名是在第一次打开写入文件时由接收器后端生成的。 When the file is rotated, that file name is preserved. 旋转文件时,将保留该文件名。

Is there a possibility to add an custom action to each rotation event? 是否可以向每个轮换事件添加自定义操作?

There are file open and close handlers . 有文件打开和关闭处理程序 These callbacks receive a file stream, not the file name. 这些回调接收文件流,而不是文件名。 But you can obtain the current file name from the sink backend by calling get_current_file_name . 但是您可以通过调用get_current_file_name从接收器后端获取当前文件名。

As an idea, you may want to create a custom sink that will monitor errors in logs and add it to the core just like the file sink. 作为一个想法,您可能想要创建一个自定义接收器,该接收器将监视日志中的错误并将其像文件接收器一样添加到核心中。 If you set the same filter as the one in the file sink, only with a severity check that only passes error log records, that monitor sink will receive errors that are also logged by the file sink. 如果您设置的过滤器与文件接收器中的过滤器相同,但仅通过仅通过错误日志记录的严重性检查,该监视器接收器将收到文件接收器也记录的错误。 Guidelines for creating custom sinks are described here . 在此介绍创建自定义接收器的准则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM