Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
reformat_message.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
19
20namespace shambase::logs {
21
29
37
42
51 std::string reformat_all(
52 const std::string &color,
53 const char *name,
54 const std::string &module_name,
55 const std::string &content) {
56 if (shambase::logs::_reformat_all == nullptr) {
57 // old form
58 return "[" + (color) + module_name + shambase::term_colors::reset() + "] " + (color)
59 + (name) + shambase::term_colors::reset() + ": " + content;
60 }
61
62 return shambase::logs::_reformat_all({color, name, module_name, content});
63 }
64
73 std::string reformat_simple(
74 const std::string &color,
75 const char *name,
76 const std::string &module_name,
77 const std::string &content) {
78
79 if (shambase::logs::_reformat_simple == nullptr) {
80 // old form
81 return "[" + (color) + module_name + shambase::term_colors::reset() + "] " + (color)
82 + (name) + shambase::term_colors::reset() + ": " + content;
83 }
84
85 return shambase::logs::_reformat_simple({color, name, module_name, content});
86 }
87} // namespace shambase::logs
Namespace containing logs utils.
Definition loglevel.hpp:24
void change_formaters(reformat_func_ptr full, reformat_func_ptr simple)
Changes the log formatter functions.
reformat_func_ptr _reformat_all
Pointer to the full formatter function.
std::string reformat_all(const std::string &color, const char *name, const std::string &module_name, const std::string &content)
Format a log message with all the information.
std::string(*)(const ReformatArgs &args) reformat_func_ptr
A pointer to a log formatter function.
reformat_func_ptr _reformat_simple
Pointer to the simple formatter function.
std::string reformat_simple(const std::string &color, const char *name, const std::string &module_name, const std::string &content)
Format a log message with the minimum information.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.