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 27947 2006-02-14 07:16:25Z visnov $
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 void y2_logger_raw( const char* message );
00042 
00043 /* Logging defines */
00044 
00045 #ifdef y2log_subcomponent
00046 #  define y2log_suffix "-" y2log_subcomponent
00047 #else
00048 #  define y2log_suffix
00049 #endif
00050 
00051 #ifdef y2log_component
00052 #  define y2log_prefix y2log_component y2log_suffix
00053 #else
00054 #  ifdef Y2LOG
00055 #    define y2log_prefix Y2LOG y2log_suffix
00056 #  else
00057 #    error neither y2log_component nor Y2LOG defined
00058 #    define y2log_prefix ""
00059 #  endif
00060 #endif
00061 
00062 #define y2_logger(level,comp,file,line,function,format,args...)         \
00063 do {                                                                    \
00064     if (should_be_logged (level, comp))                                 \
00065         y2_logger_function (level,comp,file,line,function,format,##args);\
00066 } while (0)
00067 
00068 #define y2_vlogger(level,comp,file,line,function,format,args)           \
00069 do {                                                                    \
00070     if (should_be_logged (level, comp))                                 \
00071         y2_vlogger_function (level,comp,file,line,function,format,args);\
00072 } while (0)
00073 
00074 /*
00075  * Caution: Don't use
00076  *     if (shouldbelogged(...) y2_logger(...)
00077  * above - this clashes with any
00078  *     if (...)
00079  *        y2error(...)
00080  *     else
00081  * since the "else" branch always refers to the inner (!) "if"
00082  * - in this case, the "if" of this macro :-((
00083  */
00084 
00085 #define y2logger(level, format, args...) \
00086     y2_logger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,##args)
00087 
00088 #define y2vlogger(level, format, ap) \
00089     y2_vlogger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,ap)
00090 
00091 #ifdef WITHOUT_Y2DEBUG
00092 #  define y2debug(format, args...)
00093 #else
00094 #  define y2debug(format, args...)      y2logger(LOG_DEBUG,format,##args)
00095 #endif
00096 
00097 #define y2milestone(format, args...)    y2logger(LOG_MILESTONE,format,##args)
00098 #define y2warning(format, args...)      y2logger(LOG_WARNING,format,##args)
00099 #define y2error(format, args...)        y2logger(LOG_ERROR,format,##args)
00100 #define y2security(format, args...)     y2logger(LOG_SECURITY,format,##args)
00101 #define y2internal(format, args...)     y2logger(LOG_INTERNAL,format,##args)
00102 
00103 #define y2lograw(message)               y2_logger_raw(message)
00104 
00107 bool should_be_logged (int loglevel, string componentname);
00108 
00117 void set_log_filename (string filename);
00118 string get_log_filename();
00119 
00126 void set_log_conf(string confname);
00127 
00131 void set_log_simple_mode(bool simple);
00132 
00137 void set_log_debug(bool on = true);
00138 
00142 bool get_log_debug();
00143 
00144 #endif /* _y2log_h */

Generated on Fri Jun 16 15:51:35 2006 for liby2util by  doxygen 1.4.6