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 <memory>
15#include <mutex>
16
17namespace llvm {
18namespace lsp {
19
20/// This class represents the main interface for logging, and allows for
21/// filtering logging based on different levels of severity or significance.
22class Logger {
23public:
24 /// The level of significance for a log message.
25 enum class Level { Debug, Info, Error };
26
27 /// Set the severity level of the logger.
28 static void setLogLevel(Level LogLevel);
29
30 /// Initiate a log message at various severity levels. These should be called
31 /// after a call to `initialize`.
32 template <typename... Ts> static void debug(const char *Fmt, Ts &&...Vals) {
33 log(Level::Debug, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
34 }
35 template <typename... Ts> static void info(const char *Fmt, Ts &&...Vals) {
36 log(Level::Info, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
37 }
38 template <typename... Ts> static void error(const char *Fmt, Ts &&...Vals) {
39 log(Level::Error, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
40 }
41
42private:
43 Logger() = default;
44
45 /// Return the main logger instance.
46 static Logger &get();
47
48 /// Start a log message with the given severity level.
49 static void log(Level LogLevel, const char *Fmt,
50 const llvm::formatv_object_base &Message);
51
52 /// The minimum logging level. Messages with lower level are ignored.
53 Level LogLevel = Level::Error;
54
55 /// A mutex used to guard logging.
56 std::mutex Mutex;
57};
58} // namespace lsp
59} // namespace llvm
60
61#endif // LLVM_SUPPORT_LSP_LOGGING_H
This class represents the main interface for logging, and allows for filtering logging based on diffe...
Definition Logging.h:22
static void error(const char *Fmt, Ts &&...Vals)
Definition Logging.h:38
static void debug(const char *Fmt, Ts &&...Vals)
Initiate a log message at various severity levels.
Definition Logging.h:32
Level
The level of significance for a log message.
Definition Logging.h:25
static 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:35
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)