Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ChIA-PET_network
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
LBMC
ReGArDS
ChIA-PET_network
Commits
5d29bfa7
Commit
5d29bfa7
authored
5 years ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/logging_conf.py: script containing functions and variables to handle log messages
parent
ab2a3eda
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/logging_conf.py
+40
-0
40 additions, 0 deletions
src/logging_conf.py
with
40 additions
and
0 deletions
src/logging_conf.py
+
40
−
0
View file @
5d29bfa7
...
...
@@ -7,6 +7,45 @@ Description: this file contains a dictionary that allows to \
configure the logging module of python
"""
from
typing
import
Dict
,
Any
from
pathlib
import
Path
import
logging
import
logging.config
import
coloredlogs
class
LoggingLevelError
(
Exception
):
pass
def
logging_def
(
output
:
Path
,
script
:
str
,
level
:
str
=
"
INFO
"
):
"""
Define a logging at the current level of the script
:param output: Folder where the result will be created
:param script: The name of the script
:param level: The log level
"""
possible_levels
=
[
"
INFO
"
,
"
DEBUG
"
,
"
ERROR
"
,
"
WARNING
"
,
"
CRITICAL
"
]
if
level
in
possible_levels
:
basename
=
str
(
Path
(
script
).
name
).
replace
(
"
.py
"
,
"
.log
"
)
LOGGING_CONFIG
[
"
handlers
"
][
"
file
"
][
"
filename
"
]
=
output
/
basename
LOGGING_CONFIG
[
"
loggers
"
][
""
][
"
level
"
]
=
level
logging
.
config
.
dictConfig
(
LOGGING_CONFIG
)
elif
level
!=
"
DISABLE
"
:
raise
LoggingLevelError
(
f
"
Logging level unknown : choose from
"
f
"
{
possible_levels
}
or DISABLE to disable the
"
f
"
initialisation of logging in
{
__file__
}
"
)
coloredlogs
.
DEFAULT_LEVEL_STYLES
=
{
'
critical
'
:
{
'
color
'
:
'
red
'
,
'
bold
'
:
True
},
'
debug
'
:
{
'
color
'
:
'
cyan
'
,
'
italic
'
:
True
,
'
bold
'
:
True
},
'
error
'
:
{
'
color
'
:
'
red
'
,
'
bold
'
:
True
},
'
info
'
:
{},
'
warning
'
:
{
'
color
'
:
'
yellow
'
,
'
bold
'
:
True
}}
LOGGING_CONFIG
=
{
'
version
'
:
1
,
'
disable_existing_loggers
'
:
True
,
...
...
@@ -16,6 +55,7 @@ LOGGING_CONFIG = {
'
levelname)s - %(message)s
'
},
"
simple
"
:
{
'
()
'
:
'
coloredlogs.ColoredFormatter
'
,
'
format
'
:
'
%(message)s
'
}
},
...
...
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