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
00035 void y2_logger_function (loglevel_t level, const char *component, const char *file,
00036 const int line, const char *func, const char *format, ...)
00037 __attribute__ ((format (printf, 6, 7)));
00038
00039
00040 void y2_logger_blanik (loglevel_t level, const char *component, const char *file,
00041 const int line, const char *func, const char *format, ...)
00042 __attribute__ ((format (printf, 6, 7)));
00043
00044
00045 void y2_vlogger_function (loglevel_t level, const char *component, const char *file,
00046 const int line, const char *func, const char *format, va_list ap);
00047 void y2_vlogger_blanik (loglevel_t level, const char *component, const char *file,
00048 const int line, const char *func, const char *format, va_list ap);
00049
00050 void y2_logger_raw( const char* message );
00051
00052
00053
00054 #ifdef y2log_subcomponent
00055 # define y2log_suffix "-" y2log_subcomponent
00056 #else
00057 # define y2log_suffix
00058 #endif
00059
00060 #ifdef y2log_component
00061 # define y2log_prefix y2log_component y2log_suffix
00062 #else
00063 # ifdef Y2LOG
00064 # define y2log_prefix Y2LOG y2log_suffix
00065 # else
00066 # error neither y2log_component nor Y2LOG defined
00067 # define y2log_prefix ""
00068 # endif
00069 #endif
00070
00071 #define y2_logger(level,comp,file,line,function,format,args...) \
00072 do { \
00073 if (should_be_logged (level, comp)) \
00074 y2_logger_function (level,comp,file,line,function,format,##args);\
00075 else if (should_be_buffered ()) \
00076 y2_logger_blanik (level,comp,file,line,function,format,##args); \
00077 } while (0)
00078
00079 #define y2_vlogger(level,comp,file,line,function,format,args) \
00080 do { \
00081 if (should_be_logged (level, comp)) \
00082 y2_vlogger_function (level,comp,file,line,function,format,args);\
00083 else if (should_be_buffered ()) \
00084 y2_vlogger_blanik (level,comp,file,line,function,format,args); \
00085 } while (0)
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 #define y2logger(level, format, args...) \
00099 y2_logger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,##args)
00100
00101 #define y2vlogger(level, format, ap) \
00102 y2_vlogger(level,y2log_prefix,__FILE__,__LINE__,__FUNCTION__,format,ap)
00103
00104 #ifdef WITHOUT_Y2DEBUG
00105 # define y2debug(format, args...)
00106 #else
00107 # define y2debug(format, args...) y2logger(LOG_DEBUG,format,##args)
00108 #endif
00109
00110 #define y2milestone(format, args...) y2logger(LOG_MILESTONE,format,##args)
00111 #define y2warning(format, args...) y2logger(LOG_WARNING,format,##args)
00112 #define y2error(format, args...) y2logger(LOG_ERROR,format,##args)
00113 #define y2security(format, args...) y2logger(LOG_SECURITY,format,##args)
00114 #define y2internal(format, args...) y2logger(LOG_INTERNAL,format,##args)
00115
00116 #define y2lograw(message) y2_logger_raw(message)
00117
00121 bool should_be_logged (int loglevel, string componentname);
00125 bool should_be_buffered ();
00126
00135 void set_log_filename (string filename);
00136 string get_log_filename();
00137
00144 void set_log_conf(string confname);
00145
00149 void set_log_simple_mode(bool simple);
00150
00155 void set_log_debug(bool on = true);
00156
00160 bool get_log_debug();
00161
00162
00163 class LogTail {
00164 public:
00165 typedef string Data;
00166 LogTail (size_t max_size = 42);
00167 ~LogTail ();
00168 void push_back (const Data &);
00169
00170
00171 typedef bool (* Consumer) (const Data &);
00172 void for_each (Consumer c);
00173 private:
00174 class Impl;
00175 Impl *m_impl;
00176 };
00177
00178
00179 extern LogTail blanik;
00180
00181 #endif