blob: 7811111a2f67fb43276682453e2db4a4387b6cad [file] [log] [blame]
Ilya Biryukove5128f72017-09-20 07:24:15 +00001//===--- 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
15namespace clang {
16namespace clangd {
17
Sam McCall2082fe12018-01-18 10:24:01 +000018/// 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 McCalld1a7a372018-01-31 13:40:48 +000021void log(const llvm::Twine &Message);
Ilya Biryukov940901e2017-12-13 12:51:22 +000022
Ilya Biryukove5128f72017-09-20 07:24:15 +000023/// Interface to allow custom logging in clangd.
24class Logger {
25public:
26 virtual ~Logger() = default;
27
28 /// Implementations of this method must be thread-safe.
Sam McCalld1a7a372018-01-31 13:40:48 +000029 virtual void log(const llvm::Twine &Message) = 0;
Ilya Biryukove5128f72017-09-20 07:24:15 +000030};
31
Ilya Biryukov940901e2017-12-13 12:51:22 +000032/// Only one LoggingSession can be active at a time.
33class LoggingSession {
Ilya Biryukove5128f72017-09-20 07:24:15 +000034public:
Ilya Biryukov940901e2017-12-13 12:51:22 +000035 LoggingSession(clangd::Logger &Instance);
36 ~LoggingSession();
Ilya Biryukove5128f72017-09-20 07:24:15 +000037
Ilya Biryukov940901e2017-12-13 12:51:22 +000038 LoggingSession(LoggingSession &&) = delete;
39 LoggingSession &operator=(LoggingSession &&) = delete;
Ilya Biryukove5128f72017-09-20 07:24:15 +000040
Ilya Biryukov940901e2017-12-13 12:51:22 +000041 LoggingSession(LoggingSession const &) = delete;
42 LoggingSession &operator=(LoggingSession const &) = delete;
Ilya Biryukove5128f72017-09-20 07:24:15 +000043};
44
45} // namespace clangd
46} // namespace clang
47
48#endif