1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Logger.h
12 #ifndef ZYPP_BASE_LOGGER_H
13 #define ZYPP_BASE_LOGGER_H
18 ///////////////////////////////////////////////////////////////////
21 #define OSMLOG( L, MSG )
27 void osdlog( const std::string & msg_r, unsigned level_r ); // LogControl.cc
30 #define OSDLOG( MSG ) ::zypp::debug::osdlog( MSG, 0 )
31 #define OSMLOG( L, MSG ) ::zypp::debug::osdlog( MSG, L )
33 ///////////////////////////////////////////////////////////////////
35 /** \defgroup ZYPP_BASE_LOGGER_MACROS ZYPP_BASE_LOGGER_MACROS
36 * Convenience macros for logging.
38 * The macros finaly call @ref getStream, providing appropriate arguments,
39 * to return the log stream.
44 * Logs a debug message for group @a "foo".
47 * #undef ZYPP_BASE_LOGGER_LOGGROUP
48 * #define ZYPP_BASE_LOGGER_LOGGROUP "foo"
52 * Defines group @a "foo" as default for log messages and logs a
57 #ifndef ZYPP_BASE_LOGGER_LOGGROUP
58 /** Default log group if undefined. */
59 #define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
62 #define XXX _XXX( ZYPP_BASE_LOGGER_LOGGROUP )
63 #define DBG _DBG( ZYPP_BASE_LOGGER_LOGGROUP )
64 #define MIL _MIL( ZYPP_BASE_LOGGER_LOGGROUP )
65 #define WAR _WAR( ZYPP_BASE_LOGGER_LOGGROUP )
66 #define ERR _ERR( ZYPP_BASE_LOGGER_LOGGROUP )
67 #define SEC _SEC( ZYPP_BASE_LOGGER_LOGGROUP )
68 #define INT _INT( ZYPP_BASE_LOGGER_LOGGROUP )
69 #define USR _USR( ZYPP_BASE_LOGGER_LOGGROUP )
71 #define _XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
72 #define _DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
73 #define _MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
74 #define _WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
75 #define _ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
76 #define _SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
77 #define _INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
78 #define _USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
80 #define _BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
82 /** Actual call to @ref getStream. */
83 #define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
84 zypp::base::logger::getStream( GROUP, LEVEL, _BASEFILE, __FUNCTION__, __LINE__ )
88 ///////////////////////////////////////////////////////////////////
90 { /////////////////////////////////////////////////////////////////
91 ///////////////////////////////////////////////////////////////////
93 { /////////////////////////////////////////////////////////////////
95 ///////////////////////////////////////////////////////////////////
97 { /////////////////////////////////////////////////////////////////
99 /** Definition of log levels.
104 E_XXX = 999, /**< Excessive logging. */
105 E_DBG = 0, /**< Debug or verbose. */
106 E_MIL, /**< Milestone. */
107 E_WAR, /**< Warning. */
108 E_ERR, /**< Error. */
109 E_SEC, /**< Secutrity related. */
110 E_INT, /**< Internal error. */
111 E_USR /**< User log. */
114 /** Return a log stream to write on.
116 * The returned log stream is determined by @a group_r and
117 * @a level_r. The remaining arguments @a file_r, @a func_r
118 * and @a line_r are expected to denote the location in the
119 * source code that issued the message.
121 * @note You won't call @ref getStream directly, but use the
122 * @ref ZYPP_BASE_LOGGER_MACROS.
124 extern std::ostream & getStream( const char * group_r,
129 extern bool isExcessive();
131 /////////////////////////////////////////////////////////////////
132 } // namespace logger
133 ///////////////////////////////////////////////////////////////////
135 /////////////////////////////////////////////////////////////////
137 ///////////////////////////////////////////////////////////////////
138 /////////////////////////////////////////////////////////////////
140 ///////////////////////////////////////////////////////////////////
141 #endif // ZYPP_BASE_LOGGER_H