Skip to content

Commit f8508ef

Browse files
committed
docs and improvements
1 parent ea221f7 commit f8508ef

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

CHANGELOG.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,13 @@
103103
preprocessor will eliminate the `if` branch from the hotpath and disable this feature regardless of the
104104
value of `logger->set_immediate_flush(true)`.
105105

106-
- `QUILL_LOG_RUNTIME_METADATA` macro signature has changed from
107-
`QUILL_LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, fmt, ...)` to
108-
`QUILL_LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, tags, fmt, ...)`. It now accepts one
109-
additional argument: `tags`. When upgrading to the new version, you will have to add this argument; you can use `""`
110-
for empty tags.
111-
112-
- Internally refactored how runtime metadata are handled to provide more flexibility. There are now three macros that
113-
can also be used by users allowing to log runtime metadata:
114-
- `QUILL_LOG_RUNTIME_METADATA` - Will take a deep copy of `fmt`, `file`, `function` and `tags`. This is the most
115-
flexible one; it can be used, for example, to forward logs from another logging library to quill.
106+
- The `QUILL_LOG_RUNTIME_METADATA` macro requires `file`, `function` and `fmt` to be passed as `char const*` and
107+
`line_number` as `uint32_t`. This is a breaking change from the previous version.
108+
109+
- Internally, refactored how runtime metadata are handled for more flexibility, providing three macros for logging with
110+
runtime metadata:
111+
- `QUILL_LOG_RUNTIME_METADATA_DEEP` - Takes a deep copy of `fmt`, `file`, `function` and `tags`. Most flexible
112+
option, useful for forwarding logs from another logging library.
116113
- `QUILL_LOG_RUNTIME_METADATA_HYBRID` - Will take a deep copy of `fmt` and `tags` and will take `file` and
117114
`function` as reference. This is used for the new macro-free mode.
118115
- `QUILL_LOG_RUNTIME_METADATA_SHALLOW` - Will take everything as reference. This is used when logging with

docs/logging_macros.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ Runtime Metadata Logging Macro
343343
By default, the library creates and stores metadata information (e.g., source location) for each log statement at compile time.
344344
It is also possible to supply this metadata at runtime along with a log message. While this provides runtime flexibility,
345345
it introduces some overhead compared to compile-time metadata macros. Therefore, it is recommended to prefer using
346-
the compile-time metadata macros whenever possible. This runtime option can be particularly useful when forwarding logs
347-
received from another logging library to Quill.
346+
the compile-time metadata macros whenever possible. Quill provides three specialized macros for working with runtime metadata, each offering different trade-offs between flexibility and performance:
348347

349-
- :c:macro:`LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, fmt, ...)`
348+
- :c:macro:`QUILL_LOG_RUNTIME_METADATA_DEEP` - Takes a deep copy of ``fmt``, ``file``, ``function`` and ``tags``. Most flexible option, suitable for forwarding logs from another logging library to Quill.
349+
350+
- :c:macro:`QUILL_LOG_RUNTIME_METADATA_HYBRID` - Takes a deep copy of ``fmt`` and ``tags``, while referencing ``file`` and ``function``. Used for the macro-free mode.
351+
352+
- :c:macro:`QUILL_LOG_RUNTIME_METADATA_SHALLOW` - Takes everything as reference. Most efficient option when using compile-time metadata with dynamic log levels like ``LOG_DYNAMIC``.
353+
354+
Note that ``QUILL_LOG_RUNTIME_METADATA`` is equivalent to ``QUILL_LOG_RUNTIME_METADATA_DEEP`` but without the ``tags`` parameter.

include/quill/LogMacros.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,12 @@
964964
} \
965965
} while (0)
966966

967-
#define QUILL_LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, tags, fmt, ...) \
967+
#define QUILL_LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, fmt, ...) \
968968
QUILL_LOG_RUNTIME_METADATA_CALL(quill::MacroMetadata::Event::LogWithRuntimeMetadataDeepCopy, logger, \
969+
log_level, file, line_number, function, "", fmt, ##__VA_ARGS__)
970+
971+
#define QUILL_LOG_RUNTIME_METADATA_DEEP(logger, log_level, file, line_number, function, tags, fmt, ...) \
972+
QUILL_LOG_RUNTIME_METADATA_CALL(quill::MacroMetadata::Event::LogWithRuntimeMetadataDeepCopy, logger, \
969973
log_level, file, line_number, function, tags, fmt, ##__VA_ARGS__)
970974

971975
#define QUILL_LOG_RUNTIME_METADATA_HYBRID(logger, log_level, file, line_number, function, tags, fmt, ...) \
@@ -1192,8 +1196,11 @@
11921196
#define LOGJ_CRITICAL_TAGS(logger, tags, fmt, ...) \
11931197
QUILL_LOGJ_CRITICAL_TAGS(logger, tags, fmt, ##__VA_ARGS__)
11941198

1195-
#define LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, tags, fmt, ...) \
1196-
QUILL_LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, tags, fmt, ##__VA_ARGS__)
1199+
#define LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, fmt, ...) \
1200+
QUILL_LOG_RUNTIME_METADATA(logger, log_level, file, line_number, function, fmt, ##__VA_ARGS__)
1201+
1202+
#define LOG_RUNTIME_METADATA_DEEP(logger, log_level, file, line_number, function, tags, fmt, ...) \
1203+
QUILL_LOG_RUNTIME_METADATA_DEEP(logger, log_level, file, line_number, function, tags, fmt, ##__VA_ARGS__)
11971204

11981205
#define LOG_RUNTIME_METADATA_HYBRID(logger, log_level, file, line_number, function, tags, fmt, ...) \
11991206
QUILL_LOG_RUNTIME_METADATA_HYBRID(logger, log_level, file, line_number, function, tags, fmt, ##__VA_ARGS__)

test/integration_tests/MacrosTest.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,30 @@
1212
#include <string_view>
1313
#include <vector>
1414

15-
using namespace quill;
16-
1715
/***/
1816
TEST_CASE("macros")
1917
{
2018
static constexpr char const* filename = "macros.log";
2119
static std::string const logger_name = "logger";
2220

23-
Backend::start();
21+
quill::Backend::start();
2422

2523
// Set writing logging to a file
26-
auto file_sink = Frontend::create_or_get_sink<FileSink>(
24+
auto file_sink = quill::Frontend::create_or_get_sink<quill::FileSink>(
2725
filename,
2826
[]()
2927
{
30-
FileSinkConfig cfg;
28+
quill::FileSinkConfig cfg;
3129
cfg.set_open_mode('w');
3230
return cfg;
3331
}(),
34-
FileEventNotifier{});
32+
quill::FileEventNotifier{});
3533

36-
Logger* logger = Frontend::create_or_get_logger(
34+
quill::Logger* logger = quill::Frontend::create_or_get_logger(
3735
logger_name, std::move(file_sink),
38-
PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
39-
"%(log_level_short_code) LOG_%(log_level:<9) "
40-
"%(logger:<12) %(message) [ %(tags)] [%(named_args)]"});
36+
quill::PatternFormatterOptions{"%(time) [%(thread_id)] %(short_source_location:<28) "
37+
"%(log_level_short_code) LOG_%(log_level:<9) "
38+
"%(logger:<12) %(message) [ %(tags)] [%(named_args)]"});
4139
logger->init_backtrace(1, quill::LogLevel::Error);
4240
logger->set_log_level(quill::LogLevel::TraceL3);
4341

@@ -85,14 +83,14 @@ TEST_CASE("macros")
8583
LOG_BACKTRACE_TAGS(logger, TAGS("tag"), "C BT: {}", 255);
8684
LOG_DYNAMIC_TAGS(logger, quill::LogLevel::Critical, TAGS("tag"), "C DYN: {}", 420);
8785

88-
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, "MacrosTest.cpp", 1234, "function()", "",
86+
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, "MacrosTest.cpp", 1234, "function()",
8987
"CA INF_{}", 11);
9088
LOG_RUNTIME_METADATA_SHALLOW(logger, quill::LogLevel::Info, "MacrosTest.cpp", 1234, "function()",
9189
"", "CA INF_{}", 0);
9290
LOG_RUNTIME_METADATA_HYBRID(logger, quill::LogLevel::Debug, "MacrosTest.cpp", 1234, "function()",
9391
"", "CA DBG_0");
94-
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Debug, "MacrosTest.cpp", 123, "function()", "#TEST",
95-
"CA DBG_21");
92+
LOG_RUNTIME_METADATA_DEEP(logger, quill::LogLevel::Debug, "MacrosTest.cpp", 123, "function()",
93+
"#TEST", "CA DBG_21");
9694

9795
int var{1337};
9896
LOGV_TRACE_L3(logger, "D L3", var);
@@ -180,10 +178,10 @@ TEST_CASE("macros")
180178
LOGJ_CRITICAL_TAGS(logger, TAGS("tag"), "K CRT", var);
181179

182180
logger->flush_log();
183-
Frontend::remove_logger(logger);
181+
quill::Frontend::remove_logger(logger);
184182

185183
// Wait until the backend thread stops for test stability
186-
Backend::stop();
184+
quill::Backend::stop();
187185

188186
// Read file and check
189187
std::vector<std::string> const file_contents = quill::testing::file_contents(filename);
@@ -414,5 +412,5 @@ TEST_CASE("macros")
414412
REQUIRE(quill::testing::file_contains(
415413
file_contents, std::string{"C LOG_CRITICAL logger K CRT 1337 [ #tag ] [var: 1337]"}));
416414

417-
testing::remove_file(filename);
415+
quill::testing::remove_file(filename);
418416
}

test/integration_tests/RuntimeMetadataTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace quill;
1515
void log_runtime_message(quill::Logger* quill_logger, quill::LogLevel log_level,
1616
char const* filename, uint32_t lineno, std::string_view arg)
1717
{
18-
QUILL_LOG_RUNTIME_METADATA(quill_logger, log_level, filename, lineno, "", "", "{}", arg);
18+
QUILL_LOG_RUNTIME_METADATA(quill_logger, log_level, filename, lineno, "", "{}", arg);
1919
}
2020

2121
/***/
@@ -43,17 +43,17 @@ TEST_CASE("runtime_metadata")
4343
"%(message)"});
4444

4545
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, "RuntimeMetadataTest.cpp", 1234, "function_1",
46-
nullptr, "test message");
46+
"{}", "test message");
4747

4848
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Warning, "RuntimeMetadataTest.cpp", 1234,
49-
"function_1", nullptr, "test message");
49+
"function_1", "{}", "test message");
5050

5151
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, "RuntimeMetadataTest.cpp", 1234, "foo()",
52-
nullptr, "test message");
52+
"{}", "test message");
5353

5454
LOG_INFO(logger, "standard message {} {}", 123, 456);
5555

56-
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, "app.cpp", 98, "foo()", nullptr,
56+
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, "app.cpp", 98, "foo()",
5757
"Runtime metadata with {} {}", 2, 3);
5858

5959
std::string file_name = "RuntimeMetadataTest.cpp";
@@ -62,7 +62,7 @@ TEST_CASE("runtime_metadata")
6262
uint32_t a = 1;
6363
uint32_t b = 2;
6464
LOG_RUNTIME_METADATA(logger, quill::LogLevel::Info, file_name.data(), line_number,
65-
function_name.data(), nullptr, "a={} and b={}", a, b);
65+
function_name.data(), "a={} and b={}", a, b);
6666

6767
log_runtime_message(logger, quill::LogLevel::Info, "app.cpp", 1234, "test message");
6868

0 commit comments

Comments
 (0)