numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
compact_log_formatter.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 MusicScience37 (Kenta Kabashima)
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 */
20#pragma once
21
22#include <cstddef>
23#include <iterator>
24#include <string_view>
25
26#include <fmt/base.h>
27#include <fmt/format.h>
28
34
36
45public:
47 void format(fmt::memory_buffer& buffer, time_stamp time,
48 std::string_view tag, log_level level, util::source_info_view source,
49 std::string_view body) override {
50 std::string_view filename = source.file_path();
51 const std::size_t last_separator_pos = filename.find_last_of("/\\");
52 if (last_separator_pos != std::string_view::npos) {
53 filename = filename.substr(last_separator_pos + 1);
54 }
55
56 fmt::format_to(std::back_inserter(buffer),
57 FMT_STRING("[{}] [{}] [{}] {} ({}:{}, {})"), time,
58 get_output_log_level_str(level), tag, body, filename, source.line(),
59 source.function_name());
60 }
61
64
66 ~compact_log_formatter() override = default;
67
70 auto operator=(const compact_log_formatter&) = delete;
71 auto operator=(compact_log_formatter&&) = delete;
72};
73
74} // namespace num_collect::logging::formatters
void format(fmt::memory_buffer &buffer, time_stamp time, std::string_view tag, log_level level, util::source_info_view source, std::string_view body) override
Format a log.
Class of time stamps.
Definition time_stamp.h:38
Class to hold information of source codes.
constexpr auto line() const -> index_type
Get the line number.
constexpr auto function_name() const -> std::string_view
Get the function name.
constexpr auto file_path() const -> std::string_view
Get the file path.
Definition of get_output_log_level_str function.
Definition of log_formatter_base class.
Definition of log_level enumeration.
auto get_output_log_level_str(log_level level) noexcept -> std::string_view
Get the log level string for outputs.
log_level
Enumeration of log levels.
Definition log_level.h:47
Definition of source_info_view class.
Definition of time_stamp class.