ChainCLI
A modern C++20 command-line interface library
Loading...
Searching...
No Matches
formatter.h
1
/*
2
* Copyright 2025 Dominik Czekai
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#pragma once
18
#include <chrono>
19
#include <string>
20
21
#include "logrecord.h"
22
23
namespace
cli::logging
24
{
25
27
class
AbstractFormatter
28
{
29
public
:
30
virtual
~AbstractFormatter
() =
default
;
31
35
virtual
std::string
format
(
const
LogRecord
&record)
const
= 0;
36
};
37
40
class
BasicFormatter
:
public
AbstractFormatter
41
{
42
public
:
43
std::string
format
(
const
LogRecord
&record)
const override
;
44
45
private
:
46
const
std::chrono::time_zone *timezone = std::chrono::current_zone();
47
};
48
50
class
MessageOnlyFormatter
:
public
AbstractFormatter
51
{
52
public
:
53
std::string
format
(
const
LogRecord
&record)
const override
;
54
};
55
56
}
// namespace cli::logging
cli::logging::AbstractFormatter
Interface for log record formatters.
Definition
formatter.h:28
cli::logging::AbstractFormatter::format
virtual std::string format(const LogRecord &record) const =0
Formats a log record into a string.
cli::logging::BasicFormatter
Basic implementation of a log record formatter that includes timestamp, log level,...
Definition
formatter.h:41
cli::logging::BasicFormatter::format
std::string format(const LogRecord &record) const override
Formats a log record into a string.
Definition
formatter.cpp:26
cli::logging::MessageOnlyFormatter
Formatter that displays only the message of the log record.
Definition
formatter.h:51
cli::logging::MessageOnlyFormatter::format
std::string format(const LogRecord &record) const override
Formats a log record into a string.
Definition
formatter.cpp:36
cli::logging::LogRecord
Data structure representing a log record.
Definition
logrecord.h:28
src
chaincli
logging
formatter.h
Generated by
1.9.8