1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Logger.h
12 #ifndef ZYPP_BASE_LOGGER_H
13 #define ZYPP_BASE_LOGGER_H
18 /** \defgroup ZYPP_BASE_LOGGER_MACROS ZYPP_BASE_LOGGER_MACROS
19 * Convenience macros for logging.
21 * The macros finaly call @ref getStream, providing appropriate arguments,
22 * to return the log stream.
27 * Logs a debug message for group @a "foo".
30 * #undef ZYPP_BASE_LOGGER_LOGGROUP
31 * #define ZYPP_BASE_LOGGER_LOGGROUP "foo"
35 * Defines group @a "foo" as default for log messages and logs a
40 #ifndef ZYPP_BASE_LOGGER_LOGGROUP
41 /** Default log group if undefined. */
42 #define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
45 #define XXX _XXX( ZYPP_BASE_LOGGER_LOGGROUP )
46 #define DBG _DBG( ZYPP_BASE_LOGGER_LOGGROUP )
47 #define MIL _MIL( ZYPP_BASE_LOGGER_LOGGROUP )
48 #define WAR _WAR( ZYPP_BASE_LOGGER_LOGGROUP )
49 #define ERR _ERR( ZYPP_BASE_LOGGER_LOGGROUP )
50 #define SEC _SEC( ZYPP_BASE_LOGGER_LOGGROUP )
51 #define INT _INT( ZYPP_BASE_LOGGER_LOGGROUP )
52 #define USR _USR( ZYPP_BASE_LOGGER_LOGGROUP )
54 #define _XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
55 #define _DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
56 #define _MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
57 #define _WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
58 #define _ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
59 #define _SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
60 #define _INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
61 #define _USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
63 #define _BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
65 /** Actual call to @ref getStream. */
66 #define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
67 zypp::base::logger::getStream( GROUP, LEVEL, _BASEFILE, __FUNCTION__, __LINE__ )
71 ///////////////////////////////////////////////////////////////////
73 { /////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////
76 { /////////////////////////////////////////////////////////////////
78 ///////////////////////////////////////////////////////////////////
80 { /////////////////////////////////////////////////////////////////
82 /** Definition of log levels.
87 E_XXX = 999, /**< Excessive logging. */
88 E_DBG = 0, /**< Debug or verbose. */
89 E_MIL, /**< Milestone. */
90 E_WAR, /**< Warning. */
92 E_SEC, /**< Secutrity related. */
93 E_INT, /**< Internal error. */
94 E_USR /**< User log. */
97 /** Return a log stream to write on.
99 * The returned log stream is determined by @a group_r and
100 * @a level_r. The remaining arguments @a file_r, @a func_r
101 * and @a line_r are expected to denote the location in the
102 * source code that issued the message.
104 * @note You won't call @ref getStream directly, but use the
105 * @ref ZYPP_BASE_LOGGER_MACROS.
107 extern std::ostream & getStream( const char * group_r,
112 extern bool isExcessive();
114 /////////////////////////////////////////////////////////////////
115 } // namespace logger
116 ///////////////////////////////////////////////////////////////////
118 /////////////////////////////////////////////////////////////////
120 ///////////////////////////////////////////////////////////////////
121 /////////////////////////////////////////////////////////////////
123 ///////////////////////////////////////////////////////////////////
124 #endif // ZYPP_BASE_LOGGER_H