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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
69590e3e
Commit
69590e3e
authored
Oct 5, 2021
by
Corné Lukken
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-389
: Improve unit / integration test logging approach
parent
5c165216
No related branches found
No related tags found
1 merge request
!132
L2SS-389: Very naive approach to setup loggers for tests
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
devices/common/lofar_logging.py
+21
-18
21 additions, 18 deletions
devices/common/lofar_logging.py
devices/integration_test/base.py
+2
-10
2 additions, 10 deletions
devices/integration_test/base.py
devices/test/base.py
+2
-11
2 additions, 11 deletions
devices/test/base.py
with
25 additions
and
39 deletions
devices/common/lofar_logging.py
+
21
−
18
View file @
69590e3e
...
...
@@ -94,7 +94,7 @@ class LogAnnotator(logging.Formatter):
# we just annotate, we don't filter
return
True
def
configure_logger
(
logger
:
logging
.
Logger
=
None
,
log_extra
=
None
):
def
configure_logger
(
logger
:
logging
.
Logger
=
None
,
log_extra
=
None
,
debug
=
False
):
"""
Configure the given logger (or root if None) to:
- send logs to the ELK stack
...
...
@@ -114,6 +114,26 @@ def configure_logger(logger: logging.Logger=None, log_extra=None):
# remove spam from the OPC-UA client connection
logging
.
getLogger
(
"
opcua
"
).
setLevel
(
logging
.
WARN
)
# for now, also log to stderr
# Set up logging in a way that it can be understood by a human reader, be
# easily grep'ed, be parsed with a couple of shell commands and
# easily fed into an Kibana/Elastic search system.
handler
=
logging
.
StreamHandler
()
# Always also log the hostname because it makes the origin of the log clear.
hostname
=
socket
.
gethostname
()
formatter
=
logging
.
Formatter
(
fmt
=
'
%(asctime)s.%(msecs)d %(levelname)s - HOST=
"
{}
"
DEVICE=
"
%(tango_device)s
"
PID=
"
%(process)d
"
TNAME=
"
%(threadName)s
"
FILE=
"
%(pathname)s
"
LINE=
"
%(lineno)d
"
FUNC=
"
%(funcName)s
"
MSG=
"
%(message)s
"'
.
format
(
hostname
),
datefmt
=
'
%Y-%m-%dT%H:%M:%S
'
)
handler
.
setFormatter
(
formatter
)
handler
.
addFilter
(
LogSuppressErrorSpam
())
handler
.
addFilter
(
LogAnnotator
())
logger
.
addHandler
(
handler
)
# If configuring for debug; exit early
if
debug
:
return
logger
# Log to ELK stack
try
:
from
logstash_async.handler
import
AsynchronousLogstashHandler
,
LogstashFormatter
...
...
@@ -143,23 +163,6 @@ def configure_logger(logger: logging.Logger=None, log_extra=None):
except
Exception
:
logger
.
exception
(
"
Cannot forward logs to Tango.
"
)
# for now, also log to stderr
# Set up logging in a way that it can be understood by a human reader, be
# easily grep'ed, be parsed with a couple of shell commands and
# easily fed into an Kibana/Elastic search system.
handler
=
logging
.
StreamHandler
()
# Always also log the hostname because it makes the origin of the log clear.
hostname
=
socket
.
gethostname
()
formatter
=
logging
.
Formatter
(
fmt
=
'
%(asctime)s.%(msecs)d %(levelname)s - HOST=
"
{}
"
DEVICE=
"
%(tango_device)s
"
PID=
"
%(process)d
"
TNAME=
"
%(threadName)s
"
FILE=
"
%(pathname)s
"
LINE=
"
%(lineno)d
"
FUNC=
"
%(funcName)s
"
MSG=
"
%(message)s
"'
.
format
(
hostname
),
datefmt
=
'
%Y-%m-%dT%H:%M:%S
'
)
handler
.
setFormatter
(
formatter
)
handler
.
addFilter
(
LogSuppressErrorSpam
())
handler
.
addFilter
(
LogAnnotator
())
logger
.
addHandler
(
handler
)
return
logger
def
device_logging_to_python
():
...
...
This diff is collapsed.
Click to expand it.
devices/integration_test/base.py
+
2
−
10
View file @
69590e3e
...
...
@@ -12,17 +12,9 @@ from common.lofar_logging import configure_logger
import
unittest
import
testscenarios
# TODO(Corne): Move to separate test file, parameterize for configuration
class
TestLogger
:
"""
Ensure logger is configured only once per memory space
"""
_logger
=
None
"""
Setup logging for integration tests
"""
configure_logger
(
debug
=
True
)
def
__init__
(
self
):
if
self
.
_logger
is
None
:
self
.
_logger
=
configure_logger
()
"""
Setup logging for unit tests
"""
TestLogger
()
class
BaseIntegrationTestCase
(
testscenarios
.
WithScenarios
,
unittest
.
TestCase
):
"""
Integration test base class.
"""
...
...
This diff is collapsed.
Click to expand it.
devices/test/base.py
+
2
−
11
View file @
69590e3e
...
...
@@ -12,18 +12,9 @@ from common.lofar_logging import configure_logger
import
unittest
import
testscenarios
# TODO(Corne): Move to separate test file, parameterize for configuration
class
TestLogger
:
"""
Ensure logger is configured only once per memory space
"""
_logger
=
None
def
__init__
(
self
):
if
self
.
_logger
is
None
:
self
.
_logger
=
configure_logger
()
"""
Setup logging for unit tests
"""
TestLogger
()
configure_logger
(
debug
=
True
)
class
BaseTestCase
(
testscenarios
.
WithScenarios
,
unittest
.
TestCase
):
"""
Test base class.
"""
...
...
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