yast2-core
liby2util-r/src/include/y2util/y2log.h
Go to the documentation of this file.
1 /* y2log.h
2  *
3  * YaST2: Core system
4  *
5  * YaST2 logging implementation
6  *
7  * Authors: Mathias Kettner <kettner@suse.de>
8  * Michal Svec <msvec@suse.cz>
9  *
10  * $Id$
11  */
12 
13 #ifndef _y2log_h
14 #define _y2log_h
15 
16 #include <string>
17 #include <stdio.h>
18 
19 using std::string;
20 
21 /* Logging levels */
22 
23 enum loglevel_t {
24  LOG_DEBUG = 0, // debug message
25  LOG_MILESTONE = 1, // log great events, big steps
26  LOG_WARNING = 2, // warning in application level
27  LOG_ERROR = 3, // error in application level
28  LOG_SECURITY = 4, // security relevant problem or incident
29  LOG_INTERNAL = 5 // internal bug. Please report to...
30 };
31 
32 /* Logging functions */
33 
34 // Implements y2_logger
35 void y2_logger_function (loglevel_t level, const string& component, const char *file,
36  const int line, const char *func, const char *format, ...)
37  __attribute__ ((format (printf, 6, 7)));
38 // The knights of Blanik only show up when nothing else can help, and so will
39 // the messages logged here. fate#302166
40 void y2_logger_blanik (loglevel_t level, const string& component, const char *file,
41  const int line, const char *func, const char *format, ...)
42  __attribute__ ((format (printf, 6, 7)));
43 
44 // Same as above, but with va_list
45 void y2_vlogger_function (loglevel_t level, const string& component, const char *file,
46  const int line, const char *func, const char *format, va_list ap);
47 void y2_vlogger_blanik (loglevel_t level, const string& component, const char *file,
48  const int line, const char *func, const char *format, va_list ap);
49 
50 void y2_logger_raw( const char* message );
51 
52 /* Logging defines */
53 
54 #ifdef y2log_subcomponent
55 # define y2log_suffix "-" y2log_subcomponent
56 #else
57 # define y2log_suffix
58 #endif
59 
60 #ifdef y2log_component
61 # define y2log_prefix y2log_component y2log_suffix
62 #else
63 # ifdef Y2LOG
64 # define y2log_prefix Y2LOG y2log_suffix
65 # else
66 # error neither y2log_component nor Y2LOG defined
67 # define y2log_prefix ""
68 # endif
69 #endif
70 
71 #define y2_logger(level,comp,file,line,function,format,args...) \
72 do { \
73  if (should_be_logged (level, comp)) \
74  y2_logger_function (level,comp,file,line,function,format,##args);\
75  else if (should_be_buffered ()) \
76  y2_logger_blanik (level,comp,file,line,function,format,##args); \
77 } while (0)
78 
79 #define y2_vlogger(level,comp,file,line,function,format,args) \
80 do { \
81  if (should_be_logged (level, comp)) \
82  y2_vlogger_function (level,comp,file,line,function,format,args);\
83  else if (should_be_buffered ()) \
84  y2_vlogger_blanik (level,comp,file,line,function,format,args); \
85 } while (0)
86 
87 /*
88  * Caution: Don't use
89  * if (shouldbelogged(...) y2_logger(...)
90  * above - this clashes with any
91  * if (...)
92  * y2error(...)
93  * else
94  * since the "else" branch always refers to the inner (!) "if"
95  * - in this case, the "if" of this macro :-((
96  */
97 
98 #define y2logger(level, format, args...) \
99  y2_logger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,##args)
100 
101 #define y2vlogger(level, format, ap) \
102  y2_vlogger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,ap)
103 
104 #ifdef WITHOUT_Y2DEBUG
105 # define y2debug(format, args...)
106 #else
107 # define y2debug(format, args...) y2logger(LOG_DEBUG,format,##args)
108 #endif
109 
110 #define y2milestone(format, args...) y2logger(LOG_MILESTONE,format,##args)
111 #define y2warning(format, args...) y2logger(LOG_WARNING,format,##args)
112 #define y2error(format, args...) y2logger(LOG_ERROR,format,##args)
113 #define y2security(format, args...) y2logger(LOG_SECURITY,format,##args)
114 #define y2internal(format, args...) y2logger(LOG_INTERNAL,format,##args)
115 
116 #define y2lograw(message) y2_logger_raw(message)
117 
121 bool should_be_logged (int loglevel, const string& componentname);
122 
126 bool should_be_buffered ();
127 
136 void set_log_filename (string filename);
137 string get_log_filename();
138 
145 void set_log_conf(string confname);
146 
150 void set_log_simple_mode(bool simple);
151 
156 void set_log_debug(bool on = true);
157 
161 bool get_log_debug();
162 
163 // stores a few strings. can append one. can return all. old are forgotten.
164 class LogTail {
165 public:
166  typedef string Data;
167  LogTail (size_t max_size = 42);
168  ~LogTail ();
169  void push_back (const Data &);
170 
171  // consumer returns true to continue iterating
172  typedef bool (* Consumer) (const Data &);
173  void for_each (Consumer c);
174 private:
175  class Impl;
176  Impl *m_impl;
177 };
178 
179 // the instance used for last resort logging
180 extern LogTail blanik;
181 
182 #endif /* _y2log_h */
Definition: liby2util-r/src/include/y2util/y2log.h:24
Definition: liby2util-r/src/include/y2util/y2log.h:29
~LogTail()
Definition: y2log.cc:635
void set_log_debug(bool on=true)
Definition: y2log.cc:584
string Data
Definition: liby2util-r/src/include/y2util/y2log.h:166
void void y2_logger_blanik(loglevel_t level, const string &component, const char *file, const int line, const char *func, const char *format,...) __attribute__((format(printf
Definition: liby2util-r/src/include/y2util/y2log.h:25
Definition: y2log.cc:603
void set_log_simple_mode(bool simple)
Definition: y2log.cc:580
loglevel_t
Definition: liby2util-r/src/include/y2util/y2log.h:23
bool get_log_debug()
Definition: y2log.cc:589
bool(* Consumer)(const Data &)
Definition: liby2util-r/src/include/y2util/y2log.h:172
Definition: liby2util-r/src/include/y2util/y2log.h:164
void y2_logger_function(loglevel_t level, const string &component, const char *file, const int line, const char *func, const char *format,...) __attribute__((format(printf
Impl * m_impl
Definition: liby2util-r/src/include/y2util/y2log.h:175
void for_each(Consumer c)
Definition: y2log.cc:644
LogTail blanik
Definition: y2log.cc:650
void push_back(const Data &)
Definition: y2log.cc:640
string get_log_filename()
Definition: y2log.cc:425
Definition: liby2util-r/src/include/y2util/y2log.h:27
bool should_be_logged(int loglevel, const string &componentname)
Definition: y2log.cc:550
void set_log_conf(string confname)
Definition: y2log.cc:506
void set_log_filename(string filename)
Definition: y2log.cc:365
bool should_be_buffered()
Definition: y2log.cc:597
std::string format(const char *format,...)
Definition: IniParser.cc:1027
LogTail(size_t max_size=42)
Definition: y2log.cc:630
void y2_vlogger_blanik(loglevel_t level, const string &component, const char *file, const int line, const char *func, const char *format, va_list ap)
Definition: y2log.cc:301
Definition: liby2util-r/src/include/y2util/y2log.h:26
Definition: liby2util-r/src/include/y2util/y2log.h:28
void y2_logger_raw(const char *message)
Definition: y2log.cc:323
void void void y2_vlogger_function(loglevel_t level, const string &component, const char *file, const int line, const char *func, const char *format, va_list ap)
Definition: y2log.cc:280

Generated on a sunny day for yast2-core by doxygen 1.8.8