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
23namespace cli::logging
24{
25
28{
29public:
30 virtual ~AbstractFormatter() = default;
31
35 virtual std::string format(const LogRecord &record) const = 0;
36};
37
41{
42public:
43 std::string format(const LogRecord &record) const override;
44
45private:
46 const std::chrono::time_zone *timezone = std::chrono::current_zone();
47};
48
51{
52public:
53 std::string format(const LogRecord &record) const override;
54};
55
56} // namespace cli::logging
Interface for log record formatters.
Definition formatter.h:28
virtual std::string format(const LogRecord &record) const =0
Formats a log record into a string.
Basic implementation of a log record formatter that includes timestamp, log level,...
Definition formatter.h:41
std::string format(const LogRecord &record) const override
Formats a log record into a string.
Definition formatter.cpp:26
Formatter that displays only the message of the log record.
Definition formatter.h:51
std::string format(const LogRecord &record) const override
Formats a log record into a string.
Definition formatter.cpp:36
Data structure representing a log record.
Definition logrecord.h:28