Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
LOFAR2.0
tango
Commits
31c801aa
Commit
31c801aa
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Improve logger rerouting and added decorator to log exceptions.
parent
12b7195d
No related branches found
No related tags found
1 merge request
!7
Resolve #2021 "03 16 branched from master elk stack"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
SDP/SDP/SDP.py
+6
-3
6 additions, 3 deletions
SDP/SDP/SDP.py
SDP/SDP/lofar_logging.py
+30
-14
30 additions, 14 deletions
SDP/SDP/lofar_logging.py
with
36 additions
and
17 deletions
SDP/SDP/SDP.py
+
6
−
3
View file @
31c801aa
...
@@ -26,11 +26,12 @@ import numpy
...
@@ -26,11 +26,12 @@ import numpy
from
wrappers
import
only_in_states
,
only_when_on
,
fault_on_error
from
wrappers
import
only_in_states
,
only_when_on
,
fault_on_error
from
opcua_connection
import
OPCUAConnection
from
opcua_connection
import
OPCUAConnection
from
lofar_logging
import
PythonLoggingMixin
from
lofar_logging
import
device_logging_to_python
,
log_exceptions
__all__
=
[
"
SDP
"
,
"
main
"
]
__all__
=
[
"
SDP
"
,
"
main
"
]
class
SDP
(
Device
,
PythonLoggingMixin
):
@device_logging_to_python
(
"
SDP
"
)
class
SDP
(
Device
):
"""
"""
**Properties:**
**Properties:**
...
@@ -193,6 +194,8 @@ class SDP(Device, PythonLoggingMixin):
...
@@ -193,6 +194,8 @@ class SDP(Device, PythonLoggingMixin):
self
.
info_stream
(
"
Mapping OPC-UA MP/CP to attributes done.
"
)
self
.
info_stream
(
"
Mapping OPC-UA MP/CP to attributes done.
"
)
@log_exceptions
@DebugIt
()
def
init_device
(
self
):
def
init_device
(
self
):
"""
Instantiates the device in the OFF state.
"""
"""
Instantiates the device in the OFF state.
"""
...
@@ -201,6 +204,7 @@ class SDP(Device, PythonLoggingMixin):
...
@@ -201,6 +204,7 @@ class SDP(Device, PythonLoggingMixin):
self
.
set_state
(
DevState
.
OFF
)
self
.
set_state
(
DevState
.
OFF
)
@log_exceptions
def
initialise
(
self
):
def
initialise
(
self
):
"""
Initialises the attributes and properties of the SDP.
"""
"""
Initialises the attributes and properties of the SDP.
"""
...
@@ -476,7 +480,6 @@ class SDP(Device, PythonLoggingMixin):
...
@@ -476,7 +480,6 @@ class SDP(Device, PythonLoggingMixin):
"""
"""
self
.
set_state
(
DevState
.
FAULT
)
self
.
set_state
(
DevState
.
FAULT
)
# ----------
# ----------
# Run server
# Run server
# ----------
# ----------
...
...
This diff is collapsed.
Click to expand it.
SDP/SDP/lofar_logging.py
+
30
−
14
View file @
31c801aa
import
logging
import
logging
import
tango
from
functools
import
wraps
def
configured_logger
(
name
=
''
):
def
configured_logger
(
name
=
''
):
logger
=
logging
.
getLogger
(
name
)
logger
=
logging
.
getLogger
(
name
)
...
@@ -13,17 +15,31 @@ def configured_logger(name=''):
...
@@ -13,17 +15,31 @@ def configured_logger(name=''):
return
logger
return
logger
logger
=
configured_logger
()
def
device_logging_to_python
(
name
=
''
):
"""
Call this on a Tango Device instance or class to have your Tango Device log to python instead.
"""
class
PythonLoggingMixin
(
object
):
"""
Also inherit this class to have your Tango Device log to python instead.
"""
logger
=
configured_logger
(
name
)
# Monkey patch the python logger to replace the tango logger
def
inner
(
cls
):
debug_stream
=
logger
.
debug
# Monkey patch the python logger to replace the tango logger
info_stream
=
logger
.
info
cls
.
debug_stream
=
logger
.
debug
warn_stream
=
logger
.
warning
cls
.
info_stream
=
logger
.
info
warning_stream
=
logger
.
warning
cls
.
warn_stream
=
logger
.
warning
error_stream
=
logger
.
error
cls
.
warning_stream
=
logger
.
warning
fatal_stream
=
logger
.
fatal
cls
.
error_stream
=
logger
.
error
critical_stream
=
logger
.
critical
cls
.
fatal_stream
=
logger
.
fatal
cls
.
critical_stream
=
logger
.
critical
return
cls
return
inner
def
log_exceptions
(
func
):
@wraps
(
func
)
def
inner
(
self
,
*
args
,
**
kwargs
):
try
:
return
func
(
self
,
*
args
,
**
kwargs
)
except
Exception
as
e
:
self
.
error_stream
(
"
Caught exception: %s: %s
"
,
e
.
__class__
.
__name__
,
e
,
exc_info
=
1
)
raise
e
return
inner
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