Skip to content
Snippets Groups Projects
Commit d90cc609 authored by g0dil's avatar g0dil
Browse files

Utils/Logger: Fix 'senf::log::DefaultArea as empty-string' ambiguity

parent f6862710
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
BOOST_AUTO_UNIT_TEST(areaRegistry) BOOST_AUTO_UNIT_TEST(areaRegistry)
{ {
char const * areas[] = { "", "senf::log::test::Foo", "senf::log::test::myArea" }; char const * areas[] = { "senf::log::DefaultArea",
"senf::log::test::Foo",
"senf::log::test::myArea" };
BOOST_CHECK_EQUAL_COLLECTIONS( senf::log::AreaRegistry::instance().begin(), BOOST_CHECK_EQUAL_COLLECTIONS( senf::log::AreaRegistry::instance().begin(),
senf::log::AreaRegistry::instance().end(), senf::log::AreaRegistry::instance().end(),
......
...@@ -107,12 +107,11 @@ namespace log { ...@@ -107,12 +107,11 @@ namespace log {
}; \ }; \
} }
/** \brief Default global log stream */ /** \brief Default global log stream */
SENF_LOG_DEF_STREAM(Debug, MESSAGE, MESSAGE, MESSAGE); SENF_LOG_DEF_STREAM(Debug, MESSAGE, MESSAGE, MESSAGE);
/** \brief Default global log area */ /** \brief Default global log area */
SENF_LOG_DEF_AREA_I(DefaultArea, SENF_LOG_DEF_AREA(DefaultArea);
std::string v_name() const { return ""; });
///\} ///\}
///\} ///\}
......
...@@ -68,7 +68,7 @@ prefix_ void senf::log::IOStreamTarget::v_write(boost::posix_time::ptime timesta ...@@ -68,7 +68,7 @@ prefix_ void senf::log::IOStreamTarget::v_write(boost::posix_time::ptime timesta
for (; i != i_end; ++i) { for (; i != i_end; ++i) {
stream_ << timestamp << sep; stream_ << timestamp << sep;
if (! area.empty()) if (area != "senf::log::DefaultArea")
stream_ << "[" << area << "] "; stream_ << "[" << area << "] ";
stream_ << *i << "\n"; stream_ << *i << "\n";
sep = '-'; sep = '-';
......
...@@ -43,6 +43,8 @@ namespace log { ...@@ -43,6 +43,8 @@ namespace log {
<pre> <pre>
<date> [<area>] <message> <date> [<area>] <message>
</pre> </pre>
The \e area will be omitted it it is \c senf::log::DefaultArea.
The date formatting is set using the Boost.DateTime date_facet, e.g.: The date formatting is set using the Boost.DateTime date_facet, e.g.:
\code \code
......
...@@ -39,9 +39,37 @@ namespace log { ...@@ -39,9 +39,37 @@ namespace log {
These are the valid log levels with some additional special values: These are the valid log levels with some additional special values:
\c DISABLED is a special value used as level limit to disable all messages. <dl><dt>VERBOSE</dt><dd>Really verbose log messages. Messages at this level are used for
internal debugging. They should be enabled only selectively within the areas currently under
inspection.</dd>
\c NONE is used to in some special places to inherit the default log level. <dt>NOTICE</dt><dd>Arbitrary unimportant notice. Message which normally should be disabled
but might be informative to better understand the programs operation.</dd>
<dt>MESSAGE</dt><dd>Purely informative message which should be displayed if not explicitly
disabled.</dd>
<dt>IMPORTANT</dt><dd>Important information or warning which really should be read.</dd>
<dt>CRITICAL</dt><dd>Error condition which does not terminate the program completely but has
non-reversible adverse effects</dd>
<dt>FATAL</dt><dd>Error condition which does terminate program execution or enforces a
restart or some kind of re-initialization with loss of state and context.</dd></dl>
There are also some special values which <em>must not be used as a log level</em>:
<dl><dt>DISABLED</dt><dd>Disable all log messages.</dd>
<dt>NONE</dt><dd>Special value which signifies inheritance of the default log
level.</dd></dl>
Log levels are classes, not numbers. Each log level class has a \c value member which gives
that levels numeric priority. The larger the number, the more important the message is.
\implementation The log levels need to be classes since areas and streams are classes: Since
log arguments (stream, area and level) may appear in any order and number, it is much
simpler to parse them if they are all of the same type.
*/ */
///\ingroup loglevels ///\ingroup loglevels
...@@ -67,9 +95,13 @@ namespace log { ...@@ -67,9 +95,13 @@ namespace log {
\see loglevels */ \see loglevels */
struct CRITICAL : public detail::LevelBase { static unsigned const value = 5; }; struct CRITICAL : public detail::LevelBase { static unsigned const value = 5; };
/** \brief Log level FATAL
\see loglevels */
struct FATAL : public detail::LevelBase { static unsigned const value = 6; };
/** \brief Disable logging /** \brief Disable logging
\see loglevels */ \see loglevels */
struct DISABLED : public detail::LevelBase { static unsigned const value = 6; }; struct DISABLED : public detail::LevelBase { static unsigned const value = 7; };
/** \brief Inherit log level /** \brief Inherit log level
\see loglevels */ \see loglevels */
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
Log messages are arbitrarily created throughout the code using simple log statements (which are Log messages are arbitrarily created throughout the code using simple log statements (which are
macros). Besides the log message itself, every log message is labeled with additional macros). Besides the log message itself, every log message is labeled with additional
information: The \e stream, the \e area and a log \e level. If the message is not compile-time information: The \e stream, the \e area and a log \e level. If the message is not compile-time
disabled, the message is then directed to one of several log \e targets. disabled, the message is then directed to one or several log \e targets.
A \e stream combines log messages with a single purpose: Debug messages, access logging and so A \e stream combines log messages with a single purpose: Debug messages, access logging and so
on. Any number of streams may be defined. There is one predefined default stream called \c on. Any number of streams may be defined. There is one predefined default stream called \c
...@@ -48,7 +48,8 @@ ...@@ -48,7 +48,8 @@
The \e area gives information about the source location of the message. Areas may be defined and The \e area gives information about the source location of the message. Areas may be defined and
assigned arbitrarily but should be used to label messages from a single class or subsystem. It assigned arbitrarily but should be used to label messages from a single class or subsystem. It
is possible to reuse a class as it's own area tag, which is often desireable. (see: \ref is possible to reuse a class as it's own area tag, which is often desireable. There is a
default area \c senf::log::DefaultArea which is used, when no other area is assigned. (see: \ref
SENF_LOG_DEF_AREA, \ref SENF_LOG_CLASS_AREA) SENF_LOG_DEF_AREA, \ref SENF_LOG_CLASS_AREA)
The log \e level gives information on the importance of the message. The list of log-levels is The log \e level gives information on the importance of the message. The list of log-levels is
......
...@@ -379,9 +379,7 @@ namespace log { ...@@ -379,9 +379,7 @@ namespace log {
somehow format and write the log message. somehow format and write the log message.
Every log message always possesses a complete set of Every log message always possesses a complete set of
meta information (\a stream, \a area and \a level). The meta information (\a stream, \a area and \a level).
\a area may be an empty string if the message was
written from the senf::log::DefaultArea.
\note This member must \e not block since it may be \note This member must \e not block since it may be
called from any unknown context. This prohibits called from any unknown context. This prohibits
......
...@@ -81,7 +81,7 @@ BOOST_AUTO_UNIT_TEST(target) ...@@ -81,7 +81,7 @@ BOOST_AUTO_UNIT_TEST(target)
"senf::log::Debug-senf::log::test::Foo-VERBOSE-REJECT", "senf::log::Debug-senf::log::test::Foo-VERBOSE-REJECT",
"senf::log::Debug--NONE-ACCEPT", "senf::log::Debug--NONE-ACCEPT",
"senf::log::test::myStream-senf::log::test::Foo-VERBOSE-ACCEPT", "senf::log::test::myStream-senf::log::test::Foo-VERBOSE-ACCEPT",
"senf::log::test::myStream--NONE-REJECT", "senf::log::test::myStream-senf::log::DefaultArea-NONE-REJECT",
"senf::log::test::myStream--IMPORTANT-REJECT", "senf::log::test::myStream--IMPORTANT-REJECT",
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment