EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
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
19namespace echomap
20{
21
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),
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
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
EchoMap portable logger specification.
Level
Indicates the level of importance of a logged message.
Definition Logger.hpp:31
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
static std::string_view level_to_string(Level level)
Get a human-readable string corresponding to the given log level.
Definition Logger.cpp:59
T file_name(T... args)
T format(T... args)
T get_id(T... args)
The main EchoMap outermost namespace for all non-exported symbols.