Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
logs.hpp
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
10#pragma once
11
18
20#include "shambase/logs.hpp"
21#include "shambase/print.hpp"
23#include <string>
24
42#define LIST_LEVEL \
43 X(debug_alloc, LogLevel_DebugAlloc) \
44 X(debug_mpi, LogLevel_DebugMPI) \
45 X(debug_sycl, LogLevel_DebugSYCL) \
46 X(debug, LogLevel_Debug) \
47 X(info, LogLevel_Info) \
48 X(normal, LogLevel_Normal) \
49 X(warn, LogLevel_Warning) \
50 X(err, LogLevel_Error)
51
52namespace shamcomm::logs {
53
54 using namespace shambase::logs;
55
57 // Base print without decoration
59
71 template<typename... Types>
72 inline void raw(Types... var2) {
73 print(var2...);
74 }
75
88 template<typename... Types>
89 inline void raw_ln(Types... var2) {
90 print_ln(var2...);
91 }
92
99 inline void print_faint_row() {
100 raw_ln(
101 shambase::term_colors::faint() + "-----------------------------------------------------"
103 }
104
106 // Log levels
108
110#define DECLARE_LOG_LEVEL(_name, StructREF) \
111 \
112 constexpr i8 log_##_name = (StructREF::logval); \
113 \
114 template<typename... Types> \
115 inline void _name(std::string module_name, Types... var2) { \
116 if (details::loglevel >= log_##_name) { \
117 shamcomm::logs::print( \
118 StructREF::reformat(shamcomm::logs::format_message(var2...), module_name)); \
119 } \
120 } \
121 \
122 template<typename... Types> \
123 inline void _name##_ln(std::string module_name, Types... var2) { \
124 if (details::loglevel >= log_##_name) { \
125 shamcomm::logs::print_ln( \
126 StructREF::reformat(shamcomm::logs::format_message(var2...), module_name)); \
127 } \
128 }
129
131#define X DECLARE_LOG_LEVEL
133#undef X
134
135#undef DECLARE_LOG_LEVEL
136
140 void print_active_level();
141
144
145} // namespace shamcomm::logs
146
154
162
167
175
183
188
196
204
209
217
225
230
238
246
251
259
267
272
280
288
293
301
309
314
318namespace logger {
319
320 using namespace shamcomm::logs;
321 using namespace shambase::logs;
322
323} // namespace logger
alias namespace to simplify the use of log functions
Definition logs.hpp:318
Namespace containing logs utils.
Definition loglevel.hpp:24
void print()
Prints a log message with no arguments.
void print_ln()
Prints a log message with multiple arguments followed by a newline.
void print_active_level()
Prints the active log levels.
Definition logs.cpp:33
void code_init_done_log()
Indicates that the code initialization is complete through various means ;).
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:89
void raw(Types... var2)
Prints a log message with multiple arguments without newline.
Definition logs.hpp:72
void print_faint_row()
Prints a faint separator line to the log.
Definition logs.hpp:99
#define LIST_LEVEL
X-macro for log level definition.
Definition logs.hpp:42
const std::string reset()
Get the reset terminal escape char.
const std::string faint()
Get the faint terminal escape char.