Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
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
QIM
Tools
qim3d
Commits
90610bb2
Commit
90610bb2
authored
May 26, 2023
by
Felipe Delestro Matos
Browse files
Options
Downloads
Patches
Plain Diff
Logger module docstrings
parent
77abd118
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/io/logger.py
+71
-22
71 additions, 22 deletions
qim3d/io/logger.py
with
71 additions
and
22 deletions
qim3d/io/logger.py
+
71
−
22
View file @
90610bb2
"""
Logging configuration.
"""
import
logging
def
set_detailed_output
():
"""
Configures the logging output to display detailed information.
This function sets up a logging formatter with a specific format that
includes the log level, filename, line number, and log message.
Example:
>>>
set_detailed_output
()
"""
formatter
=
logging
.
Formatter
(
"
%(levelname)-10s%(filename)s:%(lineno)-5s%(message)s
"
)
...
...
@@ -13,6 +24,15 @@ def set_detailed_output():
def
set_simple_output
():
"""
Configures the logging output to display simple messages.
This function sets up a logging formatter with a format that includes only
the log message.
Example:
>>>
set_simple_output
()
"""
formatter
=
logging
.
Formatter
(
"
%(message)s
"
)
handler
=
logging
.
StreamHandler
()
handler
.
setFormatter
(
formatter
)
...
...
@@ -21,67 +41,96 @@ def set_simple_output():
logger
.
addHandler
(
handler
)
def
set_level_DEBUG
():
def
set_level_debug
():
"""
Sets the logging level of the
"
qim3d
"
logger to DEBUG.
Example:
>>>
set_level_debug
()
"""
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
logging
.
DEBUG
)
def
set_level_INFO
():
def
set_level_info
():
"""
Sets the logging level of the
"
qim3d
"
logger to INFO.
Example:
>>>
set_level_info
()
"""
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
logging
.
INFO
)
def
set_level_WARNING
():
def
set_level_warning
():
"""
Sets the logging level of the
"
qim3d
"
logger to WARNING.
Example:
>>>
set_level_warning
()
"""
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
logging
.
WARNING
)
def
set_level_ERROR
():
def
set_level_error
():
"""
Sets the logging level of the
"
qim3d
"
logger to ERROR.
Example:
>>>
set_level_error
()
"""
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
logging
.
ERROR
)
def
set_level_CRITICAL
():
def
set_level_critical
():
"""
Sets the logging level of the
"
qim3d
"
logger to CRITICAL.
Example:
>>>
set_level_critical
()
"""
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
logging
.
CRITICAL
)
def
level
(
level
):
def
level
(
log_
level
):
"""
Set the logging level based on the specified level.
Args:
level (str or int): The logging level to set. It can be one of
the following
:
log_
level (str or int): The logging level to set. It can be one of:
-
"
DEBUG
"
or
"
debug
"
: Set the logging level to DEBUG.
-
"
INFO
"
or
"
info
"
: Set the logging level to INFO.
-
"
WARNING
"
or
"
warning
"
: Set the logging level to WARNING.
-
"
ERROR
"
or
"
error
"
: Set the logging level to ERROR.
-
"
CRITICAL
"
or
"
critical
"
: Set the logging level to CRITICAL.
- int: Set
the logging level using the
numeric value
of the level
(e.g., logging.DEBUG).
- int: Set
level to
numeric value (e.g., logging.DEBUG).
Raises:
ValueError: If the specified level is not a valid logging level.
"""
if
level
in
[
"
DEBUG
"
,
"
debug
"
]:
set_level_
DEBUG
()
if
log_
level
in
[
"
DEBUG
"
,
"
debug
"
]:
set_level_
debug
()
elif
level
in
[
"
INFO
"
,
"
info
"
]:
set_level_
INFO
()
elif
log_
level
in
[
"
INFO
"
,
"
info
"
]:
set_level_
info
()
elif
level
in
[
"
WARNING
"
,
"
warning
"
]:
set_level_
WARNING
()
elif
log_
level
in
[
"
WARNING
"
,
"
warning
"
]:
set_level_
warning
()
elif
level
in
[
"
ERROR
"
,
"
error
"
]:
set_level_
ERROR
()
elif
log_
level
in
[
"
ERROR
"
,
"
error
"
]:
set_level_
error
()
elif
level
in
[
"
CRITICAL
"
,
"
critical
"
]:
set_level_
CRITICAL
()
elif
log_
level
in
[
"
CRITICAL
"
,
"
critical
"
]:
set_level_
critical
()
elif
isinstance
(
level
,
int
):
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
level
)
elif
isinstance
(
log_
level
,
int
):
logging
.
getLogger
(
"
qim3d
"
).
setLevel
(
log_
level
)
else
:
raise
ValueError
(
f
"
Invalid logging level:
'
{
level
}
'
.
\n
Please use
'
debug
'
,
'
info
'
,
'
warning
'
,
'
error
'
,
'
critical
'
or an int.
"
f
"
Invalid logging level:
'
{
log_level
}
'
. Please use
"
"'
debug
'
,
'
info
'
,
'
warning
'
,
'
error
'
,
'
critical
'
or an int.
"
)
# create the logger
log
=
logging
.
getLogger
(
"
qim3d
"
)
set_simple_output
()
set_level_
WARNING
()
set_level_
warning
()
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