MLIR  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"
11 #include "llvm/Support/raw_ostream.h"
12 
13 using namespace mlir;
14 using namespace mlir::lsp;
15 
16 void Logger::setLogLevel(Level logLevel) { get().logLevel = logLevel; }
17 
18 Logger &Logger::get() {
19  static Logger logger;
20  return logger;
21 }
22 
23 void 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);
37  llvm::errs() << llvm::formatv(
38  "{0}[{1:%H:%M:%S.%L}] {2}\n",
39  logLevelIndicators[static_cast<unsigned>(logLevel)], timestamp, message);
40  llvm::errs().flush();
41 }
This class represents the main interface for logging, and allows for filtering logging based on diffe...
Definition: Logging.h:23
Level
The level of significance for a log message.
Definition: Logging.h:26
static void setLogLevel(Level logLevel)
Set the severity level of the logger.
Definition: Logging.cpp:16
Include the generated interface declarations.