-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathcustom_frontend_options.cpp
More file actions
38 lines (31 loc) · 1.47 KB
/
Copy pathcustom_frontend_options.cpp
File metadata and controls
38 lines (31 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "quill/Backend.h"
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/Logger.h"
#include "quill/sinks/ConsoleSink.h"
/**
* This example demonstrates defining and utilizing custom FrontendOptions.
* It's useful when you need to modify the queue type or capacity.
* FrontendOptions are compile-time options and must be passed as a template argument.
*/
// Derive from FrontendOptions and override only the values that differ.
struct CustomFrontendOptions : quill::FrontendOptions
{
static constexpr quill::QueueType queue_type = quill::QueueType::BoundedDropping;
};
// To utilize our custom FrontendOptions, we define a Frontend class using CustomFrontendOptions
using CustomFrontend = quill::FrontendImpl<CustomFrontendOptions>;
// The Logger type must also be defined
using CustomLogger = quill::LoggerImpl<CustomFrontendOptions>;
int main()
{
// Start the backend thread
quill::BackendOptions backend_options;
quill::Backend::start(backend_options); // or quill::Backend::start<CustomFrontendOptions>(backend_options, signal_handler_options);
// All frontend operations must utilize CustomFrontend instead of quill::Frontend
auto console_sink = CustomFrontend::create_or_get_sink<quill::ConsoleSink>("sink_id_1");
CustomLogger* logger = CustomFrontend::create_or_get_logger("root", std::move(console_sink));
// log something
LOG_INFO(logger, "This is a log info example {}", 123);
LOG_WARNING(logger, "This is a log warning example {}", 123);
}