Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

y2log.h

Go to the documentation of this file.
00001 /* y2log.h
00002  *
00003  * YaST2: Core system
00004  *
00005  * YaST2 logging implementation
00006  *
00007  * Authors: Mathias Kettner <kettner@suse.de>
00008  *          Michal Svec <msvec@suse.cz>
00009  *
00010  * $Id: y2log.h,v 1.5 2004/03/02 09:12:05 lnussel Exp $
00011  */
00012 
00013 #ifndef _y2log_h
00014 #define _y2log_h
00015 
00016 #include <string>
00017 #include <stdio.h>
00018 
00019 using std::string;
00020 
00021 /* Logging levels */
00022 
00023 enum loglevel_t {
00024     LOG_DEBUG = 0,      // debug message
00025     LOG_MILESTONE = 1,  // log great events, big steps
00026     LOG_WARNING = 2,    // warning in application level
00027     LOG_ERROR = 3,      // error in application level
00028     LOG_SECURITY = 4,   // security relevant problem or incident
00029     LOG_INTERNAL = 5    // internal bug. Please report to...
00030 };
00031 
00032 /* Logging functions */
00033 
00034 void y2_logger_function (loglevel_t level, const char *component, const char *file,
00035                 const int line, const char *func, const char *format, ...)
00036     __attribute__ ((format (printf, 6, 7)));
00037 
00038 void y2_vlogger_function (loglevel_t level, const char *component, const char *file,
00039                  const int line, const char *func, const char *format, va_list ap);
00040 
00041 /* Logging defines */
00042 
00043 #ifdef y2log_subcomponent
00044 #  define y2log_suffix "-" y2log_subcomponent
00045 #else
00046 #  define y2log_suffix
00047 #endif
00048 
00049 #ifdef y2log_component
00050 #  define y2log_prefix y2log_component y2log_suffix
00051 #else
00052 #  ifdef Y2LOG
00053 #    define y2log_prefix Y2LOG y2log_suffix
00054 #  else
00055 #    error neither y2log_component nor Y2LOG defined
00056 #    define y2log_prefix ""
00057 #  endif
00058 #endif
00059 
00060 #define y2_logger(level,comp,file,line,function,format,args...)         \
00061 do {                                                                    \
00062     if (should_be_logged (level, comp))                                 \
00063         y2_logger_function (level,comp,file,line,function,format,##args);\
00064 } while (0)
00065 
00066 #define y2_vlogger(level,comp,file,line,function,format,args)           \
00067 do {                                                                    \
00068     if (should_be_logged (level, comp))                                 \
00069         y2_vlogger_function (level,comp,file,line,function,format,args);\
00070 } while (0)
00071 
00072 /*
00073  * Caution: Don't use
00074  *     if (shouldbelogged(...) y2_logger(...)
00075  * above - this clashes with any
00076  *     if (...)
00077  *        y2error(...)
00078  *     else
00079  * since the "else" branch always refers to the inner (!) "if"
00080  * - in this case, the "if" of this macro :-((
00081  */
00082 
00083 #define y2logger(level, format, args...) \
00084     y2_logger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,##args)
00085 
00086 #define y2vlogger(level, format, ap) \
00087     y2_vlogger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,ap)
00088 
00089 #ifdef WITHOUT_Y2DEBUG
00090 #  define y2debug(format, args...)
00091 #else
00092 #  define y2debug(format, args...)      y2logger(LOG_DEBUG,format,##args)
00093 #endif
00094 
00095 #define y2milestone(format, args...)    y2logger(LOG_MILESTONE,format,##args)
00096 #define y2warning(format, args...)      y2logger(LOG_WARNING,format,##args)
00097 #define y2error(format, args...)        y2logger(LOG_ERROR,format,##args)
00098 #define y2security(format, args...)     y2logger(LOG_SECURITY,format,##args)
00099 #define y2internal(format, args...)     y2logger(LOG_INTERNAL,format,##args)
00100 
00103 bool should_be_logged (int loglevel, string componentname);
00104 
00113 void set_log_filename (string filename);
00114 string get_log_filename();
00115 
00122 void set_log_conf(string confname);
00123 
00127 void set_log_simple_mode(bool simple);
00128 
00133 void set_log_debug(bool on = true);
00134 
00138 bool get_log_debug();
00139 
00140 #endif /* _y2log_h */

Generated on Thu Feb 23 23:56:10 2006 for liby2util by doxygen 1.3.6