clang 23.0.0git
AtomicLineLogger.h
Go to the documentation of this file.
1//===- AtomicLineLogger.h ---------------------------------------*- C++ -*-===//
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//
9/// \file
10/// Defines a logger where each line is written atomically to the file. It is
11/// safe to share a logger instance across threads.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_ATOMICLINELOGGER_H
16#define LLVM_CLANG_BASIC_ATOMICLINELOGGER_H
17
18#include "clang/Basic/LLVM.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/Support/raw_ostream.h"
21#include <atomic>
22#include <optional>
23#include <string>
24
25namespace clang {
26
27class LogLine {
28 SmallString<128> Buffer;
29 std::optional<llvm::raw_svector_ostream> FormattingOS;
30 int FD = -1;
31 std::atomic<uint64_t> *DroppedLines = nullptr;
32
33 explicit LogLine(int FD, std::atomic<uint64_t> *DroppedLines);
34
35public:
38 LogLine(const LogLine &) = delete;
39 LogLine &operator=(const LogLine &) = delete;
40 LogLine &operator=(LogLine &&) = delete;
41
42 ~LogLine();
43
44 template <typename T> LogLine &operator<<(const T &Val) {
45 if (FormattingOS)
46 *FormattingOS << Val;
47 return *this;
48 }
49
50 friend class AtomicLineLogger;
51};
52
54 int FD = -1;
55 std::string LogPath;
56 std::atomic<uint64_t> DroppedLines{0};
57
58public:
60 AtomicLineLogger(StringRef LogFilePath);
61
62 // AtomicLineLogger is non-movable because LogLines have pointers to the
63 // atomic member DroppedLines.
66
68
69 LogLine log();
70};
71
72} // namespace clang
73
74#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
AtomicLineLogger(AtomicLineLogger &&)=delete
AtomicLineLogger & operator=(AtomicLineLogger &&)=delete
LogLine(const LogLine &)=delete
LogLine & operator<<(const T &Val)
friend class AtomicLineLogger
LogLine & operator=(const LogLine &)=delete
LogLine & operator=(LogLine &&)=delete
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Definition Decl.h:1774