1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 // Log messages to stdout. LOG() prints normal user messages, VLOG()
8 // is verbose, for tracing and debugging. SetVerbose() enables/disables
11 // LOG() and VLOG() are printf-like, and arguments are checked by gcc.
12 // LOG_IF() and VLOG_IF() call LOG/VLOG if their predicate is true.
13 // CHECK() aborts if its predicate is false. NOTREACHED() always aborts.
14 // Logging is not thread-safe.
17 #ifndef TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_
18 #define TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_
31 namespace relocation_packer {
33 // If gcc, define PRINTF_ATTRIBUTE so that gcc checks Log() as printf-like.
34 #if defined(__GNUC__) && (__GNUC__ >= 3)
35 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \
36 __attribute__((__format__(__printf__, string_index, first_to_check)))
38 #define PRINTF_ATTRIBUTE(string_index, first_to_check)
41 // Logging and checking macros.
42 #define LOG(...) ::relocation_packer::Logger::Log(__VA_ARGS__)
43 #define VLOG(...) ::relocation_packer::Logger::VLog(__VA_ARGS__)
44 #define LOG_IF(cond, ...) \
49 #define VLOG_IF(cond, ...) \
55 #define CHECK(expr) assert((expr))
56 #define NOTREACHED(_) assert(false)
60 // Log and verbose log to stdout.
61 // |format| is a printf format string.
62 static void Log(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
63 static void VLog(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
66 // |flag| is true to enable verbose logging, false to disable it.
67 static void SetVerbose(bool flag);
70 Logger() : is_verbose_(false) { }
73 // Implementation of log to stdout.
74 // |format| is a printf format string.
75 // |args| is a varargs list of printf arguments.
76 void Log(const char* format, va_list args);
78 // If set, VLOG is enabled, otherwise it is a no-op.
81 // Singleton support. Not thread-safe.
82 static Logger* GetInstance();
83 static Logger* instance_;
86 } // namespace relocation_packer
88 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_