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 void y2_logger_raw( const char* message );
00042
00043
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
00076
00077
00078
00079
00080
00081
00082
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