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
20#include "shambase/logs.hpp"
21#include "shambase/print.hpp"
22#include "shambase/string.hpp"
24#include <string>
25
43#define LIST_LEVEL \
44 X(debug_alloc, LogLevel_DebugAlloc) \
45 X(debug_mpi, LogLevel_DebugMPI) \
46 X(debug_sycl, LogLevel_DebugSYCL) \
47 X(debug, LogLevel_Debug) \
48 X(info, LogLevel_Info) \
49 X(normal, LogLevel_Normal) \
50 X(warn, LogLevel_Warning) \
51 X(err, LogLevel_Error)
52
53namespace shamcomm::logs {
54
55 using namespace shambase::logs;
56
58 // Base print without decoration
60
72 template<typename... Types>
73 inline void raw(Types... var2) {
74 print(var2...);
75 }
76
89 template<typename... Types>
90 inline void raw_ln(Types... var2) {
91 print_ln(var2...);
92 }
93
100 inline void print_faint_row() {
101 raw_ln(
102 shambase::term_colors::faint() + "-----------------------------------------------------"
103 + shambase::term_colors::reset());
104 }
105
107 // Log levels
109
111#define DECLARE_LOG_LEVEL(_name, StructREF) \
112 \
113 constexpr i8 log_##_name = (StructREF::logval); \
114 \
115 template<typename... Types> \
116 inline void _name(std::string module_name, Types... var2) { \
117 if (details::loglevel >= log_##_name) { \
118 shamcomm::logs::print( \
119 StructREF::reformat(shamcomm::logs::format_message(var2...), module_name)); \
120 } \
121 } \
122 \
123 template<typename... Types> \
124 inline void _name##_ln(std::string module_name, Types... var2) { \
125 if (details::loglevel >= log_##_name) { \
126 shamcomm::logs::print_ln( \
127 StructREF::reformat(shamcomm::logs::format_message(var2...), module_name)); \
128 } \
129 }
130
132#define X DECLARE_LOG_LEVEL
134#undef X
135
136#undef DECLARE_LOG_LEVEL
137
141 void print_active_level();
142
144 void code_init_done_log();
145
146} // namespace shamcomm::logs
147
319namespace logger {
320
321 using namespace shamcomm::logs;
322 using namespace shambase::logs;
323
324} // namespace logger
alias namespace to simplify the use of log functions
Definition logs.hpp:319
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 ;)
Definition logs.cpp:57
void raw_ln(Types... var2)
Prints a log message with multiple arguments followed by a newline.
Definition logs.hpp:90
void raw(Types... var2)
Prints a log message with multiple arguments without newline.
Definition logs.hpp:73
void print_faint_row()
Prints a faint separator line to the log.
Definition logs.hpp:100
#define LIST_LEVEL
X-macro for log level definition.
Definition logs.hpp:43