tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
pc_error_handler.h
Go to the documentation of this file.
1#include <iostream>
2#include <sstream>
4
6{
7public:
8 template <typename T>
9 static void log(const T &msg, ErrorLevel level)
10 {
11 std::ostringstream oss;
12 oss << msg; // works for any type that has operator<< defined
13
14 std::string prefix;
15 switch (level)
16 {
18 std::cout << oss.str();
19 return;
21 prefix = "[INFO] ";
22 break;
24 prefix = "[WARN] ";
25 break;
27 prefix = "[ERROR] ";
28 break;
30 prefix = "[FATAL] ";
31 break;
32 }
33
34 std::cerr << prefix << oss.str() << std::endl;
35 }
36
37 // variadic log
38 template <typename... Args>
39 static void log(ErrorLevel level, Args &&...args)
40 {
41 std::ostringstream oss;
42 (oss << ... << forward<Args>(args));
43
44 std::string prefix;
45 switch (level)
46 {
48 std::cout << oss.str();
49 return;
51 prefix = "[INFO] ";
52 break;
54 prefix = "[WARN] ";
55 break;
57 prefix = "[ERROR] ";
58 break;
60 prefix = "[FATAL] ";
61 break;
62 }
63
64 std::cerr << prefix << oss.str() << std::endl;
65 }
66
67 template <typename... Args>
68 [[noreturn]] static void error(Args &&...args)
69 {
70 std::ostringstream oss;
71 (oss << ... << forward<Args>(args));
72 throw std::runtime_error(oss.str());
73 }
74};
Definition pc_error_handler.h:6
static void log(ErrorLevel level, Args &&...args)
Definition pc_error_handler.h:39
static void log(const T &msg, ErrorLevel level)
Definition pc_error_handler.h:9
static void error(Args &&...args)
Definition pc_error_handler.h:68
ErrorLevel
Definition error_handler.h:5