Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
generic
Logger.cpp
Go to the documentation of this file.
1
/****************************************************************
2
*
3
* Copyright (c) 2011
4
* All rights reserved.
5
*
6
* Hochschule Bonn-Rhein-Sieg
7
* University of Applied Sciences
8
* Computer Science Department
9
*
10
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
*
12
* Author:
13
* Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
14
* Supervised by:
15
* Gerhard K. Kraetzschmar
16
*
17
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18
*
19
* This sofware is published under a dual-license: GNU Lesser General Public
20
* License LGPL 2.1 and BSD license. The dual-license implies that users of this
21
* code may choose which terms they prefer.
22
*
23
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
*
25
* Redistribution and use in source and binary forms, with or without
26
* modification, are permitted provided that the following conditions are met:
27
*
28
* * Redistributions of source code must retain the above copyright
29
* notice, this list of conditions and the following disclaimer.
30
* * Redistributions in binary form must reproduce the above copyright
31
* notice, this list of conditions and the following disclaimer in the
32
* documentation and/or other materials provided with the distribution.
33
* * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
34
* contributors may be used to endorse or promote products derived from
35
* this software without specific prior written permission.
36
*
37
* This program is free software: you can redistribute it and/or modify
38
* it under the terms of the GNU Lesser General Public License LGPL as
39
* published by the Free Software Foundation, either version 2.1 of the
40
* License, or (at your option) any later version or the BSD license.
41
*
42
* This program is distributed in the hope that it will be useful,
43
* but WITHOUT ANY WARRANTY; without even the implied warranty of
44
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45
* GNU Lesser General Public License LGPL and the BSD license for more details.
46
*
47
* You should have received a copy of the GNU Lesser General Public
48
* License LGPL and BSD license along with this program.
49
*
50
****************************************************************/
51
52
#include "
youbot_driver/generic/Logger.hpp
"
53
54
namespace
youbot
{
55
56
bool
Logger::toConsole
=
true
;
57
bool
Logger::toFile
=
false
;
58
bool
Logger::toROS
=
false
;
59
severity_level
Logger::logginLevel
=
info
;
60
61
Logger::Logger
(
const
std::string &funcName,
const
int
&lineNo,
const
std::string &fileName,
severity_level
level) {
62
#ifndef USE_ROS_LOGGING
63
if
(
toROS
) {
64
toConsole
=
true
;
65
}
66
#endif
67
68
this->level =
level
;
69
if
(
toConsole
||
toFile
) {
70
if
(level >=
logginLevel
) {
71
print
=
true
;
72
73
switch
(level) {
74
case
trace
:
75
out
<<
"Trace"
<<
": "
;
76
break
;
77
case
debug
:
78
out
<<
"Debug"
<<
": "
;
79
break
;
80
case
info
:
81
out
<<
"Info"
<<
": "
;
82
break
;
83
case
warning
:
84
out
<<
"Warning"
<<
": "
;
85
break
;
86
case
error
:
87
out
<<
"Error"
<<
": "
;
88
break
;
89
case
fatal
:
90
out
<<
"Fatal"
<<
": "
;
91
break
;
92
default
:
93
break
;
94
}
95
// out << "function " << funcName << ": ";
96
// out << "line " << lineNo << ": ";
97
// out << "fileName " << fileName << ": ";
98
// out << "time " << boost::posix_time::microsec_clock::local_time() << ": ";
99
}
else
{
100
print
=
false
;
101
}
102
}
else
{
103
print
=
false
;
104
}
105
106
}
107
108
Logger::~Logger
() {
109
//end of message
110
if
(
toConsole
&&
print
) {
111
printf(
"%s\n"
,
out
.str().c_str());
112
// std::cout << out.str() << std::endl;
113
}
114
115
if
(
toFile
&&
print
) {
116
std::fstream filestr;
117
filestr.open(
"log.txt"
, std::fstream::out | std::fstream::app);
118
filestr <<
out
.str() << std::endl;
119
filestr.close();
120
}
121
#ifdef USE_ROS_LOGGING
122
if
(
toROS
) {
123
switch
(
level
) {
124
case
trace
:
125
ROS_DEBUG
(
"%s"
,
out
.str().c_str());
126
break
;
127
case
debug
:
128
ROS_DEBUG
(
"%s"
,
out
.str().c_str());
129
break
;
130
case
info
:
131
ROS_INFO
(
"%s"
,
out
.str().c_str());
132
break
;
133
case
warning
:
134
ROS_WARN
(
"%s"
,
out
.str().c_str());
135
break
;
136
case
error
:
137
ROS_ERROR
(
"%s"
,
out
.str().c_str());
138
break
;
139
case
fatal
:
140
ROS_FATAL
(
"%s"
,
out
.str().c_str());
141
break
;
142
default
:
143
break
;
144
}
145
}
146
#endif
147
}
148
149
}
// namespace youbot
youbot::severity_level
severity_level
Definition:
Logger.hpp:65
ROS_FATAL
#define ROS_FATAL(...)
youbot::error
Definition:
Logger.hpp:70
youbot
Definition:
FourSwedishWheelOmniBaseKinematic.hpp:60
youbot::Logger::toROS
static bool toROS
Definition:
Logger.hpp:89
youbot::Logger::~Logger
~Logger()
Definition:
Logger.cpp:108
ROS_WARN
#define ROS_WARN(...)
youbot::Logger::logginLevel
static severity_level logginLevel
Definition:
Logger.hpp:90
youbot::Logger::Logger
Logger(const std::string &funcName, const int &lineNo, const std::string &fileName, severity_level level)
Definition:
Logger.cpp:61
Logger.hpp
youbot::Logger::out
std::stringstream out
Definition:
Logger.hpp:79
youbot::Logger::toConsole
static bool toConsole
Definition:
Logger.hpp:87
ROS_INFO
#define ROS_INFO(...)
youbot::Logger::toFile
static bool toFile
Definition:
Logger.hpp:88
youbot::Logger::print
bool print
Definition:
Logger.hpp:80
youbot::warning
Definition:
Logger.hpp:69
youbot::debug
Definition:
Logger.hpp:67
youbot::fatal
Definition:
Logger.hpp:71
youbot::trace
Definition:
Logger.hpp:66
youbot::info
Definition:
Logger.hpp:68
ROS_ERROR
#define ROS_ERROR(...)
ROS_DEBUG
#define ROS_DEBUG(...)
youbot::Logger::level
severity_level level
Definition:
Logger.hpp:81
youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:24