LLVM 22.0.0git
Logging.cpp
Go to the documentation of this file.
1//===- Logging.cpp --------------------------------------------------------===//
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
10#include "llvm/Support/Chrono.h"
12
13using namespace llvm;
14using namespace llvm::lsp;
15
16void Logger::setLogLevel(Level LogLevel) { get().LogLevel = LogLevel; }
17
18Logger &Logger::get() {
19 static Logger Logger;
20 return Logger;
21}
22
23void Logger::log(Level LogLevel, const char *Fmt,
24 const llvm::formatv_object_base &Message) {
25 Logger &Logger = get();
26
27 // Ignore messages with log levels below the current setting in the logger.
28 if (LogLevel < Logger.LogLevel)
29 return;
30
31 // An indicator character for each log level.
32 const char *LogLevelIndicators = "DIE";
33
34 // Format the message and print to errs.
35 llvm::sys::TimePoint<> Timestamp = std::chrono::system_clock::now();
36 std::lock_guard<std::mutex> LogGuard(Logger.Mutex);
38 "{0}[{1:%H:%M:%S.%L}] {2}\n",
39 LogLevelIndicators[static_cast<unsigned>(LogLevel)], Timestamp, Message);
40 llvm::errs().flush();
41}
Logging utility - given an ordered specification of features, and assuming a scalar reward,...
This class represents the main interface for logging, and allows for filtering logging based on diffe...
Definition Logging.h:22
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
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
Definition Chrono.h:34
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)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.