Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
logger_sample.cpp File Reference

Logger system sample with multi-language Unicode output. More...

#include <iostream>
#include <chrono>
#include <thread>
#include "logger/core/logger.h"
#include <kcenon/thread/utils/formatter.h>
Include dependency graph for logger_sample.cpp:

Go to the source code of this file.

Functions

auto initialize_logger () -> std::optional< std::string >
 
auto main () -> int
 

Variables

bool use_backup_ = false
 
uint32_t max_lines_ = 0
 
uint16_t wait_interval_ = 100
 
uint32_t test_line_count_ = 10000
 
log_module::log_types file_target_ = log_module::log_types::Sequence
 
log_module::log_types console_target_ = log_module::log_types::Sequence
 
log_module::log_types callback_target_ = log_module::log_types::None
 

Detailed Description

Logger system sample with multi-language Unicode output.

Definition in file logger_sample.cpp.

Function Documentation

◆ initialize_logger()

auto initialize_logger ( ) -> std::optional<std::string>
Examples
logger_sample.cpp, thread_pool_sample.cpp, typed_thread_pool_sample.cpp, and typed_thread_pool_sample_2.cpp.

Definition at line 34 of file logger_sample.cpp.

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}
static auto format(const char *formats, const FormatArgs &... args) -> std::string
Formats a narrow-character string with the given arguments.
Definition formatter.h:132
log_module::log_types file_target_
log_module::log_types callback_target_
uint32_t max_lines_
bool use_backup_
log_module::log_types console_target_
uint16_t wait_interval_

References callback_target_, console_target_, file_target_, kcenon::thread::utils::formatter::format(), max_lines_, use_backup_, and wait_interval_.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

auto main ( ) -> int

Definition at line 54 of file logger_sample.cpp.

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}
auto initialize_logger() -> std::optional< std::string >
uint32_t test_line_count_

References kcenon::thread::utils::formatter::format(), initialize_logger(), and test_line_count_.

Here is the call graph for this function:

Variable Documentation

◆ callback_target_

log_module::log_types callback_target_ = log_module::log_types::None

◆ console_target_

log_module::log_types console_target_ = log_module::log_types::Sequence

◆ file_target_

log_module::log_types file_target_ = log_module::log_types::Sequence

◆ max_lines_

uint32_t max_lines_ = 0

◆ test_line_count_

uint32_t test_line_count_ = 10000

◆ use_backup_

bool use_backup_ = false

◆ wait_interval_

uint16_t wait_interval_ = 100