summaryrefslogtreecommitdiff
path: root/Log.hh
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-06-01 11:02:24 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-06-01 11:02:24 +0800
commit241f27a653330af1227694947626f409c3b128e2 (patch)
tree02f2eb98a78e7de6b8ccb9af1016688b009ecb63 /Log.hh
parentf3729aee72a60578738f0c2fddcca2831019f546 (diff)
message formatting, assembly and object support
Diffstat (limited to 'Log.hh')
-rw-r--r--Log.hh31
1 files changed, 28 insertions, 3 deletions
diff --git a/Log.hh b/Log.hh
index f18500c..561ccf2 100644
--- a/Log.hh
+++ b/Log.hh
@@ -4,14 +4,39 @@
#include <cstdarg>
#include <cstdio>
+#include <llvm/Support/FormatVariadic.h>
+#include <llvm/Support/WithColor.h>
+
namespace pcc {
enum LogLevel { PCC_DEBUG, PCC_INFO, PCC_WARNING, PCC_ERROR };
-extern LogLevel CurrentLogLevel;
-
void SetLogLevel(LogLevel level);
+LogLevel GetLogLevel();
+
+void SetExecutableName(const char* name);
+const char* GetExecutableName();
-void Log(LogLevel level, const char* format, ...);
+template <typename... Args>
+void Log(LogLevel level, const char* format, Args&&... args) {
+ auto msg = llvm::formatv(format, std::forward<Args>(args)...);
+ const char* name = GetExecutableName();
+ switch (level) {
+ case PCC_DEBUG:
+ llvm::WithColor::remark(llvm::errs(), name) << msg << '\n';
+ break;
+ case PCC_INFO:
+ llvm::WithColor::note(llvm::errs(), name) << msg << '\n';
+ break;
+ case PCC_WARNING:
+ llvm::WithColor::warning(llvm::errs(), name) << msg << '\n';
+ break;
+ case PCC_ERROR:
+ llvm::WithColor::error(llvm::errs(), name) << msg << '\n';
+ break;
+ default:
+ break;
+ }
+}
} // namespace pcc
#endif