Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
logs.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
20#include "shamcomm/logs.hpp"
22#include <cmath>
23
24namespace shamcomm::logs {
25
27 // log level declared printer
29
31#define IsActivePrint(_name, StructREF) _name##_ln("xxx", "xxx", "(", "logger::" #_name, ")");
32
34 raw_ln("log status : ");
35 if (get_loglevel() == i8_max) {
36 raw_ln("If you've seen spam in your life i can garantee you, this is worst");
37 }
38
39 raw_ln(shambase::format(" - Loglevel: {}, enabled log types :", u32(get_loglevel())));
40
41// logger::raw_ln(terminal_effects::faint + "----------------------" + terminal_effects::reset);
42
44#define X IsActivePrint
46#undef X
47 // logger::raw_ln(terminal_effects::faint + "----------------------" +
48 // terminal_effects::reset);
49 }
50
51#undef IsActivePrint
52
54 // Code init done
56
58
59 auto lines = std::array<std::string, 16>{
60 // Someone that coded too much here
61 "Now it's time to " + shambase::term_colors::col8b_cyan()
62 + shambase::term_colors::blink() + "ROCK" + shambase::term_colors::reset() + ".",
63 "Shamrock rolls - no time for moss.", // Rolling stone gathers no moss.
64 "Shamrock's live - go with the flow.",
65 "Shamrock - as solid as a rock.",
66 "Shamrock's stable and steady as a rock.",
67 "Shamrock initialized - no cracks in this rock.",
68 "Shamrock is ready to eat cheese (melted) and bread.",
69 "Are you sure you want to work today?",
70 "No holidays for the Shamrock ... (yeah, this was a PhD at some point)",
71 "-[--->+<]>--.>+[----->+++<]>+.-------.++++++++++++.+++++.---.------------.++++++++.",
72 "CPU hours to burn? We don't do such thing here.",
73 "Are you burning GPUs or CPUs today?",
74
75 // Someone that started on oumuamua
76 "Shamrock your way to a brighter day!",
77 "Node hours to burn? Leaf it to me.",
78 "Ready for some shamazing simulations?",
79 R"=(
80While you wait for this simulation to run, give that cat a hug!
81
82 |\__/,| (`\
83 _.|o o |_ ) )
84-(((---(((--------
85 )="};
86
87 auto get_sentence = [&]() {
88 f64 t = shambase::details::get_wtime();
89 u64 idx = static_cast<u64>(std::floor(
90 t * 2503'09713 // you wont guess what this stands for
91 ))
92 % lines.size();
93 return lines[idx];
94 };
95
96 if (shamcomm::world_rank() == 0) {
97 logger::print_faint_row();
98 logger::raw_ln(
99 " - Code init:",
100 shambase::term_colors::col8b_green() + "DONE" + shambase::term_colors::reset()
101 + ".",
102 get_sentence());
103 logger::print_faint_row();
104 }
105 }
106
107} // namespace shamcomm::logs
108
109std::string LogLevel_DebugAlloc::reformat(const std::string &in, std::string module_name) {
110 return logger::reformat_all(shambase::term_colors::col8b_red(), level_name, module_name, in);
111}
112
113std::string LogLevel_DebugMPI::reformat(const std::string &in, std::string module_name) {
114 return logger::reformat_all(shambase::term_colors::col8b_blue(), level_name, module_name, in);
115}
116
117std::string LogLevel_DebugSYCL::reformat(const std::string &in, std::string module_name) {
119 shambase::term_colors::col8b_magenta(), level_name, module_name, in);
120}
121
122std::string LogLevel_Debug::reformat(const std::string &in, std::string module_name) {
123 return logger::reformat_all(shambase::term_colors::col8b_green(), level_name, module_name, in);
124}
125
126std::string LogLevel_Info::reformat(const std::string &in, std::string module_name) {
127 return logger::reformat_all(shambase::term_colors::col8b_cyan(), "Info", module_name, in);
128}
129
130std::string LogLevel_Normal::reformat(const std::string &in, std::string module_name) {
131 return logger::reformat_simple(shambase::term_colors::empty(), level_name, module_name, in);
132}
133
134std::string LogLevel_Warning::reformat(const std::string &in, std::string module_name) {
135 return logger::reformat_all(shambase::term_colors::col8b_yellow(), level_name, module_name, in);
136}
137
138std::string LogLevel_Error::reformat(const std::string &in, std::string module_name) {
139 return logger::reformat_all(shambase::term_colors::col8b_red(), level_name, module_name, in);
140}
double f64
Alias for double.
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
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.
i8 get_loglevel()
Get the current global log level.
Definition loglevel.hpp:52
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.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Definition worldInfo.cpp:40
constexpr i8 i8_max
i8 max value
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
#define LIST_LEVEL
X-macro for log level definition.
Definition logs.hpp:43
This file contains the definition for the stacktrace related functionality.
static constexpr const char * level_name
Log level name.
Definition loglevels.hpp:29
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for debugging memory allocation.
Definition logs.cpp:109
static constexpr const char * level_name
Log level name.
Definition loglevels.hpp:67
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for debugging MPI operations.
Definition logs.cpp:113
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for debugging SYCL operations.
Definition logs.cpp:117
static constexpr const char * level_name
Log level name.
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for debugging general operations.
Definition logs.cpp:122
static constexpr const char * level_name
Log level name.
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for error messages.
Definition logs.cpp:138
static constexpr const char * level_name
Log level name.
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for informational messages.
Definition logs.cpp:126
static constexpr const char * level_name
Log level name.
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for normal messages.
Definition logs.cpp:130
static constexpr const char * level_name
Log level name.
static std::string reformat(const std::string &in, std::string module_name)
Log formatter function for warning messages.
Definition logs.cpp:134
Functions related to the MPI communicator.