Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PySegCNN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
earth_observation_public
PySegCNN
Commits
9fd8acd9
Commit
9fd8acd9
authored
4 years ago
by
Frisinghelli Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Made logging to file optional.
parent
bc471953
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pysegcnn/core/logging.py
+40
-34
40 additions, 34 deletions
pysegcnn/core/logging.py
with
40 additions
and
34 deletions
pysegcnn/core/logging.py
+
40
−
34
View file @
9fd8acd9
...
@@ -18,8 +18,38 @@ License
...
@@ -18,8 +18,38 @@ License
import
pathlib
import
pathlib
# logging configuration dictionary
LOGGING_CONFIG
=
{
'
version
'
:
1
,
'
disable_existing_loggers
'
:
False
,
'
formatters
'
:
{
'
brief
'
:
{
'
format
'
:
'
%(name)s: %(message)s
'
},
'
standard
'
:
{
'
format
'
:
'
%(asctime)s [%(levelname)s] %(name)s: %(message)s
'
,
'
datefmt
'
:
'
%Y-%m-%dT%H:%M:%S
'
},
},
'
handlers
'
:
{
'
console
'
:
{
'
class
'
:
'
logging.StreamHandler
'
,
'
formatter
'
:
'
brief
'
,
'
level
'
:
'
INFO
'
,
'
stream
'
:
'
ext://sys.stderr
'
,
},
},
'
loggers
'
:
{
''
:
{
'
handlers
'
:
[
'
console
'
],
'
level
'
:
'
INFO
'
,
},
}
}
# the logging configuration dictionary
# the logging configuration dictionary
def
log_conf
(
logfile
):
def
log_conf
(
logfile
=
None
):
"""
Set basic logging configuration.
"""
Set basic logging configuration.
See the logging `docs`_ for a detailed description of the configuration
See the logging `docs`_ for a detailed description of the configuration
...
@@ -31,7 +61,8 @@ def log_conf(logfile):
...
@@ -31,7 +61,8 @@ def log_conf(logfile):
Parameters
Parameters
----------
----------
logfile : `str` or :py:class:`pathlib.Path`
logfile : `str` or :py:class:`pathlib.Path`
The file to save the logs to.
The file to save the logs to. The default is `None`, which means only
log to stdout and not to file.
Returns
Returns
-------
-------
...
@@ -40,44 +71,19 @@ def log_conf(logfile):
...
@@ -40,44 +71,19 @@ def log_conf(logfile):
"""
"""
# check if the parent directory of the log file exists
# check if the parent directory of the log file exists
logfile
=
pathlib
.
Path
(
logfile
)
if
logfile
is
not
None
:
if
not
logfile
.
parent
.
is_dir
():
logfile
=
pathlib
.
Path
(
logfile
)
logfile
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
if
not
logfile
.
parent
.
is_dir
():
logfile
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
LOGGING_CONFIG
=
{
'
version
'
:
1
,
'
disable_existing_loggers
'
:
False
,
'
formatters
'
:
{
'
brief
'
:
{
'
format
'
:
'
%(name)s: %(message)s
'
},
'
standard
'
:
{
'
format
'
:
'
%(asctime)s [%(levelname)s] %(name)s: %(message)s
'
,
'
datefmt
'
:
'
%Y-%m-%dT%H:%M:%S
'
},
},
'
handlers
'
:
{
'
console
'
:
{
'
class
'
:
'
logging.StreamHandler
'
,
'
formatter
'
:
'
brief
'
,
'
level
'
:
'
INFO
'
,
'
stream
'
:
'
ext://sys.stderr
'
,
},
'
file
'
:
{
# add log file to logging configuration
LOGGING_CONFIG
[
'
handlers
'
][
'
file
'
]
=
{
'
class
'
:
'
logging.FileHandler
'
,
'
class
'
:
'
logging.FileHandler
'
,
'
formatter
'
:
'
standard
'
,
'
formatter
'
:
'
standard
'
,
'
level
'
:
'
INFO
'
,
'
level
'
:
'
INFO
'
,
'
filename
'
:
logfile
,
'
filename
'
:
logfile
,
'
mode
'
:
'
a
'
'
mode
'
:
'
a
'
}
}
},
LOGGING_CONFIG
[
'
loggers
'
][
''
][
'
handlers
'
].
append
(
'
file
'
)
'
loggers
'
:
{
''
:
{
'
handlers
'
:
[
'
console
'
,
'
file
'
],
'
level
'
:
'
INFO
'
,
},
}
}
return
LOGGING_CONFIG
return
LOGGING_CONFIG
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