Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
message_handler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_MESSAGE_HANDLER_H_
20 #define PAGESPEED_KERNEL_BASE_MESSAGE_HANDLER_H_
21 
22 #include <cstdarg>
23 
27 
28 namespace net_instaweb {
29 
30 class Writer;
31 
32 enum MessageType {
33  kInfo,
34  kWarning,
35  kError,
36  kFatal
37 };
38 
40  public:
42  virtual ~MessageHandler();
43 
45  const char* MessageTypeToString(const MessageType type) const;
46 
48  static MessageType StringToMessageType(const StringPiece& msg);
49 
52  void set_min_message_type(MessageType min) { min_message_type_ = min; }
53 
55  void Message(MessageType type, const char* msg, ...)
57  void MessageV(MessageType type, const char* msg, va_list args);
58 
60  void FileMessage(MessageType type, const char* filename, int line,
61  const char* msg, ...) INSTAWEB_PRINTF_FORMAT(5, 6);
62  void FileMessageV(MessageType type, const char* filename, int line,
63  const char* msg, va_list args);
64 
66  void Check(bool condition, const char* msg, ...) INSTAWEB_PRINTF_FORMAT(3, 4);
67  void CheckV(bool condition, const char* msg, va_list args);
68 
69 
73  void Info(const char* filename, int line, const char* msg, ...)
74  INSTAWEB_PRINTF_FORMAT(4, 5);
75  void Warning(const char* filename, int line, const char* msg, ...)
76  INSTAWEB_PRINTF_FORMAT(4, 5);
77  void Error(const char* filename, int line, const char* msg, ...)
78  INSTAWEB_PRINTF_FORMAT(4, 5);
79  void FatalError(const char* filename, int line, const char* msg, ...)
80  INSTAWEB_PRINTF_FORMAT(4, 5);
81 
82  void InfoV(const char* filename, int line, const char* msg, va_list args) {
83  FileMessageV(kInfo, filename, line, msg, args);
84  }
85  void WarningV(const char* filename, int line, const char* msg, va_list a) {
86  FileMessageV(kWarning, filename, line, msg, a);
87  }
88  void ErrorV(const char* filename, int line, const char* msg, va_list args) {
89  FileMessageV(kError, filename, line, msg, args);
90  }
91  void FatalErrorV(const char* fname, int line, const char* msg, va_list a) {
92  FileMessageV(kFatal, fname, line, msg, a);
93  }
94 
97  void MessageS(MessageType type, const GoogleString& message);
98  void FileMessageS(MessageType type, const char* filename, int line,
99  const GoogleString& message);
100 
104  virtual bool Dump(Writer* writer);
105 
107  virtual void ParseMessageDumpIntoMessages(
108  StringPiece message_dump, StringPieceVector* messages);
109 
111  virtual MessageType GetMessageType(StringPiece message);
112 
114  virtual StringPiece ReformatMessage(StringPiece message);
115 
116  protected:
119  virtual void MessageVImpl(MessageType type, const char* msg,
120  va_list args);
121  virtual void FileMessageVImpl(MessageType type, const char* filename,
122  int line, const char* msg, va_list args);
126  virtual void MessageSImpl(MessageType type, const GoogleString& message) = 0;
127  virtual void FileMessageSImpl(
128  MessageType type, const char* filename, int line,
129  const GoogleString& message) = 0;
131  void FormatTo(GoogleString* buffer, const char* msg, va_list args);
132 
133  private:
136  MessageType min_message_type_;
137 };
138 
140 #define PS_LOG_INFO(handler, ...) \
141  (handler)->Info(__FILE__, __LINE__, __VA_ARGS__)
142 #define PS_LOG_WARN(handler, ...) \
143  (handler)->Warning(__FILE__, __LINE__, __VA_ARGS__)
144 #define PS_LOG_ERROR(handler, ...) \
145  (handler)->Error(__FILE__, __LINE__, __VA_ARGS__)
146 #define PS_LOG_FATAL(handler, ...) \
147  (handler)->FatalError(__FILE__, __LINE__, __VA_ARGS__)
148 
149 #ifndef NDEBUG
150 #define PS_LOG_DFATAL(handler, ...) \
151  PS_LOG_FATAL(handler, __VA_ARGS__)
152 #else
153 #define PS_LOG_DFATAL(handler, ...) \
154  PS_LOG_ERROR(handler, __VA_ARGS__)
155 #endif
156 
157 #ifndef NDEBUG
160 #define PS_DLOG_INFO(handler, ...) \
161  PS_LOG_INFO(handler, __VA_ARGS__)
162 #define PS_DLOG_WARN(handler, ...) \
163  PS_LOG_WARN(handler, __VA_ARGS__)
164 #define PS_DLOG_ERROR(handler, ...) \
165  PS_LOG_ERROR(handler, __VA_ARGS__)
166 #else
167 inline void NoOpMacroPlaceholder() {}
171 
172 #define PS_DLOG_INFO(handler, ...) ::net_instaweb::NoOpMacroPlaceholder()
173 #define PS_DLOG_WARN(handler, ...) ::net_instaweb::NoOpMacroPlaceholder()
174 #define PS_DLOG_ERROR(handler, ...) ::net_instaweb::NoOpMacroPlaceholder()
175 #endif
176 }
177 
178 #endif
void Check(bool condition, const char *msg,...) INSTAWEB_PRINTF_FORMAT(3
Conditional errors.
virtual void MessageSImpl(MessageType type, const GoogleString &message)=0
void FileMessage(MessageType type, const char *filename, int line, const char *msg,...) INSTAWEB_PRINTF_FORMAT(5
Log a message with a filename and line number attached.
void Info(const char *filename, int line, const char *msg,...) INSTAWEB_PRINTF_FORMAT(4
virtual void ParseMessageDumpIntoMessages(StringPiece message_dump, StringPieceVector *messages)
Parse the dumped log into messages.
void MessageS(MessageType type, const GoogleString &message)
const char * MessageTypeToString(const MessageType type) const
String representation for MessageType.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual bool Dump(Writer *writer)
virtual StringPiece ReformatMessage(StringPiece message)
Make the message look more readable when rendering to history page.
virtual MessageType GetMessageType(StringPiece message)
Return the message type.
void Message(MessageType type, const char *msg,...) INSTAWEB_PRINTF_FORMAT(3
Log an info, warning, error or fatal error message.
void set_min_message_type(MessageType min)
Definition: message_handler.h:52
#define INSTAWEB_PRINTF_FORMAT(x, y)
< Not GCC
Definition: printf_format.h:34
void FormatTo(GoogleString *buffer, const char *msg, va_list args)
FormatTo appends to *buffer.
Definition: message_handler.h:39
virtual void MessageVImpl(MessageType type, const char *msg, va_list args)
static MessageType StringToMessageType(const StringPiece &msg)
Convert string to MessageType.