Skip to content

Commit fee5580

Browse files
committed
cleanup
1 parent 0489a98 commit fee5580

8 files changed

Lines changed: 18 additions & 44 deletions

File tree

example/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ function(DEFINE_EXAMPLE TARGET)
55
target_link_libraries(example_${TARGET} PRIVATE rsl-log)
66
endfunction()
77

8-
# DEFINE_EXAMPLE(args)
9-
# DEFINE_EXAMPLE(colorize)
10-
# DEFINE_EXAMPLE(spans)
11-
# DEFINE_EXAMPLE(coroutine)
12-
# DEFINE_EXAMPLE(systemd)
8+
DEFINE_EXAMPLE(spans)
9+
DEFINE_EXAMPLE(coroutine)
10+
DEFINE_EXAMPLE(systemd)
1311
DEFINE_EXAMPLE(custom_logger)

example/args.cpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

example/systemd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main() {
2828
// SystemdSink(),
2929
TerminalSink(),
3030
filter(event->severity >= rsl::log_level::ERROR) >> error_sink,
31-
filter([](auto const& event){ return event.severity >= rsl::log_level::ERROR; }) >> error_sink
31+
filter([](auto const& ev){ return ev.severity >= rsl::log_level::ERROR; }) >> error_sink
3232
);
3333
logger.set_as_default();
3434
// set_output(logger);

include/rsl/logging/_impl/formatter.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void emit_event(ExtraFields const* fnc_args,
6565
FormatString<Level, Args...> fmt,
6666
Args&&... args) {
6767
// we've already checked against global_min_level in FormatString's ctor
68-
// do it again here to avoid instantiating GlobalLogger::emit
68+
// do it again here to avoid instantiating `emit`
6969
if constexpr (Level >= global_min_level) {
7070
// check context level override
7171
if (context != nullptr && Level < context->min_level) {
@@ -78,7 +78,6 @@ void emit_event(ExtraFields const* fnc_args,
7878
.arguments = fnc_args ? *fnc_args : ExtraFields{},
7979
.sloc = fmt.sloc};
8080

81-
// RSL_LOG_EMITTER(meta, fmt, std::forward<Args>(args)...);
8281
selected_logger<Empty...>.emit(meta, fmt, std::forward<Args>(args)...);
8382
}
8483
}

include/rsl/logging/async_logger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ struct AsyncLogger : DefaultLogger {
1212
template <LogLevel Severity, typename... Args>
1313
void emit(Metadata& meta, _impl::FormatString<Severity, Args...> fmt, Args&&... args) {
1414
auto formatter = fmt.make_message;
15-
// serialize metadata
1615
// serialize formatter
16+
// serialize metadata
1717
// serialize arguments
1818
// submit to message queue
1919
}

include/rsl/logging/context.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ struct RSL_CONSUMABLE(unconsumed) Context {
8181

8282
extern thread_local Context* current_context;
8383

84-
template <typename T>
84+
template <typename T = std::monostate>
8585
struct ContextGuard : private Context {
8686
T extra;
8787

8888
explicit ContextGuard(std::string name,
8989
LogLevel min_level,
90-
T extra,
90+
T extra = {},
9191
ExtraFields arguments = {},
9292
rsl::source_location const& sloc = std::source_location::current())
9393
: Context(name, min_level, arguments, {}, sloc) {
@@ -105,6 +105,7 @@ struct ContextGuard : private Context {
105105
using Context::enabled_for;
106106
};
107107

108+
108109
namespace _log_impl {
109110
template <typename T>
110111
concept has_member_op_co_await = requires(T t) { t.operator co_await(); };

include/rsl/logging/logger.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,32 @@ template <typename... Ts>
8080
Output(Ts&&...) -> Output<Ts...>;
8181

8282
struct NullLogger {
83-
constexpr static auto min_level = LogLevel::DISABLE;
84-
85-
void context(Metadata const& meta, bool entered, bool async_handover) const {}
83+
static void context(Metadata const& meta, bool entered, bool async_handover) {}
8684

8785
template <LogLevel Severity, typename... Args>
88-
void emit(Metadata& meta, _impl::FormatString<Severity, Args...> fmt, Args&&... args) const {}
86+
static void emit(Metadata& meta, _impl::FormatString<Severity, Args...> fmt, Args&&... args) {}
8987
};
9088

9189
struct DefaultLogger {
92-
constexpr static auto min_level = LogLevel::INFO;
93-
94-
void context(Metadata const& meta, bool entered, bool async_handover) const {
95-
if (auto* logger = current_output()) {
90+
static void context(Metadata const& meta, bool entered, bool async_handover) {
91+
if (auto* logger = output()) {
9692
logger->context(meta, entered, async_handover);
9793
}
9894
}
9995

10096
template <LogLevel Severity, typename... Args>
101-
void emit(Metadata& meta, _impl::FormatString<Severity, Args...> fmt, Args&&... args) const {
97+
static void emit(Metadata& meta, _impl::FormatString<Severity, Args...> fmt, Args&&... args) {
10298
auto message = fmt.make_message(std::forward<Args>(args)...);
10399
auto event = Event{.meta = meta, .text = message};
104-
if (auto* logger = current_output()) {
100+
if (auto* logger = output()) {
105101
logger->emit(event);
106102
}
107103
}
108104

109-
static LoggerBase*& current_output();
105+
static LoggerBase*& output();
110106
template <typename... Sinks>
111107
static void set_output(Output<Sinks...>& logger) {
112-
current_output() = &logger;
108+
output() = &logger;
113109
}
114110
};
115111

src/logger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LoggerBase* get_default_logger() {
99
}
1010
} // namespace
1111

12-
LoggerBase*& DefaultLogger::current_output() {
12+
LoggerBase*& DefaultLogger::output() {
1313
static LoggerBase* current = get_default_logger();
1414
return current;
1515
}

0 commit comments

Comments
 (0)