Bug 1568157 - Part 4: Replace `toolbox.walker` with the contextual WalkerFront. r...
[gecko.git] / mozglue / linker / Logging.h
blob54e16ff091c126d9a612d2241fa9ff56e39803fc
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"
9 #include "mozilla/MacroArgs.h"
11 #ifdef ANDROID
12 # include <android/log.h>
13 # define LOG(...) \
14 __android_log_print(ANDROID_LOG_INFO, "GeckoLinker", __VA_ARGS__)
15 # define WARN(...) \
16 __android_log_print(ANDROID_LOG_WARN, "GeckoLinker", __VA_ARGS__)
17 # define ERROR(...) \
18 __android_log_print(ANDROID_LOG_ERROR, "GeckoLinker", __VA_ARGS__)
19 #else
20 # include <cstdio>
22 /* Expand to 1 or m depending on whether there is one argument or more
23 * given. */
24 # define MOZ_ONE_OR_MORE_ARGS_IMPL2(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, \
25 ...) \
27 # define MOZ_ONE_OR_MORE_ARGS_IMPL(args) MOZ_ONE_OR_MORE_ARGS_IMPL2 args
28 # define MOZ_ONE_OR_MORE_ARGS(...) \
29 MOZ_ONE_OR_MORE_ARGS_IMPL((__VA_ARGS__, m, m, m, m, m, m, m, m, 1, 0))
31 # define MOZ_MACRO_GLUE(a, b) a b
33 /* Some magic to choose between LOG1 and LOGm depending on the number of
34 * arguments */
35 # define MOZ_CHOOSE_LOG(...) \
36 MOZ_MACRO_GLUE(MOZ_CONCAT(LOG, MOZ_ONE_OR_MORE_ARGS(__VA_ARGS__)), \
37 (__VA_ARGS__))
39 # define LOG1(format) fprintf(stderr, format "\n")
40 # define LOGm(format, ...) fprintf(stderr, format "\n", __VA_ARGS__)
41 # define LOG(...) MOZ_CHOOSE_LOG(__VA_ARGS__)
42 # define WARN(...) MOZ_CHOOSE_LOG("Warning: " __VA_ARGS__)
43 # define ERROR(...) MOZ_CHOOSE_LOG("Error: " __VA_ARGS__)
45 #endif
47 class Logging {
48 public:
49 static bool isVerbose() { return Singleton.verbose; }
51 private:
52 bool verbose;
54 public:
55 static void Init() {
56 const char* env = getenv("MOZ_DEBUG_LINKER");
57 if (env && *env == '1') Singleton.verbose = true;
60 private:
61 static Logging Singleton;
64 #define DEBUG_LOG(...) \
65 do { \
66 if (MOZ_UNLIKELY(Logging::isVerbose())) { \
67 LOG(__VA_ARGS__); \
68 } \
69 } while (0)
71 #endif /* Logging_h */