blob: b6d7a1b4caf462675e1acb757f36bc8667eebc5a [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
Ilya Biryukov940901e2017-12-13 12:51:22 +000013#include "Context.h"
Ilya Biryukove5128f72017-09-20 07:24:15 +000014#include "llvm/ADT/Twine.h"
15
16namespace clang {
17namespace clangd {
18
Sam McCall2082fe12018-01-18 10:24:01 +000019/// 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 Biryukov940901e2017-12-13 12:51:22 +000022void log(const Context &Ctx, const llvm::Twine &Message);
23
Ilya Biryukove5128f72017-09-20 07:24:15 +000024/// Interface to allow custom logging in clangd.
25class Logger {
26public:
27 virtual ~Logger() = default;
28
29 /// Implementations of this method must be thread-safe.
Ilya Biryukov940901e2017-12-13 12:51:22 +000030 virtual void log(const Context &Ctx, const llvm::Twine &Message) = 0;
Ilya Biryukove5128f72017-09-20 07:24:15 +000031};
32
Ilya Biryukov940901e2017-12-13 12:51:22 +000033/// Only one LoggingSession can be active at a time.
34class LoggingSession {
Ilya Biryukove5128f72017-09-20 07:24:15 +000035public:
Ilya Biryukov940901e2017-12-13 12:51:22 +000036 LoggingSession(clangd::Logger &Instance);
37 ~LoggingSession();
Ilya Biryukove5128f72017-09-20 07:24:15 +000038
Ilya Biryukov940901e2017-12-13 12:51:22 +000039 LoggingSession(LoggingSession &&) = delete;
40 LoggingSession &operator=(LoggingSession &&) = delete;
Ilya Biryukove5128f72017-09-20 07:24:15 +000041
Ilya Biryukov940901e2017-12-13 12:51:22 +000042 LoggingSession(LoggingSession const &) = delete;
43 LoggingSession &operator=(LoggingSession const &) = delete;
Ilya Biryukove5128f72017-09-20 07:24:15 +000044};
45
46} // namespace clangd
47} // namespace clang
48
49#endif