LLVM 22.0.0git
Logging.h
Go to the documentation of this file.
1//===- Logging.h - LSP Server Logging ----------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_SUPPORT_LSP_LOGGING_H
10#define LLVM_SUPPORT_LSP_LOGGING_H
11
12#include "llvm/Support/Debug.h"
14#include <mutex>
15
16namespace llvm {
17namespace lsp {
18
19/// This class represents the main interface for logging, and allows for
20/// filtering logging based on different levels of severity or significance.
21class Logger {
22public:
23 /// The level of significance for a log message.
24 enum class Level { Debug, Info, Error };
25
26 /// Set the severity level of the logger.
27 LLVM_ABI_FOR_TEST static void setLogLevel(Level LogLevel);
28
29 /// Initiate a log message at various severity levels. These should be called
30 /// after a call to `initialize`.
31 template <typename... Ts> static void debug(const char *Fmt, Ts &&...Vals) {
32 log(Level::Debug, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
33 }
34 template <typename... Ts> static void info(const char *Fmt, Ts &&...Vals) {
35 log(Level::Info, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
36 }
37 template <typename... Ts> static void error(const char *Fmt, Ts &&...Vals) {
38 log(Level::Error, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
39 }
40
41private:
42 Logger() = default;
43
44 /// Return the main logger instance.
45 static Logger &get();
46
47 /// Start a log message with the given severity level.
48 LLVM_ABI_FOR_TEST static void log(Level LogLevel, const char *Fmt,
49 const llvm::formatv_object_base &Message);
50
51 /// The minimum logging level. Messages with lower level are ignored.
52 Level LogLevel = Level::Error;
53
54 /// A mutex used to guard logging.
55 std::mutex Mutex;
56};
57} // namespace lsp
58} // namespace llvm
59
60#endif // LLVM_SUPPORT_LSP_LOGGING_H
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
This class represents the main interface for logging, and allows for filtering logging based on diffe...
Definition Logging.h:21
static void error(const char *Fmt, Ts &&...Vals)
Definition Logging.h:37
static void debug(const char *Fmt, Ts &&...Vals)
Initiate a log message at various severity levels.
Definition Logging.h:31
Level
The level of significance for a log message.
Definition Logging.h:24
static LLVM_ABI_FOR_TEST void setLogLevel(Level LogLevel)
Set the severity level of the logger.
Definition Logging.cpp:16
static void info(const char *Fmt, Ts &&...Vals)
Definition Logging.h:34
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
Definition Mutex.h:66
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)