Jafar Gh
Jafar Gh

Reputation: 146

Boost.Log -managing repeated consecutive log messages and prevent printing duplicates

I am new to Boost.Log and Using it to develop a logger library as a wrapper on top of Boost.Log. My Problem is finding a convenient way to set a counter for number of consecutive repeated log messages instead of printing the same log multiple times.

for example: (ADD_LOG() method is in my library and do BOOST_LOG_SEV(...))

ADD_LOG("Hello");
ADD_LOG("Hello");
ADD_LOG("Hello");
ADD_LOG("Some Different Hello");

I want to be the output log file like this: (sample_0.log)

........................................................

[TimeStamp] [Filter] Hello

[TimeStamp] [Filter] Skipped 2 duplicate messages!

[TimeStamp] [Filter] Some Different Hello

.......................................................

I am using this example with Text File Backend and TimeStamp, Filter are Ok. My problem is about skipping duplicates. maybe with setting filters or anything else.

I think syslog in linux has this feature by some configurations.

Upvotes: 1

Views: 758

Answers (1)

Andrey Semashev
Andrey Semashev

Reputation: 10614

Boost.Log does not implement such log record accumulation, you will have to implement it yourself. You can do this by implementing a sink backend that would buffer the last log record message and compare it with the next one. Note that you should not buffer the whole record or formatted string because it will likely differ because of timestamps, record counters and other frequently changing attribute values that you might use.

Upvotes: 1

Related Questions