Skip to content

Commit cc3b00d

Browse files
committed
null logger
1 parent a572936 commit cc3b00d

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/odr/logger.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ namespace odr {
1010

1111
namespace {
1212

13+
class NullLogger : public Logger {
14+
public:
15+
[[nodiscard]] bool will_log(LogLevel) const override { return false; }
16+
17+
void log_impl(LogLevel, const std::string &,
18+
const std::source_location &) override {
19+
// Do nothing
20+
}
21+
};
22+
1323
class StdioLogger : public Logger {
1424
public:
1525
StdioLogger(std::string name, LogLevel level, LogFormat format,
@@ -84,6 +94,11 @@ std::string_view level_to_string(LogLevel level) {
8494

8595
} // namespace
8696

97+
Logger &Logger::null() {
98+
static NullLogger null_logger;
99+
return null_logger;
100+
}
101+
87102
std::unique_ptr<Logger>
88103
Logger::create_stdio(const std::string &name, LogLevel level,
89104
const LogFormat &format,

src/odr/logger.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct LogFormat {
4040

4141
class Logger {
4242
public:
43+
static Logger &null();
4344
static std::unique_ptr<Logger>
4445
create_stdio(const std::string &name, LogLevel level,
4546
const LogFormat &format = LogFormat(),

0 commit comments

Comments
 (0)