00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_MESSAGE_HANDLER_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_MESSAGE_HANDLER_H_
00021
00022 #include <cstdarg>
00023
00024 #include "net/instaweb/util/public/printf_format.h"
00025 #include "net/instaweb/util/public/string_util.h"
00026
00027 namespace net_instaweb {
00028
00029 enum MessageType {
00030 kInfo,
00031 kWarning,
00032 kError,
00033 kFatal
00034 };
00035
00036 class MessageHandler {
00037 public:
00038 MessageHandler();
00039 virtual ~MessageHandler();
00040
00042 const char* MessageTypeToString(const MessageType type) const;
00043
00045 static const MessageType StringToMessageType(const StringPiece& msg);
00046
00049 void set_min_message_type(MessageType min) { min_message_type_ = min; }
00050
00052 void Message(MessageType type, const char* msg, ...)
00053 INSTAWEB_PRINTF_FORMAT(3, 4);
00054 void MessageV(MessageType type, const char* msg, va_list args);
00055
00057 void FileMessage(MessageType type, const char* filename, int line,
00058 const char* msg, ...) INSTAWEB_PRINTF_FORMAT(5, 6);
00059 void FileMessageV(MessageType type, const char* filename, int line,
00060 const char* msg, va_list args);
00061
00062
00064 void Check(bool condition, const char* msg, ...) INSTAWEB_PRINTF_FORMAT(3, 4);
00065 void CheckV(bool condition, const char* msg, va_list args);
00066
00067
00071 void Info(const char* filename, int line, const char* msg, ...)
00072 INSTAWEB_PRINTF_FORMAT(4, 5);
00073 void Warning(const char* filename, int line, const char* msg, ...)
00074 INSTAWEB_PRINTF_FORMAT(4, 5);
00075 void Error(const char* filename, int line, const char* msg, ...)
00076 INSTAWEB_PRINTF_FORMAT(4, 5);
00077 void FatalError(const char* filename, int line, const char* msg, ...)
00078 INSTAWEB_PRINTF_FORMAT(4, 5);
00079
00080 void InfoV(const char* filename, int line, const char* msg, va_list args) {
00081 FileMessageV(kInfo, filename, line, msg, args);
00082 }
00083 void WarningV(const char* filename, int line, const char* msg, va_list a) {
00084 FileMessageV(kWarning, filename, line, msg, a);
00085 }
00086 void ErrorV(const char* filename, int line, const char* msg, va_list args) {
00087 FileMessageV(kError, filename, line, msg, args);
00088 }
00089 void FatalErrorV(const char* fname, int line, const char* msg, va_list a) {
00090 FileMessageV(kFatal, fname, line, msg, a);
00091 }
00092
00093 protected:
00094 virtual void MessageVImpl(MessageType type, const char* msg,
00095 va_list args) = 0;
00096 virtual void FileMessageVImpl(MessageType type, const char* filename,
00097 int line, const char* msg, va_list args) = 0;
00098
00099 private:
00102 MessageType min_message_type_;
00103 };
00104
00105 }
00106
00107 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_MESSAGE_HANDLER_H_