Bumping manifests a=b2g-bump
[gecko.git] / mozglue / linker / Logging.h
blob046d918f4a8b5ad9593a06726d2f0d9dce45a814
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef Logging_h
6 #define Logging_h
8 #include "mozilla/Likely.h"
10 #ifdef ANDROID
11 #include <android/log.h>
12 #define LOG(...) __android_log_print(ANDROID_LOG_INFO, "GeckoLinker", __VA_ARGS__)
13 #define WARN(...) __android_log_print(ANDROID_LOG_WARN, "GeckoLinker", __VA_ARGS__)
14 #define ERROR(...) __android_log_print(ANDROID_LOG_ERROR, "GeckoLinker", __VA_ARGS__)
15 #else
16 #include <cstdio>
18 /* Expand to 1 or m depending on whether there is one argument or more
19 * given. */
20 #define MOZ_ONE_OR_MORE_ARGS_IMPL2(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) \
22 #define MOZ_ONE_OR_MORE_ARGS_IMPL(args) MOZ_ONE_OR_MORE_ARGS_IMPL2 args
23 #define MOZ_ONE_OR_MORE_ARGS(...) \
24 MOZ_ONE_OR_MORE_ARGS_IMPL((__VA_ARGS__, m, m, m, m, m, m, m, m, 1, 0))
26 #define MOZ_MACRO_GLUE(a, b) a b
27 #define MOZ_CONCAT2(a, b) a ## b
28 #define MOZ_CONCAT1(a, b) MOZ_CONCAT2(a, b)
29 #define MOZ_CONCAT(a, b) MOZ_CONCAT1(a, b)
31 /* Some magic to choose between LOG1 and LOGm depending on the number of
32 * arguments */
33 #define MOZ_CHOOSE_LOG(...) \
34 MOZ_MACRO_GLUE(MOZ_CONCAT(LOG, MOZ_ONE_OR_MORE_ARGS(__VA_ARGS__)), \
35 (__VA_ARGS__))
37 #define LOG1(format) fprintf(stderr, format "\n")
38 #define LOGm(format, ...) fprintf(stderr, format "\n", __VA_ARGS__)
39 #define LOG(...) MOZ_CHOOSE_LOG(__VA_ARGS__)
40 #define WARN(...) MOZ_CHOOSE_LOG("Warning: " __VA_ARGS__)
41 #define ERROR(...) MOZ_CHOOSE_LOG("Error: " __VA_ARGS__)
43 #endif
45 class Logging
47 public:
48 static bool isVerbose()
50 return Singleton.verbose;
53 private:
54 bool verbose;
56 public:
57 static void Init()
59 const char *env = getenv("MOZ_DEBUG_LINKER");
60 if (env && *env == '1')
61 Singleton.verbose = true;
64 private:
65 static Logging Singleton;
68 #define DEBUG_LOG(...) \
69 do { \
70 if (MOZ_UNLIKELY(Logging::isVerbose())) { \
71 LOG(__VA_ARGS__); \
72 } \
73 } while(0)
75 #if defined(__LP64__)
76 # define PRIxAddr "lx"
77 # define PRIxSize "lx"
78 # define PRIdSize "ld"
79 # define PRIuSize "lu"
80 #else
81 # define PRIxAddr "x"
82 # define PRIxSize "x"
83 # define PRIdSize "d"
84 # define PRIuSize "u"
85 #endif
87 #endif /* Logging_h */