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 )
28 void osdlog( const std::string & msg_r, unsigned level_r ); // LogControl.cc
30 struct TraceLeave // LogControl.cc
32 TraceLeave( const TraceLeave & ) =delete;
33 TraceLeave & operator=( const TraceLeave & ) =delete;
34 TraceLeave( const char * file_r, const char * fnc_r, int line_r );
37 static unsigned _depth;
44 #define OSDLOG( MSG ) ::zypp::debug::osdlog( MSG, 0 )
45 #define OSMLOG( L, MSG ) ::zypp::debug::osdlog( MSG, L )
46 #define TRACELEAVE ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__ )
48 ///////////////////////////////////////////////////////////////////
50 /** \defgroup ZYPP_BASE_LOGGER_MACROS ZYPP_BASE_LOGGER_MACROS
51 * Convenience macros for logging.
53 * The macros finaly call @ref getStream, providing appropriate arguments,
54 * to return the log stream.
57 * L_DBG("foo") << ....
59 * Logs a debug message for group @a "foo".
62 * #undef ZYPP_BASE_LOGGER_LOGGROUP
63 * #define ZYPP_BASE_LOGGER_LOGGROUP "foo"
67 * Defines group @a "foo" as default for log messages and logs a
72 #ifndef ZYPP_BASE_LOGGER_LOGGROUP
73 /** Default log group if undefined. */
74 #define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
77 #define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
78 #define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
79 #define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
80 #define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
81 #define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
82 #define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
83 #define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
84 #define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
86 #define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
87 #define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
88 #define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
89 #define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
90 #define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
91 #define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
92 #define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
93 #define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
95 #define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
97 /** Actual call to @ref getStream. */
98 #define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
99 zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
103 ///////////////////////////////////////////////////////////////////
105 { /////////////////////////////////////////////////////////////////
106 ///////////////////////////////////////////////////////////////////
108 { /////////////////////////////////////////////////////////////////
110 ///////////////////////////////////////////////////////////////////
112 { /////////////////////////////////////////////////////////////////
114 /** Definition of log levels.
119 E_XXX = 999, /**< Excessive logging. */
120 E_DBG = 0, /**< Debug or verbose. */
121 E_MIL, /**< Milestone. */
122 E_WAR, /**< Warning. */
123 E_ERR, /**< Error. */
124 E_SEC, /**< Secutrity related. */
125 E_INT, /**< Internal error. */
126 E_USR /**< User log. */
129 /** Return a log stream to write on.
131 * The returned log stream is determined by @a group_r and
132 * @a level_r. The remaining arguments @a file_r, @a func_r
133 * and @a line_r are expected to denote the location in the
134 * source code that issued the message.
136 * @note You won't call @ref getStream directly, but use the
137 * @ref ZYPP_BASE_LOGGER_MACROS.
139 extern std::ostream & getStream( const char * group_r,
144 extern bool isExcessive();
146 /////////////////////////////////////////////////////////////////
147 } // namespace logger
148 ///////////////////////////////////////////////////////////////////
150 /////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////
153 /////////////////////////////////////////////////////////////////
155 ///////////////////////////////////////////////////////////////////
156 #endif // ZYPP_BASE_LOGGER_H