Skip to content
GitLab
Explore
Sign in
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
dc08b2bc
Commit
dc08b2bc
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Refined log redirection code
parent
31c801aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+1
-1
1 addition, 1 deletion
SDP/SDP/SDP.py
SDP/SDP/lofar_logging.py
+18
-8
18 additions, 8 deletions
SDP/SDP/lofar_logging.py
with
19 additions
and
9 deletions
SDP/SDP/SDP.py
+
1
−
1
View file @
dc08b2bc
...
@@ -30,7 +30,7 @@ from lofar_logging import device_logging_to_python, log_exceptions
...
@@ -30,7 +30,7 @@ from lofar_logging import device_logging_to_python, log_exceptions
__all__
=
[
"
SDP
"
,
"
main
"
]
__all__
=
[
"
SDP
"
,
"
main
"
]
@device_logging_to_python
(
"
SDP
"
)
@device_logging_to_python
(
{
"
device
"
:
"
SDP
"
}
)
class
SDP
(
Device
):
class
SDP
(
Device
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
SDP/SDP/lofar_logging.py
+
18
−
8
View file @
dc08b2bc
import
logging
import
logging
import
tango
from
functools
import
wraps
from
functools
import
wraps
def
configured_logger
(
name
=
''
):
def
configure_logger
(
logger
:
logging
.
Logger
,
log_extra
=
None
):
logger
=
logging
.
getLogger
(
name
)
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
setLevel
(
logging
.
DEBUG
)
try
:
try
:
from
logstash_async.handler
import
AsynchronousLogstashHandler
from
logstash_async.handler
import
AsynchronousLogstashHandler
,
LogstashFormatter
logger
.
addHandler
(
AsynchronousLogstashHandler
(
"
elk
"
,
5959
,
database_path
=
'
logstash_test.db
'
))
# log to the tcp_input of logstash in our ELK stack
handler
=
AsynchronousLogstashHandler
(
"
elk
"
,
5959
,
database_path
=
'
pending_log_messages.db
'
)
# configure log messages
formatter
=
LogstashFormatter
(
extra
=
log_extra
,
tags
=
[
"
python
"
,
"
lofar
"
])
handler
.
setFormatter
(
formatter
)
# install the handler
logger
.
addHandler
(
handler
)
except
Exception
:
except
Exception
:
logger
.
exception
(
"
Cannot import or configure logstash_async module, not forwarding logs to ELK stack.
"
)
logger
.
exception
(
"
Cannot import or configure logstash_async module, not forwarding logs to ELK stack.
"
)
return
logger
return
logger
def
device_logging_to_python
(
name
=
''
):
def
device_logging_to_python
(
log_extra
:
dict
=
None
):
"""
Call this on a Tango Device instance or class to have your Tango Device log to python instead.
"""
"""
Call this on a Tango Device instance or class to have your Tango Device log to python instead.
"""
logger
=
configured_logger
(
name
)
def
inner
(
cls
):
def
inner
(
cls
):
# Create a logger that logs to ELK, dedicated for this class
logger
=
logging
.
getLogger
(
cls
.
__name__
)
configure_logger
(
logger
,
log_extra
)
# Monkey patch the python logger to replace the tango logger
# Monkey patch the python logger to replace the tango logger
cls
.
debug_stream
=
logger
.
debug
cls
.
debug_stream
=
logger
.
debug
cls
.
info_stream
=
logger
.
info
cls
.
info_stream
=
logger
.
info
...
@@ -34,6 +42,8 @@ def device_logging_to_python(name = ''):
...
@@ -34,6 +42,8 @@ def device_logging_to_python(name = ''):
return
inner
return
inner
def
log_exceptions
(
func
):
def
log_exceptions
(
func
):
"""
Decorator that logs all exceptions that the function raises.
"""
@wraps
(
func
)
@wraps
(
func
)
def
inner
(
self
,
*
args
,
**
kwargs
):
def
inner
(
self
,
*
args
,
**
kwargs
):
try
:
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