From 8119729fb0538dc0b92961c4444385f3de22423c Mon Sep 17 00:00:00 2001
From: janis <janis@nirgendwo.xyz>
Date: Mon, 20 Jun 2022 22:46:11 +0100
Subject: [PATCH] GLOG comat macro LOG_F

---
 Alloy.toml          |  3 ++-
 include/journal.hpp | 25 ++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Alloy.toml b/Alloy.toml
index 9789ded..6b597aa 100644
--- a/Alloy.toml
+++ b/Alloy.toml
@@ -6,8 +6,9 @@ version = "0.1.0"
 
 [lib]
 name = "libjournal"
+cc-flags = ["-DJOURNAL_GLOG_COMPAT"]
 
 [[bin]]
 name = "journal"
-cc-flags = ["-DJOURNAL_ALL", "-gcodeview", "-g"]
+cc-flags = ["-DJOURNAL_GLOG_COMPAT", "-DJOURNAL_ALL", "-gcodeview", "-g"]
 ld-flags = ["-g", "-gcodeview"]
\ No newline at end of file
diff --git a/include/journal.hpp b/include/journal.hpp
index ca78a62..079e670 100644
--- a/include/journal.hpp
+++ b/include/journal.hpp
@@ -76,7 +76,11 @@ auto add_sink(std::shared_ptr<std::ostream> stream,
               const LogVerbosity &min = LogVerbosity::Trace,
               const LogVerbosity &max = LogVerbosity::Error) -> void;
 
-#ifdef JOURNAL_ALL
+/// JOURNAL_NONE: undefines all logs
+/// JOURNAL_ALL: defines all logs, on by default
+/// JOURNAL_NOT_ALL: does not define any logs by default even it JOURNAL_ALL is
+/// defined, off by default
+#if defined(JOURNAL_ALL) && !defined(JOURNAL_NONE) && !defined(JOURNAL_NOT_ALL)
 #define JOURNAL_TRACE
 #define JOURNAL_DEBUG
 #define JOURNAL_INFO
@@ -84,6 +88,14 @@ auto add_sink(std::shared_ptr<std::ostream> stream,
 #define JOURNAL_ERROR
 #endif
 
+#if defined(JOURNAL_NONE)
+#undef JOURNAL_TRACE
+#undef JOURNAL_DEBUG
+#undef JOURNAL_INFO
+#undef JOURNAL_WARN
+#undef JOURNAL_ERROR
+#endif
+
 #ifdef JOURNAL_TRACE
 template <typename... Args>
 inline constexpr auto
@@ -149,4 +161,15 @@ template <typename... Args>
 inline constexpr auto error(std::string_view fmt, Args... args) -> void {}
 #endif
 
+/// JOURNAL_GLOG_COMPAT: enables LOG_F macro format which GLOG and Loguru use
+/// for compatibility, on by default
+#if defined(JOURNAL_GLOG_COMPAT)
+#define LOG_F_TRACE(...) trace(__VA_ARGS__)
+#define LOG_F_DEBUG(...) debug(__VA_ARGS__)
+#define LOG_F_INFO(...) info(__VA_ARGS__)
+#define LOG_F_WARN(...) warn(__VA_ARGS__)
+#define LOG_F_ERROR(...) error(__VA_ARGS__)
+#define LOG_F(V, ...) LOG_F_##V(__VA_ARGS__)
+#endif
+
 } // namespace journal
\ No newline at end of file