00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00022
00023 enum loglevel_t {
00024 LOG_DEBUG = 0,
00025 LOG_MILESTONE = 1,
00026 LOG_WARNING = 2,
00027 LOG_ERROR = 3,
00028 LOG_SECURITY = 4,
00029 LOG_INTERNAL = 5
00030 };
00031
00032
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
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
00074
00075
00076
00077
00078
00079
00080
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