Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Core Modules
dune-common
Commits
dc660174
Commit
dc660174
authored
7 years ago
by
Martin Nolte
Browse files
Options
Downloads
Patches
Plain Diff
add Python logger to C++
parent
aa1078d6
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!790
Feature/add python bindings
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CMakeLists.txt
+1
-0
1 addition, 0 deletions
CMakeLists.txt
logger.hh
+99
-0
99 additions, 0 deletions
logger.hh
with
100 additions
and
0 deletions
CMakeLists.txt
+
1
−
0
View file @
dc660174
...
...
@@ -8,6 +8,7 @@ set(HEADERS
fmatrix.hh
fvector.hh
getdimension.hh
logger.hh
iteratorrange.hh
mpihelper.hh
numpyvector.hh
...
...
This diff is collapsed.
Click to expand it.
logger.hh
0 → 100644
+
99
−
0
View file @
dc660174
#ifndef DUNE_PYTHON_COMMON_LOGGER_HH
#define DUNE_PYTHON_COMMON_LOGGER_HH
#include
<string>
#include
<utility>
#include
<dune/common/visibility.hh>
#include
<dune/python/pybind11/pybind11.h>
namespace
Dune
{
namespace
Python
{
// Logger
// ------
struct
DUNE_PRIVATE
Logger
{
enum
class
Level
:
int
{
critical
=
50
,
error
=
40
,
warning
=
30
,
info
=
20
,
debug
=
10
,
notSet
=
0
};
explicit
Logger
(
const
std
::
string
&
name
)
:
logging_
(
pybind11
::
module
::
import
(
"logging"
)
),
logger_
(
logging_
.
attr
(
"getLogger"
)(
name
)
)
{}
template
<
class
...
Args
>
void
critical
(
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
log
(
Level
::
critical
,
msg
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
class
...
Args
>
void
error
(
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
log
(
Level
::
error
,
msg
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
class
...
Args
>
void
warning
(
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
log
(
Level
::
warning
,
msg
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
class
...
Args
>
void
info
(
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
log
(
Level
::
info
,
msg
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
class
...
Args
>
void
debug
(
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
log
(
Level
::
debug
,
msg
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
class
...
Args
>
void
log
(
int
level
,
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
#if PY_MAJOR_VERSION < 3
pybind11
::
object
pyLevel
=
pybind11
::
reinterpret_steal
<
pybind11
::
object
>
(
PyInt_FromLong
(
level
)
);
#else // #if PY_MAJOR_VERSION < 3
pybind11
::
object
pyLevel
=
pybind11
::
int_
(
level
);
#endif // #else // #if PY_MAJOR_VERSION < 3
logger_
.
attr
(
"log"
)(
pyLevel
,
msg
,
*
pybind11
::
make_tuple
(
std
::
forward
<
Args
>
(
args
)...
)
);
}
template
<
class
...
Args
>
void
log
(
Level
level
,
const
std
::
string
&
msg
,
Args
&&
...
args
)
const
{
log
(
static_cast
<
int
>
(
level
),
msg
,
std
::
forward
<
Args
>
(
args
)...
);
}
void
setLevel
(
int
level
)
{
logger_
.
attr
(
"setLevel"
)(
level
);
}
bool
isEnabledFor
(
int
level
)
{
return
pybind11
::
cast
<
bool
>
(
logger_
.
attr
(
"isEnabledFor"
)(
level
)
);
}
int
getEffectiveLevel
()
{
return
pybind11
::
cast
<
int
>
(
logger_
.
attr
(
"getEffectiveLevel"
)()
);
}
private
:
pybind11
::
module
logging_
;
pybind11
::
object
logger_
;
};
}
// namespace Python
}
// namespace Dune
#endif // #ifndef DUNE_PYTHON_COMMON_LOGGER_HH
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