Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.core
Commits
2bb4be8c
Commit
2bb4be8c
authored
Sep 29, 2016
by
Manuel Günther
Browse files
Added C++ function to set log level
parent
9b0f4266
Pipeline
#4206
failed with stage
in 13 minutes and 1 second
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
bob/core/cpp/logging.cpp
View file @
2bb4be8c
...
...
@@ -140,12 +140,7 @@ bob::core::AutoOutputDevice::AutoOutputDevice()
bob
::
core
::
AutoOutputDevice
::
AutoOutputDevice
(
const
std
::
string
&
configuration
)
:
m_device
()
{
std
::
string
str
(
configuration
);
str
.
erase
(
std
::
remove_if
(
str
.
begin
(),
str
.
end
(),
::
isspace
),
str
.
end
());
if
(
str
==
"null"
||
str
.
size
()
==
0
)
m_device
.
reset
(
new
NullOutputDevice
);
else
if
(
str
==
"stdout"
)
m_device
.
reset
(
new
StdoutOutputDevice
);
else
if
(
str
==
"stderr"
)
m_device
.
reset
(
new
StderrOutputDevice
);
else
m_device
.
reset
(
new
FileOutputDevice
(
configuration
));
reset
(
configuration
);
}
bob
::
core
::
AutoOutputDevice
::
AutoOutputDevice
(
boost
::
shared_ptr
<
OutputDevice
>
d
)
...
...
@@ -156,6 +151,16 @@ bob::core::AutoOutputDevice::AutoOutputDevice(boost::shared_ptr<OutputDevice> d)
bob
::
core
::
AutoOutputDevice
::~
AutoOutputDevice
()
{
}
void
bob
::
core
::
AutoOutputDevice
::
reset
(
const
std
::
string
&
configuration
)
{
std
::
string
str
(
configuration
);
str
.
erase
(
std
::
remove_if
(
str
.
begin
(),
str
.
end
(),
::
isspace
),
str
.
end
());
if
(
str
==
"null"
||
str
.
size
()
==
0
)
m_device
.
reset
(
new
NullOutputDevice
);
else
if
(
str
==
"stdout"
)
m_device
.
reset
(
new
StdoutOutputDevice
);
else
if
(
str
==
"stderr"
)
m_device
.
reset
(
new
StderrOutputDevice
);
else
m_device
.
reset
(
new
FileOutputDevice
(
configuration
));
}
std
::
streamsize
bob
::
core
::
AutoOutputDevice
::
write
(
const
char
*
s
,
std
::
streamsize
n
)
{
return
m_device
->
write
(
s
,
n
);
}
...
...
@@ -168,3 +173,10 @@ boost::iostreams::stream<bob::core::AutoOutputDevice> bob::core::debug("stdout")
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
bob
::
core
::
info
(
"stdout"
);
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
bob
::
core
::
warn
(
"stderr"
);
boost
::
iostreams
::
stream
<
bob
::
core
::
AutoOutputDevice
>
bob
::
core
::
error
(
"stderr"
);
void
bob
::
core
::
log_level
(
bob
::
core
::
LOG_LEVEL
level
){
bob
::
core
::
debug
->
reset
(
level
==
DEBUG
?
"stdout"
:
"null"
);
bob
::
core
::
info
->
reset
(
level
>=
INFO
&&
level
<
DISABLE
?
"stdout"
:
"null"
);
bob
::
core
::
warn
->
reset
(
level
>=
WARNING
&&
level
<
DISABLE
?
"stderr"
:
"null"
);
bob
::
core
::
error
->
reset
(
level
>=
ERROR
&&
level
<
DISABLE
?
"stderr"
:
"null"
);
}
bob/core/include/bob.core/logging.h
View file @
2bb4be8c
...
...
@@ -80,6 +80,13 @@ namespace bob { namespace core {
*/
AutoOutputDevice
(
boost
::
shared_ptr
<
OutputDevice
>
device
);
/**
* @brief Updates with the given configuration;
* see constructor documentation for supported values
*/
void
reset
(
const
std
::
string
&
configuration
);
/**
* @brief D'tor
*/
...
...
@@ -118,6 +125,24 @@ namespace bob { namespace core {
*/
bool
debug_level
(
unsigned
int
i
);
/** enum defining levels of logs in C++;
they are the same as in the Python bindings, except for DISABLE, which is None in Python*/
typedef
enum
{
ERROR
=
0
,
// only errors are printed
WARNING
=
1
,
// errors and warnings are printed
INFO
=
2
,
// errors, warnings and info messages are printed
DEBUG
=
3
,
// all messages are printed
DISABLE
=
9
// no message is printed
}
LOG_LEVEL
;
/**
* brief This method will set up our default log streams to the given log level
*
* warning: This function should only be used in pure C++ code, as Python uses its own log level handling
*/
void
log_level
(
LOG_LEVEL
level
=
DEBUG
);
}}
//returns the current location where the message is being printed
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment