MinitScript  0.9.31 PRE-BETA
ErrorConsole.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <string_view>
4 
7 
8 using std::cerr;
9 using std::endl;
10 using std::unique_ptr;
11 
13 
14 unique_ptr<ErrorConsole::Logger> ErrorConsole::logger;
15 
16 void ErrorConsole::setLogger(Logger* logger) {
17  ErrorConsole::logger = unique_ptr<Logger>(logger);
18 }
19 
20 void ErrorConsole::printLine(const string_view& str)
21 {
22  // log to logger
23  if (logger != nullptr) {
24  logger->printLine(str);
25  return;
26  }
27  // nope, cerr this
28  cerr << str << endl;
29  cerr.flush();
30 }
31 
32 void ErrorConsole::print(const string_view& str)
33 {
34  // log to logger
35  if (logger != nullptr) {
36  logger->print(str);
37  return;
38  }
39  // nope, cerr this
40  cerr << str;
41  cerr.flush();
42 }
43 
45 {
46  // log to logger
47  if (logger != nullptr) {
48  logger->printLine();
49  return;
50  }
51  // nope, cerr this
52  cerr << endl;
53  cerr.flush();
54 }
static void printLine()
Print newline to error console.
static void print(const string_view &str)
Print given string to error console without trainling new line.
static MINITSCRIPT_STATIC_DLL_IMPEXT unique_ptr< Logger > logger
Definition: ErrorConsole.h:73