
While using rotating text file as stream, is it possible to keep most recent log file name same all the time? Currently what I observe is 'N' keeps incrementing and have to manually find out the most recent file. Also, is there some way to print severity in log file without explicitly passing it as part of message i.e. BOOST_LOG_SEV(my_logger, CRITICAL) Thanks

Rajpal Dangi wrote:
While using rotating text file as stream, is it possible to keep most recent log file name same all the time? Currently what I observe is 'N' keeps incrementing and have to manually find out the most recent file.
No, the stream always generates a new file name on rotation and uses it to write the log to. Therefore, the mos recent log file is the one with the last counter value. The rationale for such behavior is that there are considerably more possibilities for the rotation to fail, if done as you suggest. It is possible that the current log file gets locked by another process, in which case it is not clear where to write logs to. Also, if keeping the current log file name the same, it would be necessary to provide at least two file name templates to the stream: one for the current file name and another to form up the rotated file names. This would complicate the stream usage.
Also, is there some way to print severity in log file without explicitly passing it as part of message i.e. BOOST_LOG_SEV(my_logger, CRITICAL)
Yes, you can provide the default severity level to the logger constructor. Having done that, all log records that are written through this logger without an explicit severity level specification will have the default level. For example: severity_logger my_crit_logger(keywords::severity = CRITICAL); BOOST_LOG(my_crit_logger) << "The record is CRITICAL by default"; BOOST_LOG_SEV(my_crit_logger, NORMAL) << "This record is explicitly marked as to NORMAL";

Rephrasing my second question from previous post. Suppose NORMAL, ERROR and CRITICAL severity logs are directed to text file. How to identify which one of them belong to ERROR severity? I understand this can be done by using attribute (Tags in example) but I'm looking something implicit. So that we can avoid call to BOOST_LOG_SCOPED_LOGGER_TAG for each BOOST_LOG_SEV call. What I meant by print severity in log file is to have severity level as part of log file contents i.e. For BOOST_LOG_SEV(my_crit_logger, NORMAL) << "This record is explicitly marked as to NORMAL"; Log file contents: ......[NORMAL] This record is explicitly marked as to NORMAL In other words -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Andrey Semashev Sent: Wednesday, September 03, 2008 12:51 PM To: boost@lists.boost.org Subject: Re: [boost] Boost::log query Rajpal Dangi wrote:
While using rotating text file as stream, is it possible to keep most recent log file name same all the time? Currently what I observe is 'N' keeps incrementing and have to manually find out the most recent file.
No, the stream always generates a new file name on rotation and uses it to write the log to. Therefore, the mos recent log file is the one with the last counter value. The rationale for such behavior is that there are considerably more possibilities for the rotation to fail, if done as you suggest. It is possible that the current log file gets locked by another process, in which case it is not clear where to write logs to. Also, if keeping the current log file name the same, it would be necessary to provide at least two file name templates to the stream: one for the current file name and another to form up the rotated file names. This would complicate the stream usage.
Also, is there some way to print severity in log file without explicitly passing it as part of message i.e. BOOST_LOG_SEV(my_logger, CRITICAL)
Yes, you can provide the default severity level to the logger constructor. Having done that, all log records that are written through this logger without an explicit severity level specification will have the default level. For example: severity_logger my_crit_logger(keywords::severity = CRITICAL); BOOST_LOG(my_crit_logger) << "The record is CRITICAL by default"; BOOST_LOG_SEV(my_crit_logger, NORMAL) << "This record is explicitly marked as to NORMAL"; _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Rajpal Dangi wrote:
Rephrasing my second question from previous post. Suppose NORMAL, ERROR and CRITICAL severity logs are directed to text file. How to identify which one of them belong to ERROR severity?
I understand this can be done by using attribute (Tags in example) but I'm looking something implicit. So that we can avoid call to BOOST_LOG_SCOPED_LOGGER_TAG for each BOOST_LOG_SEV call.
What I meant by print severity in log file is to have severity level as part of log file contents i.e. For BOOST_LOG_SEV(my_crit_logger, NORMAL) << "This record is explicitly marked as to NORMAL";
Log file contents: ......[NORMAL] This record is explicitly marked as to NORMAL
Oh, I think, I understand now. What you need is to specify a formatter. Formatters are used to describe how different attributes will be represented in the log file. Severity level is one of the attributes, it is automatically registered by the severity_logger, so you don't need to put BOOST_LOG_SCOPED_LOGGER_TAG macros or anything around your log records. All you need is to define the formatter for the attribute and pass it to the sink backend. For example: // Assume, you have constructed the backend shared_ptr< text_ostream_backend > backend; // The formatter can be set in one of the two ways: // the lambda-like expression backend->set_formatter( ostrm << "[" << attr< int >("Severity") << "] " << message() ); // ... or with Boost.Format-like expression backend->set_formatter( format("[%1%] %2%") % attr< int >("Severity") % message() ); The "Severity" in these examples is the attribute name. It is the name that severity_logger uses to register the severity level attribute. int is the type of the attribute, it is currently predefined and cannot be customized. Now, you can log like this: enum level { NORMAL, ERROR, CRITICAL }; severity_logger lg; BOOST_LOG_SEV(lg, NORMAL) << "This record is explicitly marked as NORMAL"; BOOST_LOG_SEV(lg, Critical) << "This record is explicitly marked as CRITICAL"; The log file will contain then: [0] This record is explicitly marked as NORMAL [2] This record is explicitly marked as CRITICAL

Is there some way to fine tune flushing of logs into file? What I observed is if there are quite a few logs to be written they never appear into file. Many thanks to Andrey for adressing queries. -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Andrey Semashev Sent: Wednesday, September 03, 2008 3:04 PM To: boost@lists.boost.org Subject: Re: [boost] Boost::log query Rajpal Dangi wrote:
Rephrasing my second question from previous post. Suppose NORMAL, ERROR and CRITICAL severity logs are directed to text file. How to identify which one of them belong to ERROR severity?
I understand this can be done by using attribute (Tags in example) but
I'm looking something implicit. So that we can avoid call to BOOST_LOG_SCOPED_LOGGER_TAG for each BOOST_LOG_SEV call.
What I meant by print severity in log file is to have severity level as part of log file contents i.e. For BOOST_LOG_SEV(my_crit_logger, NORMAL) << "This record is explicitly marked as to NORMAL";
Log file contents: ......[NORMAL] This record is explicitly marked as to NORMAL
Oh, I think, I understand now. What you need is to specify a formatter. Formatters are used to describe how different attributes will be represented in the log file. Severity level is one of the attributes, it is automatically registered by the severity_logger, so you don't need to put BOOST_LOG_SCOPED_LOGGER_TAG macros or anything around your log records. All you need is to define the formatter for the attribute and pass it to the sink backend. For example: // Assume, you have constructed the backend shared_ptr< text_ostream_backend > backend; // The formatter can be set in one of the two ways: // the lambda-like expression backend->set_formatter( ostrm << "[" << attr< int >("Severity") << "] " << message() ); // ... or with Boost.Format-like expression backend->set_formatter( format("[%1%] %2%") % attr< int >("Severity") % message() ); The "Severity" in these examples is the attribute name. It is the name that severity_logger uses to register the severity level attribute. int is the type of the attribute, it is currently predefined and cannot be customized. Now, you can log like this: enum level { NORMAL, ERROR, CRITICAL }; severity_logger lg; BOOST_LOG_SEV(lg, NORMAL) << "This record is explicitly marked as NORMAL"; BOOST_LOG_SEV(lg, Critical) << "This record is explicitly marked as CRITICAL"; The log file will contain then: [0] This record is explicitly marked as NORMAL [2] This record is explicitly marked as CRITICAL _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Thu, Sep 4, 2008 at 10:35 PM, Rajpal Dangi <rajpal.dangi@transerainc.com>wrote:
Is there some way to fine tune flushing of logs into file? What I observed is if there are quite a few logs to be written they never appear into file.
Many thanks to Andrey for adressing queries.
Perhaps, you need the auto_flush function in the text_ostream_backend?
participants (2)
-
Andrey Semashev
-
Rajpal Dangi