RSC  0.19.0
SGRConsoleLogger.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSC project.
4  *
5  * Copyright (C) 2018 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #include "SGRConsoleLogger.h"
28 
29 #include "../misc/langutils.h"
30 
31 namespace rsc {
32 namespace logging {
33 
34 SGRConsoleLogger::SGRConsoleLogger(const std::string& name) :
35  ConsoleLogger(name) {
36 }
37 
39 
40 std::ostream& SGRConsoleLogger::printHeader(std::ostream& stream, const Level& level) {
41  return (stream
42  << "" << rsc::misc::currentTimeMillis() << ""
43  << " " << this->name << ""
44  << " [" << level << "]: ");
45 }
46 
47 std::ostream& SGRConsoleLogger::printBody(std::ostream& stream,
48  const Level& level,
49  const std::string& msg) {
50  switch (level) {
51  case LEVEL_TRACE:
52  case LEVEL_DEBUG:
53  return stream << "" << msg << "" << std::endl;
54  break;
55  case LEVEL_WARN:
56  return stream << "" << msg << "" << std::endl;
57  break;
58  case LEVEL_ERROR:
59  return stream << "" << msg << "" << std::endl;
60  break;
61  case LEVEL_FATAL:
62  return stream << "" << msg << "" << std::endl;
63  break;
64  default:
65  return stream << msg << std::endl;
66  break;
67  }
68 }
69 
70 }
71 }
std::ostream & printBody(std::ostream &stream, const Level &level, const std::string &msg)
A simple logger that uses cout and cerr for logging.
Definition: ConsoleLogger.h:45
boost::uint64_t currentTimeMillis()
Returns the current system time as milliseconds.
Definition: langutils.cpp:64
std::ostream & printHeader(std::ostream &stream, const Level &level)
Level
Possible logging levels.
Definition: Logger.h:63
SGRConsoleLogger(const std::string &name)