ONE - On-device Neural Engine
Loading...
Searching...
No Matches
hermes::ConsoleReporter Struct Referencefinal

Print messages into standard console. More...

#include <ConsoleReporter.h>

Collaboration diagram for hermes::ConsoleReporter:

Public Member Functions

void notify (const Message *m) final
 
void set_colored_mode (bool is_colored)
 
- Public Member Functions inherited from hermes::Sink
virtual ~Sink ()=default
 

Detailed Description

Print messages into standard console.

Definition at line 28 of file ConsoleReporter.h.

Member Function Documentation

◆ notify()

void hermes::ConsoleReporter::notify ( const Message m)
finalvirtual

Implements hermes::Sink.

Definition at line 43 of file ConsoleReporter.cpp.

44{
45 if (not _env_checked)
46 {
47 const char *env_color_p = std::getenv("ONE_HERMES_COLOR");
48 if (env_color_p)
49 {
50 auto env_color_str = std::string(env_color_p);
51 if ((env_color_str == "1") or (env_color_str == "ON"))
52 _is_colored = true;
53 }
54 _env_checked = true;
55 }
56
57 if (_is_colored)
58 {
59 switch (m->get_severity())
60 {
61 case FATAL:
62 std::cout << kTermColorRedTextCode << kTermBoldTextCode << kTermUnderlineTextCode;
63 break;
64 case ERROR:
65 std::cout << kTermColorRedTextCode;
66 break;
67 case WARN:
68 std::cout << kTermColorOrangeTextCode;
69 break;
70 case INFO:
71 std::cout << kTermColorGreenTextCode;
72 break;
73 case VERBOSE:
74 std::cout << kTermColorResetAllCode;
75 break;
76 };
77 }
78 for (uint32_t n = 0; n < m->text()->lines(); ++n)
79 {
80 std::cout << m->text()->line(n) << std::endl;
81 }
82 if (_is_colored)
83 {
84 std::cout << kTermColorResetAllCode;
85 }
86}
@ FATAL
Definition Severity.h:33
@ ERROR
Definition Severity.h:34
@ VERBOSE
Definition Severity.h:37
@ INFO
Definition Severity.h:36
@ WARN
Definition Severity.h:35

References hermes::ERROR, hermes::FATAL, hermes::INFO, m, hermes::VERBOSE, and hermes::WARN.

◆ set_colored_mode()

void hermes::ConsoleReporter::set_colored_mode ( bool  is_colored)
inline

Definition at line 31 of file ConsoleReporter.h.

31{ _is_colored = is_colored; }

The documentation for this struct was generated from the following files: