libzypp 17.35.1
Logger.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_BASE_LOGGER_H
13#define ZYPP_BASE_LOGGER_H
14#include <cstring>
15#include <iosfwd>
16#include <string>
17
18#include <zypp/Globals.h>
19
21#ifndef ZYPP_NDEBUG
22namespace zypp
23{
24 namespace debug
25 { // impl in LogControl.cc
26
27 // Log code loacaton and block leave
28 // Indent if nested
30 {
31 TraceLeave( const TraceLeave & ) =delete;
32 TraceLeave & operator=( const TraceLeave & ) =delete;
33 TraceLeave( const char * file_r, const char * fnc_r, int line_r );
35 private:
36 static unsigned _depth;
37 const char * _file;
38 const char * _fnc;
39 int _line;
40 };
41#define TRACE ::zypp::debug::TraceLeave _TraceLeave( __FILE__, __FUNCTION__, __LINE__ )
42
43 // OnScreenDebug messages colored to stderr
45 {
46 Osd( std::ostream &, int = 0 );
47 ~Osd();
48
49 template<class Tp>
50 Osd & operator<<( Tp && val )
51 {
54 return *this;
55 }
56
57 Osd & operator<<( std::ostream& (*iomanip)( std::ostream& ) );
58
59 private:
60 std::ostream & _strout;
61 std::ostream & _strlog;
62 };
63#define OSD ::zypp::debug::Osd(L_USR("OSD"))
64 }
65}
66#endif // ZYPP_NDEBUG
68
90
91#ifndef ZYPP_BASE_LOGGER_LOGGROUP
93#define ZYPP_BASE_LOGGER_LOGGROUP "DEFINE_LOGGROUP"
94#endif
95
96#define XXX L_XXX( ZYPP_BASE_LOGGER_LOGGROUP )
97#define DBG L_DBG( ZYPP_BASE_LOGGER_LOGGROUP )
98#define MIL L_MIL( ZYPP_BASE_LOGGER_LOGGROUP )
99#define WAR L_WAR( ZYPP_BASE_LOGGER_LOGGROUP )
100#define ERR L_ERR( ZYPP_BASE_LOGGER_LOGGROUP )
101#define SEC L_SEC( ZYPP_BASE_LOGGER_LOGGROUP )
102#define INT L_INT( ZYPP_BASE_LOGGER_LOGGROUP )
103#define USR L_USR( ZYPP_BASE_LOGGER_LOGGROUP )
104
105#define L_XXX(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_XXX )
106#define L_DBG(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP"++", zypp::base::logger::E_MIL )
107#define L_MIL(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_MIL )
108#define L_WAR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_WAR )
109#define L_ERR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_ERR )
110#define L_SEC(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_SEC )
111#define L_INT(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_INT )
112#define L_USR(GROUP) ZYPP_BASE_LOGGER_LOG( GROUP, zypp::base::logger::E_USR )
113
114
115#define L_ENV_CONSTR_DEFINE_FUNC(ENV) \
116 namespace zypp::log { \
117 bool has_env_constr_##ENV () \
118 { \
119 static bool has_##ENV = (::getenv(#ENV) != NULL); \
120 return has_##ENV; \
121 } \
122 const char *empty_or_group_if_##ENV ( const char *group ) \
123 { \
124 return has_env_constr_##ENV() ? group : nullptr; \
125 } \
126 }
127
128#define L_ENV_CONSTR_FWD_DECLARE_FUNC(ENV) namespace zypp::log { bool has_env_constr_##ENV (); const char *empty_or_group_if_##ENV ( const char *group ); }
129#define L_ENV_CONSTR(ENV,GROUP,LEVEL) ZYPP_BASE_LOGGER_LOG( zypp::log::empty_or_group_if_##ENV( GROUP ), LEVEL )
130
131#define L_BASEFILE ( *__FILE__ == '/' ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
132
134#define ZYPP_BASE_LOGGER_LOG(GROUP,LEVEL) \
135 zypp::base::logger::getStream( GROUP, LEVEL, L_BASEFILE, __FUNCTION__, __LINE__ )
136
140namespace zypp
141{
143 namespace base
144 {
145
147 namespace logger
148 {
149
164
175 extern std::ostream & getStream( const char * group_r,
176 LogLevel level_r,
177 const char * file_r,
178 const char * func_r,
179 const int line_r ) ZYPP_API;
180 extern bool isExcessive() ZYPP_API;
181
183 } // namespace logger
185
187 } // namespace base
190} // namespace zypp
192#endif // ZYPP_BASE_LOGGER_H
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
LogLevel
Definition of log levels.
Definition Logger.h:154
@ E_SEC
Secutrity related.
Definition Logger.h:160
@ E_XXX
Excessive logging.
Definition Logger.h:155
@ E_DBG
Debug or verbose.
Definition Logger.h:156
@ E_USR
User log.
Definition Logger.h:162
@ E_WAR
Warning.
Definition Logger.h:158
@ E_MIL
Milestone.
Definition Logger.h:157
@ E_INT
Internal error.
Definition Logger.h:161
std::ostream & getStream(const char *group_r, LogLevel level_r, const char *file_r, const char *func_r, const int line_r)
Return a log stream to write on.
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
std::ostream & _strlog
Definition Logger.h:61
std::ostream & _strout
Definition Logger.h:60
Osd & operator<<(Tp &&val)
Definition Logger.h:50
TraceLeave(const TraceLeave &)=delete
static unsigned _depth
Definition Logger.h:36
TraceLeave & operator=(const TraceLeave &)=delete
const char * _fnc
Definition Logger.h:38
const char * _file
Definition Logger.h:37