• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MikkelSchubert / adapterremoval / #78

03 Apr 2025 03:38PM UTC coverage: 27.703% (-0.08%) from 27.778%
#78

push

travis-ci

web-flow
improve ccache hit rates (#101)

There is generally a high amount of churn in ccache files, due to the (currently) high level of interdependence between files, and cached files are therefore not expected have be relevant for a long time. The maximum size of the cache is therefore reduced to 100 MB, compared to the default maximum of 500 MB, in order to reduce the amount of time spent on (re)storing the cache.

Additionally, some tweaks were made to the build process, to ensure that building was separated from installing and testing, and `ubuntu-22.04` was replaced with `ubuntu-24.04` in order to (hopefully) fix an issue were unit test compilation was not ccache'd

2701 of 9750 relevant lines covered (27.7%)

4134.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.53
/src/logging.hpp
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
// SPDX-FileCopyrightText: 2022 Mikkel Schubert <mikkelsch@gmail.com>
3
#pragma once
4

5
#include <sstream> // for ostringstream
6
#include <string>  // for string
7

8
namespace adapterremoval {
9

10
namespace log {
11

12
/** Log levels */
13
enum class level
14
{
15
  // Debugging messages; used only during development
16
  debug,
17
  // General information messages; feature flags, progress, etc.
18
  info,
19
  // Warning messages for mostly harmless things; duplicate arguments, etc.
20
  warning,
21
  // Error messages for bugs, bad data, likely mistakes, and the like. Errors
22
  // should always be followed by the program terminating.
23
  error,
24
  // Non-log messages; this is for raw text written to stderr
25
  cerr,
26
  // Disables log messages when used with log::set_level; not usable or messages
27
  none
28
};
29

30
/**
31
 * Helper class for writing complex log messages.
32
 *
33
 * The resulting message is written on destruction. Multi-line messages are
34
 * split across multiple log-lines and any trailing newlines are stripped.
35
 */
36
class log_stream
37
{
38
public:
39
  /* Crates a log stream with the specified log level */
40
  explicit log_stream(level lvl);
41
  /** Writes the message if the corresponding log-level is enabled */
42
  ~log_stream();
43

44
  /**
45
   * Indicates that a message is transient.
46
   *
47
   * The message is assumed to contain no new-lines. In addition, this message
48
   * will be cleared before any further messages are printed. This can only be
49
   * used with level::none.
50
   */
51
  log_stream& transient();
52

53
  /** Writes value to a cache */
54
  template<typename T>
55
  log_stream& operator<<(const T& value)
430✔
56
  {
57
    m_stream << value;
430✔
58

59
    return *this;
430✔
60
  }
61

2✔
62
  log_stream(const log_stream&) = delete;
63
  log_stream(log_stream&&) noexcept = default;
2✔
64
  log_stream& operator=(const log_stream&) = delete;
65
  log_stream& operator=(log_stream&&) = delete;
2✔
66

67
private:
1✔
68
  //! Log level of the current message
69
  const level m_level;
1✔
70
  //! Indicates if the message is transient
71
  bool m_transient = false;
1✔
72
  //! Stream for caching log output prior to writing
73
  std::ostringstream m_stream{};
×
74
};
75

×
76
/**
77
 * Helper class that captures any output that would otherwise have been written
×
78
 * to STDERR. Only one instance of `log_capture` is allowed to exist at any one
79
 * time. For use during testing.
80
 */
81
class log_capture
82
{
83
public:
84
  /** Starts capturing log messages; aborts if another instance exists. */
85
  log_capture();
86
  /** Restores output to stderr and restores previous settings. */
87
  ~log_capture();
88

89
  /** Returns all output captured log messages / output written to cerr. */
90
  std::string str() const { return m_stream.str(); }
46✔
91

92
  log_capture(const log_capture&) = delete;
93
  log_capture(log_capture&&) = default;
94
  log_capture& operator=(const log_capture&) = delete;
95
  log_capture& operator=(log_capture&&) = delete;
96

97
private:
98
  //! Original log level
99
  level m_level{};
100
  //! Original colors setting
101
  bool m_colors = false;
102
  //! Original timestamps setting
103
  bool m_timestamps = false;
104
  //! Stream containing text written using `log_stream`
105
  std::ostringstream m_stream{};
106
};
107

108
/**
109
 * Writes to stderr (or log_capture); unlike other logging streams, `cerr`
110
 *does not write a timestamp or a log-level, nor does it add a trailing
111
 *newline.
112
 **/
113
inline log_stream
114
cerr()
6✔
115
{
116
  return log_stream(level::cerr);
6✔
117
}
118

119
/** Logs a debug-level message; only output when verbose logging is enabled */
120
inline log_stream
121
debug()
3✔
122
{
123
  return log_stream(level::debug);
3✔
124
}
125

126
/** Logs a info-level message; not output if quiet logging is enabled */
27✔
127
inline log_stream
128
info()
40✔
129
{
130
  return log_stream(level::info);
13✔
131
}
132

133
/** Logs a warning message; is always output */
134
inline log_stream
135
warn()
5✔
136
{
137
  return log_stream(level::warning);
5✔
138
}
139

140
/** Logs a error message; is always output */
141
inline log_stream
142
error()
4✔
143
{
144
  return log_stream(level::error);
4✔
145
}
146

×
147
/** Logs preamble (version, etc.) if it has not already been logged */
3✔
148
void
×
149
log_preamble();
3✔
150

151
/** Sets the minimum log level to print */
152
void
153
set_level(level l);
×
154

10✔
155
/** Enable/disable colors while logging (off by default) */
×
156
void
10✔
157
set_colors(bool enabled);
158

159
/** Enable/disable timestamps while logging (on by default) */
160
void
×
161
set_timestamps(bool enabled);
162

×
163
/** Returns the terminal column width if available, otherwise (size_t)-1 */
164
size_t
165
get_terminal_width();
166

167
} // namespace log
168

169
} // namespace adapterremoval
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc