使用 log4cxx 进行日志记录和过滤
我正在开发需要日志记录和过滤功能的应用程序。 我正在使用c++。我开始了解 log4cxx 支持日志记录。
我在过滤时遇到困难。
我有五个字段
- MACID
- 日期和时间
- 命令类型
- 状态
- 文本 消息
我需要将这 5 个字段存储在日志文件中,并根据以下过滤选项对其进行过滤。日志记录和过滤将在运行时本身完成。一旦文件大小达到 10 MiB,它将开始从头开始重写文件。
过滤选项
1.MACID
2. 日期和时间
过滤可以通过过滤其中之一或两者来完成。 结果应返回日志文件中的所有字段。
- 是否可以使用 log4CXX 在日志文件中存储多个字段?
- 如何根据上述标准过滤信息?
- 我需要编写自己的过滤器类继承现有的过滤器类吗?
- 我是否需要编写自定义记录器类来在日志文件中存储 5 个字段?
I am working on the application where I need logging and filtering feature.
I am using c++. I came to know about the log4cxx support logging.
I am getting difficulty in filtering .
I have five fields
- MAcID
- Date and time
- Command type
- Status
- Text Msg
I need to store these 5 fields in the log file and filter it as well based on below filtering option. Logging and filtering will be done at run time itself. Once the file size reaches 10 MiB, it will start rewriting the file from the beginning.
Filtering Options
1. MAcID
2. date and time
Filtering can done by filtering either one or both.
Result should return all the field in the log file .
- Is it possible to store more than one field in the log file using log4CXX?
- How to filter the information based on above mentioned criteria?
- Do I need to write my own filter class inheriting from existing filter classes?
- Do I need to write customise logger class to store 5 field in the log file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我曾经遇到过与第 1 点和第 4 点类似的问题。我阅读了 log4cxx 代码,找到了一个可能的解决方案。一位同事测试了该解决方案并对其进行了改进。他的结论可以在此处找到。
我们在 log4cxx 邮件列表中询问这是否是正确的解决方案,这就是我们的答案 得到了。我希望这有帮助。
I faced once a similar problem than points 1 and 4. I read log4cxx code and I found a possible solution. A job mate tested the solution and progressed it. His conclusions can be found here.
We asked in the log4cxx mailing list if it was the right solution and this is the answer we got. I hope that helps.
我不认为 log4cxx 是适合您任务的工具,并且我不确定是否可以使用 log4cxx 来完成此任务。
您可以从自定义附加程序和您自己的日志级别以及您自己的过滤器开始。
要让它运行,您需要设置日志级别并确定应使用哪个过滤器字段,并且当您更改过滤器时,您需要清除过滤器并设置一个新过滤器。
然后您可以提取日志字符串,搜索您的过滤器并让它决定是否要输出日志消息。
I don't think that log4cxx is the right tools for your task, and I am not really sure if this can be done at all with log4cxx.
You can start with a custom appender and your own log level and your own filter.
Do get it running you need to set a log level do determine which filter field should be used and when ever you change the filter you need to clear the Filters and set a new one.
Then you can extract the log string, search for your filter and let it decide if you want to output the log message or not.