20namespace alpaka::onHost::logger::internal
33 static StdErr inst = StdErr{};
37 std::ostream&
operator<<(
auto const& input)
const
39 return std::cerr << input;
66 return indentLvl.load();
70 std::atomic<int> indentLvl = 1;
77 inline void indent(
auto& writer, [[maybe_unused]]
int indentLvl)
79#if defined(ALPAKA_LOG_INDENT)
80 for(
int i = 0; i < indentLvl; ++i)
81 i == 0 ? (writer <<
"|-") : (writer <<
"--");
94 inline std::string adjStringLength(std::string str,
size_t n,
char const paddingCharacter =
' ')
100 str.resize(n, paddingCharacter);
108 inline std::string adjDetails(std::string
const& str)
110#if defined(ALPAKA_LOG_DETAIL_SHORT)
118 template<logger::concepts::Level T_LogLvl,
typename T_Writer = StdErr>
122 Scoped(T_LogLvl logLvl, std::source_location
const& location)
123 : m_functionName{adjDetails(location.function_name())}
124 , m_prefix{std::string(
"[") + adjStringLength(logLvl.getName(), 6) +
"]"}
125 , m_startTime{std::chrono::high_resolution_clock::now()}
126 , m_writer{T_Writer::get()}
128 m_writer << m_prefix <<
"[+]";
129 indent(m_writer, m_writer.enter());
130 m_writer << m_functionName << std::endl;
133 Scoped(T_LogLvl logLvl) : m_writer{T_Writer::get()}, m_enableOutput{
false}
135 alpaka::unused(logLvl);
138 Scoped(Scoped
const&) =
delete;
139 Scoped(Scoped&&) =
delete;
140 Scoped& operator=(Scoped
const&) =
delete;
141 Scoped& operator=(Scoped&&) =
delete;
147 auto const endTime = std::chrono::high_resolution_clock::now();
148 double durationInSeconds = std::chrono::duration<double, std::milli>(endTime - m_startTime).count();
150 m_writer << m_prefix <<
"[-]";
151 indent(m_writer, m_writer.leave());
152 m_writer << m_functionName <<
" " << durationInSeconds <<
" ms" << std::endl;
157 std::string m_functionName;
158 std::string m_prefix;
159 decltype(std::chrono::high_resolution_clock::now()) m_startTime;
161 bool m_enableOutput =
true;
168 template<logger::concepts::Level T_LogLvl,
typename T_Callable,
typename T_Writer = StdErr>
169 requires(std::is_invocable_r_v<std::string, T_Callable>)
173 Info(T_LogLvl logLvl, T_Callable
const& callable, std::source_location
const& location)
175 auto fullPrefix = std::string(
"[") + adjStringLength(logLvl.getName(), 6) +
"]";
177 auto& writer = T_Writer::get();
178 std::stringstream ss;
180 writer << fullPrefix << ss.str();
181 indent(writer, writer.current());
182 writer << callable() <<
" " << adjDetails(location.function_name()) <<
" " << location.file_name() <<
":"
183 << location.line() << std::endl;
186 Info(Info
const&) =
delete;
187 Info(Info&&) =
delete;
188 Info& operator=(Info
const&) =
delete;
189 Info& operator=(Info&&) =
delete;