Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
6b8d9e80
Commit
6b8d9e80
authored
Dec 15, 2023
by
BO ZHANG
🏀
Browse files
add tests for logger
parent
7eb6a5ba
Pipeline
#2428
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_common/logger.py
View file @
6b8d9e80
...
...
@@ -16,7 +16,7 @@ from typing import Optional
def
get_logger
(
name
:
str
=
"CSST pipeline"
,
filename
:
Optional
[
str
]
=
None
):
"""
Get a
logger for CSST pipelines
.
Get a
CSST starndard logger
.
Messages with levels >= DEBUG will be output by stream.
Messages with levels >= INFO will be recorded by a log file.
...
...
@@ -68,16 +68,3 @@ def get_logger(name: str = "CSST pipeline", filename: Optional[str] = None):
logger
.
addHandler
(
file_handler
)
return
logger
if
__name__
==
"__main__"
:
import
os
print
(
os
.
getcwd
())
logger
=
get_logger
(
filename
=
"test_logger.log"
)
print
(
"Type of logger:"
,
type
(
logger
))
print
(
"Name of logger:"
,
logger
.
name
)
logger
.
debug
(
"Well .."
)
logger
.
info
(
"Hello ..."
)
logger
.
warning
(
"There ..."
)
logger
.
error
(
"Good morning ..."
)
tests/test_logger.py
0 → 100644
View file @
6b8d9e80
"""
Identifier: tests/test_logger.py
Name: test_logger.py
Description: test logger
Author: Bo Zhang
Created: 2023-12-15
Modified-History:
2023-12-15, Bo Zhang, add TestLogger
"""
import
os
import
unittest
from
csst_common.logger
import
get_logger
class
TestFile
(
unittest
.
TestCase
):
def
test_file
(
self
):
logger
=
get_logger
(
filename
=
"test_logger.log"
)
print
(
os
.
getcwd
())
print
(
"Type of logger:"
,
type
(
logger
))
print
(
"Name of logger:"
,
logger
.
name
)
logger
.
debug
(
"Well .."
)
logger
.
info
(
"Hello ..."
)
logger
.
warning
(
"There ..."
)
logger
.
error
(
"Good morning ..."
)
with
open
(
"test_logger.log"
,
"r"
)
as
f
:
lines
=
f
.
readlines
()
self
.
assertTrue
(
lines
[
0
].
endswith
(
"Hello ..."
))
self
.
assertTrue
(
lines
[
1
].
endswith
(
"There ..."
))
self
.
assertTrue
(
lines
[
2
].
endswith
(
"Good morning ..."
))
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment