Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 1 | //===--- Logger.h - Logger interface for clangd ------------------*- C++-*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_LOGGER_H |
| 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_LOGGER_H |
| 12 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 13 | #include "Context.h" |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/Twine.h" |
| 15 | |
| 16 | namespace clang { |
| 17 | namespace clangd { |
| 18 | |
Sam McCall | 2082fe1 | 2018-01-18 10:24:01 +0000 | [diff] [blame^] | 19 | /// Main logging function. |
| 20 | /// Logs messages to a global logger, which can be set up by LoggingSesssion. |
| 21 | /// If no logger is registered, writes to llvm::errs(). |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 22 | void log(const Context &Ctx, const llvm::Twine &Message); |
| 23 | |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 24 | /// Interface to allow custom logging in clangd. |
| 25 | class Logger { |
| 26 | public: |
| 27 | virtual ~Logger() = default; |
| 28 | |
| 29 | /// Implementations of this method must be thread-safe. |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 30 | virtual void log(const Context &Ctx, const llvm::Twine &Message) = 0; |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 33 | /// Only one LoggingSession can be active at a time. |
| 34 | class LoggingSession { |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 35 | public: |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 36 | LoggingSession(clangd::Logger &Instance); |
| 37 | ~LoggingSession(); |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 38 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 39 | LoggingSession(LoggingSession &&) = delete; |
| 40 | LoggingSession &operator=(LoggingSession &&) = delete; |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 41 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 42 | LoggingSession(LoggingSession const &) = delete; |
| 43 | LoggingSession &operator=(LoggingSession const &) = delete; |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | } // namespace clangd |
| 47 | } // namespace clang |
| 48 | |
| 49 | #endif |