Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
b21aa572
Commit
b21aa572
authored
13 years ago
by
Marco Biasini
Browse files
Options
Downloads
Patches
Plain Diff
python logging functions accept variable number of args
parent
8e05d5a1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/base/pymod/export_logger.cc
+51
-10
51 additions, 10 deletions
modules/base/pymod/export_logger.cc
modules/base/tests/test_log.py
+3
-0
3 additions, 0 deletions
modules/base/tests/test_log.py
with
54 additions
and
10 deletions
modules/base/pymod/export_logger.cc
+
51
−
10
View file @
b21aa572
...
...
@@ -17,6 +17,7 @@
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include
<boost/python.hpp>
#include
<boost/python/raw_function.hpp>
using
namespace
boost
::
python
;
#include
<ost/log.hh>
...
...
@@ -82,11 +83,51 @@ LogSinkPtr get_log_sink()
return
Logger
::
Instance
().
GetCurrentSink
();
}
void
log_error
(
const
String
&
m
)
{
LOG_ERROR
(
m
);}
void
log_warning
(
const
String
&
m
)
{
LOG_WARNING
(
m
);}
void
log_script
(
const
String
&
m
)
{
LOG_SCRIPT
(
m
);}
void
log_info
(
const
String
&
m
)
{
LOG_INFO
(
m
);}
void
log_verbose
(
const
String
&
m
)
{
LOG_VERBOSE
(
m
);}
String
args_to_string
(
tuple
args
,
dict
kwargs
)
{
std
::
stringstream
ss
;
bool
empty
=
true
;
for
(
size_t
i
=
0
,
l
=
len
(
args
);
i
<
l
;
++
i
)
{
if
(
!
empty
)
{
ss
<<
" "
;
}
empty
=
false
;
String
string_val
;
try
{
string_val
=
extract
<
String
>
(
args
[
i
]);
}
catch
(...)
{
string_val
=
extract
<
String
>
(
args
[
i
].
attr
(
"__str__"
)());
}
ss
<<
string_val
;
}
return
ss
.
str
();
}
object
log_error
(
tuple
args
,
dict
kwargs
)
{
LOG_ERROR
(
args_to_string
(
args
,
kwargs
));
return
object
();
}
object
log_warning
(
tuple
args
,
dict
kwargs
)
{
LOG_WARNING
(
args_to_string
(
args
,
kwargs
));
return
object
();
}
object
log_script
(
tuple
args
,
dict
kwargs
)
{
LOG_SCRIPT
(
args_to_string
(
args
,
kwargs
));
return
object
();
}
object
log_info
(
tuple
args
,
dict
kwargs
)
{
LOG_INFO
(
args_to_string
(
args
,
kwargs
));
return
object
();
}
object
log_verbose
(
tuple
args
,
dict
kwargs
)
{
LOG_VERBOSE
(
args_to_string
(
args
,
kwargs
));
return
object
();
}
void
reset_sinks
()
...
...
@@ -121,11 +162,11 @@ void export_Logger()
def
(
"PushLogSink"
,
push_log_sink
);
def
(
"GetCurrentLogSink"
,
get_log_sink
);
def
(
"PopLogSink"
,
pop_log_sink
);
def
(
"LogError"
,
log_error
);
def
(
"LogWarning"
,
log_warning
);
def
(
"LogInfo"
,
log_info
);
def
(
"LogScript"
,
log_script
);
def
(
"LogVerbose"
,
log_verbose
);
def
(
"LogError"
,
raw_function
(
log_error
,
1
)
);
def
(
"LogWarning"
,
raw_function
(
log_warning
,
1
)
);
def
(
"LogInfo"
,
raw_function
(
log_info
,
1
)
);
def
(
"LogScript"
,
raw_function
(
log_script
,
1
)
);
def
(
"LogVerbose"
,
raw_function
(
log_verbose
,
1
)
);
// this relatively ugly construct is required to work around a problem with
// the "ost" command-line interpreter. If we don't remove all the sinks from
...
...
This diff is collapsed.
Click to expand it.
modules/base/tests/test_log.py
+
3
−
0
View file @
b21aa572
...
...
@@ -34,6 +34,9 @@ class TestLog(unittest.TestCase):
ost
.
LogError
(
'
error message
'
)
self
.
assertEqual
(
ls
.
message
,
'
error message
\n
'
)
self
.
assertEqual
(
ls
.
severity
,
0
)
ost
.
LogWarning
(
1
,
2
,
3
)
self
.
assertEqual
(
ls
.
message
,
'
1 2 3
\n
'
)
self
.
assertEqual
(
ls
.
severity
,
1
)
ost
.
PopLogSink
()
if
__name__
==
"
__main__
"
:
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment