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 | |
| 13 | #include "llvm/ADT/Twine.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace clangd { |
| 17 | |
Sam McCall | 2082fe1 | 2018-01-18 10:24:01 +0000 | [diff] [blame] | 18 | /// Main logging function. |
| 19 | /// Logs messages to a global logger, which can be set up by LoggingSesssion. |
| 20 | /// If no logger is registered, writes to llvm::errs(). |
Sam McCall | d1a7a37 | 2018-01-31 13:40:48 +0000 | [diff] [blame^] | 21 | void log(const llvm::Twine &Message); |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 22 | |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 23 | /// Interface to allow custom logging in clangd. |
| 24 | class Logger { |
| 25 | public: |
| 26 | virtual ~Logger() = default; |
| 27 | |
| 28 | /// Implementations of this method must be thread-safe. |
Sam McCall | d1a7a37 | 2018-01-31 13:40:48 +0000 | [diff] [blame^] | 29 | virtual void log(const llvm::Twine &Message) = 0; |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 32 | /// Only one LoggingSession can be active at a time. |
| 33 | class LoggingSession { |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 34 | public: |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 35 | LoggingSession(clangd::Logger &Instance); |
| 36 | ~LoggingSession(); |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 37 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 38 | LoggingSession(LoggingSession &&) = delete; |
| 39 | LoggingSession &operator=(LoggingSession &&) = delete; |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 40 | |
Ilya Biryukov | 940901e | 2017-12-13 12:51:22 +0000 | [diff] [blame] | 41 | LoggingSession(LoggingSession const &) = delete; |
| 42 | LoggingSession &operator=(LoggingSession const &) = delete; |
Ilya Biryukov | e5128f7 | 2017-09-20 07:24:15 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | } // namespace clangd |
| 46 | } // namespace clang |
| 47 | |
| 48 | #endif |