Logger System 0.1.3
High-performance C++20 thread-safe logging system with asynchronous capabilities
Loading...
Searching...
No Matches
log_context.h
Go to the documentation of this file.
1// BSD 3-Clause License
2
9#pragma once
10
11#include <chrono>
12#include <string_view>
13#include <thread>
14
15namespace kcenon::logger::core {
16
17struct log_context {
18 std::string_view file{"unknown"};
19 int line{0};
20 std::string_view function{"unknown"};
21 std::thread::id thread_id{std::this_thread::get_id()};
22 std::chrono::time_point<std::chrono::system_clock> timestamp{
23 std::chrono::system_clock::now()};
24};
25
26inline log_context make_log_context(std::string_view file,
27 int line,
28 std::string_view function) {
29 log_context ctx;
30 ctx.file = file;
31 ctx.line = line;
32 ctx.function = function;
33 ctx.thread_id = std::this_thread::get_id();
34 ctx.timestamp = std::chrono::system_clock::now();
35 return ctx;
36}
37
38} // namespace kcenon::logger::core
log_context make_log_context(std::string_view file, int line, std::string_view function)
Create a log context with source location.
Definition log_context.h:26
Log context containing source location information.
Definition core.cppm:91
std::chrono::time_point< std::chrono::system_clock > timestamp
Definition log_context.h:22