EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
Loading...
Searching...
No Matches
Logger.cpp
Go to the documentation of this file.
1
7
8
#include "
Logger.hpp
"
9
10
#include <
thread
>
11
12
#if defined(__EMSCRIPTEN__) || defined(__DOXYGEN__)
13
#include <emscripten/console.h>
14
#else
15
#include <
iostream
>
16
#include <
syncstream
>
17
#endif
18
19
namespace
echomap
20
{
21
22
void
Logger::log
(
23
const
Level
level,
24
const
std::string_view
message,
25
const
std::source_location
location
26
)
27
{
28
const
auto
line =
std::format
(
29
"[{} ({})] {}:{} says: {}"
,
30
level_to_string
(level),
31
std::this_thread::get_id
(),
32
location.
file_name
(),
33
location.
line
(),
34
message
35
);
36
37
#if defined(__EMSCRIPTEN__) || defined(__DOXYGEN__)
38
switch
(level) {
39
case
Level::Error:
40
emscripten_console_error(line.c_str());
41
break
;
42
case
Level::Info:
43
emscripten_console_log(line.c_str());
44
break
;
45
case
Level::Warning:
46
emscripten_console_warn(line.c_str());
47
break
;
48
case
Level::Debug:
49
// Do not use console.trace, since Chrome DevTools expands it.
50
emscripten_console_log(line.c_str());
51
break
;
52
}
53
#else
54
auto
stream =
std::osyncstream
(level == Level::Error ?
std::cerr
:
std::cout
);
55
stream << line <<
'\n'
;
56
#endif
57
}
58
59
std::string_view
Logger::level_to_string
(
60
const
Level
level
61
)
62
{
63
switch
(level) {
64
case
Level::Debug:
65
return
"Debug"
;
66
case
Level::Error:
67
return
"Error"
;
68
case
Level::Info:
69
return
"Info"
;
70
case
Level::Warning:
71
return
"Warning"
;
72
}
73
74
return
"Unknown"
;
75
}
76
77
}
// namespace echomap
Logger.hpp
EchoMap portable logger specification.
std::osyncstream
std::string_view
std::cerr
echomap::Logger::Level
Level
Indicates the level of importance of a logged message.
Definition
Logger.hpp:31
echomap::Logger::log
static void log(Level level, std::string_view message, std::source_location location=std::source_location::current())
Log an unformatted message to the backend.
Definition
Logger.cpp:22
echomap::Logger::level_to_string
static std::string_view level_to_string(Level level)
Get a human-readable string corresponding to the given log level.
Definition
Logger.cpp:59
std::cout
std::source_location::file_name
T file_name(T... args)
std::format
T format(T... args)
std::this_thread::get_id
T get_id(T... args)
iostream
std::source_location::line
T line(T... args)
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::source_location
syncstream
thread
src
utility
Logger.cpp
Generated by
1.17.0