logger.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 The urg_stamped Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <iostream>
18 #include <sstream>
19 #include <string>
20 
21 #include <scip2/logger.h>
22 
23 namespace scip2
24 {
25 namespace logger
26 {
27 namespace
28 {
29 class DefaultStreamBuffer : public std::stringbuf
30 {
31 private:
32  bool active_;
33  std::ostream* raw_;
34  std::string type_;
35 
36 public:
37  DefaultStreamBuffer(std::ostream* raw, const char* type)
38  : raw_(raw)
39  , type_(type)
40  {
41  }
42  virtual int sync()
43  {
44  if (raw_)
45  {
46  *raw_ << "[" << type_ << "] " << str();
47  }
48  str("");
49  return 0;
50  }
51 };
52 
53 DefaultStreamBuffer debug_buf(&std::cout, "DEBUG");
54 DefaultStreamBuffer info_buf(&std::cout, " INFO");
55 DefaultStreamBuffer warn_buf(&std::cout, " WARN");
56 DefaultStreamBuffer error_buf(&std::cerr, "ERROR");
57 DefaultStreamBuffer fatal_buf(&std::cerr, "FATAL");
58 
59 std::ostream default_debug(&debug_buf);
60 std::ostream default_info(&info_buf);
61 std::ostream default_warn(&warn_buf);
62 std::ostream default_error(&error_buf);
63 std::ostream default_fatal(&fatal_buf);
64 
65 std::ostream* current_debug(&default_debug);
66 std::ostream* current_info(&default_info);
67 std::ostream* current_warn(&default_warn);
68 std::ostream* current_error(&default_error);
69 std::ostream* current_fatal(&default_fatal);
70 } // namespace
71 
72 void setDebugLogger(std::ostream* l)
73 {
74  current_debug = l;
75 }
76 void setInfoLogger(std::ostream* l)
77 {
78  current_info = l;
79 }
80 void setWarnLogger(std::ostream* l)
81 {
82  current_warn = l;
83 }
84 void setErrorLogger(std::ostream* l)
85 {
86  current_error = l;
87 }
88 void setFatalLogger(std::ostream* l)
89 {
90  current_fatal = l;
91 }
92 
93 std::ostream& debug()
94 {
95  return *current_debug;
96 }
97 std::ostream& info()
98 {
99  return *current_info;
100 }
101 std::ostream& warn()
102 {
103  return *current_warn;
104 }
105 std::ostream& error()
106 {
107  return *current_error;
108 }
109 std::ostream& fatal()
110 {
111  return *current_fatal;
112 }
113 } // namespace logger
114 } // namespace scip2
void setErrorLogger(std::ostream *l)
Definition: logger.cpp:84
void setInfoLogger(std::ostream *l)
Definition: logger.cpp:76
std::ostream & info()
Definition: logger.cpp:97
std::ostream & fatal()
Definition: logger.cpp:109
bool active_
Definition: logger.cpp:32
void setDebugLogger(std::ostream *l)
Definition: logger.cpp:72
std::ostream & debug()
Definition: logger.cpp:93
void setWarnLogger(std::ostream *l)
Definition: logger.cpp:80
std::ostream & warn()
Definition: logger.cpp:101
void setFatalLogger(std::ostream *l)
Definition: logger.cpp:88
std::ostream * raw_
Definition: logger.cpp:33
std::ostream & error()
Definition: logger.cpp:105
std::string type_
Definition: logger.cpp:34


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Tue May 11 2021 02:14:05