Is there a way to avoid segfault from using macros without creating a logger? #900
-
|
I am writing some tests for a component that emit some logs. I am not interested in the logs for the test. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hey, If you don’t care about log output in your tests, there are a few clean ways to avoid the logging overhead Option 1 (Recommended): Initialize the logger, but don’t start the backendYou can keep your existing logging calls, create the As long as your test doesn’t enqueue more than ~2 GB of logs (which is extremely unlikely), this is perfectly safe. Library is explicitly designed to handle this case: your code can still push log records into the queue, but since the backend thread never starts, the records are never processed. This completely avoids backend startup/shutdown cost while keeping your production code unchanged. Option 2: Compile logs out entirely for testsIf you want zero logging code generated, you can raise the compile-time log level for your test target. In your #define QUILL_COMPILE_ACTIVE_LOG_LEVEL QUILL_COMPILE_ACTIVE_LOG_LEVEL_CRITICAL + 1
#include "quill/LogMacros.h"Or, via CMake with This removes all logging statements at compile time for that target. Option 3: Use a nullptr logger (LogFunctions only – not released yet - slower by default)If you’re using the macro-free LogFunctions API, you can pass a https://github.com/odygrd/quill/blob/master/examples/console_logging_macro_free.cpp quill/include/quill/LogFunctions.h Line 328 in 88c9d6b |
Beta Was this translation helpful? Give feedback.
Hey, If you don’t care about log output in your tests, there are a few clean ways to avoid the logging overhead
Option 1 (Recommended): Initialize the logger, but don’t start the backend
You can keep your existing logging calls, create the
loggerwithcreate_or_get_logger(...)but simply never callquill::Backend::start()/quill::Backend::stop()As long as your test doesn’t enqueue more than ~2 GB of logs (which is extremely unlikely), this is perfectly safe.
Library is explicitly designed to handle this case:
your code can still push log records into the queue, but since the backend thread never starts, the records are never processed. This completely avoids backend startup/shutdown cos…