2004-04-07 06:51:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
// the __attribute((format...)) tags are GCC extensions that let the compiler
|
|
|
|
// do like-checking on printf-like arguments
|
2004-04-08 08:15:23 +00:00
|
|
|
//
|
2004-04-07 06:51:42 +00:00
|
|
|
#if !defined(__GNUC__) && !defined(__attribute__)
|
|
|
|
#define __attribute__(x) /*nothing*/
|
|
|
|
#endif
|
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#define __attribute__(x) /*nothing*/
|
|
|
|
#endif
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
class MSG_LOG {
|
2004-04-07 06:51:42 +00:00
|
|
|
int debug_level;
|
|
|
|
int indent_level;
|
|
|
|
char spaces[80];
|
|
|
|
FILE* output;
|
|
|
|
public:
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
MSG_LOG(FILE* output);
|
2004-04-07 06:51:42 +00:00
|
|
|
void enter_level(int = 1);
|
|
|
|
void leave_level() { enter_level(-1); }
|
2004-04-08 08:15:23 +00:00
|
|
|
MSG_LOG& operator++() { enter_level(); return *this; }
|
|
|
|
MSG_LOG& operator--() { leave_level(); return *this; }
|
2004-04-07 06:51:42 +00:00
|
|
|
|
|
|
|
void printf(int kind, const char* format, ...) __attribute__ ((format (printf, 3, 4)));
|
|
|
|
void printf_multiline(int kind, const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 4, 5)));
|
|
|
|
void printf_file(int kind, const char* filename, const char* prefix_format, ...) __attribute__ ((format (printf, 4, 5)));
|
|
|
|
void vprintf(int kind, const char* format, va_list va);
|
|
|
|
void vprintf_multiline(int kind, const char* str, const char* prefix_format, va_list va);
|
|
|
|
void vprintf_file(int kind, const char* filename, const char* prefix_format, va_list va);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual const char* v_format_kind(int kind) const = 0;
|
|
|
|
virtual bool v_message_wanted(int kind) const = 0;
|
|
|
|
};
|
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
// automatically ++/--MSG_LOG on scope entry / exit.
|
|
|
|
// See lib/msg_log.C for commentary
|
|
|
|
//
|
|
|
|
class SCOPE_MSG_LOG {
|
|
|
|
MSG_LOG& messages;
|
2004-04-07 06:51:42 +00:00
|
|
|
int kind;
|
|
|
|
public:
|
2004-04-08 08:15:23 +00:00
|
|
|
SCOPE_MSG_LOG(MSG_LOG& messages_, int kind_) : messages(messages_), kind(kind_)
|
2004-04-07 06:51:42 +00:00
|
|
|
{ ++messages; }
|
2004-04-08 08:15:23 +00:00
|
|
|
~SCOPE_MSG_LOG() { --messages; }
|
|
|
|
SCOPE_MSG_LOG& operator++() { ++messages; return *this; }
|
|
|
|
SCOPE_MSG_LOG& operator--() { --messages; return *this; }
|
2004-04-07 06:51:42 +00:00
|
|
|
|
|
|
|
void printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));
|
|
|
|
void printf_multiline(const char* str, const char* prefix_format, ...) __attribute__ ((format (printf, 3, 4)));
|
|
|
|
void printf_file(const char* filename, const char* prefix_format, ...) __attribute__ ((format (printf, 3, 4)));
|
|
|
|
};
|
|
|
|
|