Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
logger_sample.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, πŸ€β˜€πŸŒ•πŸŒ₯ 🌊
3// See the LICENSE file in the project root for full license information.
4
17#include <iostream>
18#include <chrono>
19#include <thread>
20
21#include "logger/core/logger.h"
23
25
26bool use_backup_ = false;
27uint32_t max_lines_ = 0;
28uint16_t wait_interval_ = 100;
29uint32_t test_line_count_ = 10000;
30log_module::log_types file_target_ = log_module::log_types::Sequence;
31log_module::log_types console_target_ = log_module::log_types::Sequence;
32log_module::log_types callback_target_ = log_module::log_types::None;
33
34auto initialize_logger() -> std::optional<std::string>
35{
36 log_module::set_title("logger_sample");
37 log_module::set_use_backup(use_backup_);
38 log_module::set_max_lines(max_lines_);
39 log_module::file_target(file_target_);
40 log_module::console_target(console_target_);
41 log_module::callback_target(callback_target_);
42 log_module::message_callback(
43 [](const log_module::log_types& type, const std::string& datetime,
44 const std::string& message)
45 { std::cout << formatter::format("[{}][{}] {}\n", datetime, type, message); });
46 if (wait_interval_ > 0)
47 {
48 log_module::set_wake_interval(std::chrono::milliseconds(wait_interval_));
49 }
50
51 return log_module::start();
52}
53
54auto main() -> int
55{
56 auto error_message = initialize_logger();
57 if (error_message.has_value())
58 {
59 std::cerr << formatter::format("error starting logger: {}\n",
60 error_message.value_or("unknown error"));
61 return 0;
62 }
63
64 for (auto index = 0; index < test_line_count_; ++index)
65 {
66 log_module::write_debug("μ•ˆλ…•, World!: {}", index);
67 log_module::write_debug("ν…ŒμŠ€νŠΈ #{} - Hello, δΈ–η•Œ!", index);
68 log_module::write_debug("θ­¦ε‘Š {}: こんにけは", index);
69
70 log_module::write_sequence(L"μ•ˆλ…•, World!: {}", index);
71 log_module::write_sequence(L"ν…ŒμŠ€νŠΈ #{} - Hello, δΈ–η•Œ!", index);
72 log_module::write_sequence(L"θ­¦ε‘Š {}: こんにけは", index);
73
74 log_module::write_parameter("볡합 ν…ŒμŠ€νŠΈ - κ°’: {}, 이름: {}", index, "홍길동");
75 log_module::write_parameter(L"볡합 ν…ŒμŠ€νŠΈ - κ°’: {}, 이름: {}", index, L"홍길동");
76
77 log_module::write_information("μ—¬λŸ¬ 쀄 ν…ŒμŠ€νŠΈ:\n 라인 1: {}\n 라인 2: {}\n 라인 3: {}",
78 "μ•ˆλ…•ν•˜μ„Έμš”", "Hello, World", "こんにけは");
79 log_module::write_information(L"μ—¬λŸ¬ 쀄 ν…ŒμŠ€νŠΈ:\n 라인 1: {}\n 라인 2: {}\n 라인 3: {}",
80 L"μ•ˆλ…•ν•˜μ„Έμš”", L"Hello, World", L"こんにけは");
81 }
82
83 log_module::stop();
84
85 return 0;
86}
Provides convenience methods for string formatting using C++20 <format>.
Definition formatter.h:122
static auto format(const char *formats, const FormatArgs &... args) -> std::string
Formats a narrow-character string with the given arguments.
Definition formatter.h:132
Generic formatter for enum types using user-provided converter functors.
log_module::log_types file_target_
log_module::log_types callback_target_
uint32_t max_lines_
bool use_backup_
auto main() -> int
auto initialize_logger() -> std::optional< std::string >
uint32_t test_line_count_
log_module::log_types console_target_
uint16_t wait_interval_