Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
cf2f14d0
Unverified
Commit
cf2f14d0
authored
Feb 02, 2021
by
Rui Xu
Committed by
GitHub
Feb 02, 2021
Browse files
[Feature] Add file mode for logger (#808)
* add file mode for logger * add more docs and comments
parent
93980b4b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
mmcv/utils/logging.py
mmcv/utils/logging.py
+7
-2
No files found.
mmcv/utils/logging.py
View file @
cf2f14d0
...
...
@@ -5,7 +5,7 @@ import torch.distributed as dist
logger_initialized
=
{}
def
get_logger
(
name
,
log_file
=
None
,
log_level
=
logging
.
INFO
):
def
get_logger
(
name
,
log_file
=
None
,
log_level
=
logging
.
INFO
,
file_mode
=
'w'
):
"""Initialize and get a logger by name.
If the logger has not been initialized, this method will initialize the
...
...
@@ -21,6 +21,8 @@ def get_logger(name, log_file=None, log_level=logging.INFO):
log_level (int): The logger level. Note that only the process of
rank 0 is affected, and other processes will set the level to
"Error" thus be silent most of the time.
file_mode (str): The file mode used in opening log file.
Defaults to 'w'.
Returns:
logging.Logger: The expected logger.
...
...
@@ -45,7 +47,10 @@ def get_logger(name, log_file=None, log_level=logging.INFO):
# only rank 0 will add a FileHandler
if
rank
==
0
and
log_file
is
not
None
:
file_handler
=
logging
.
FileHandler
(
log_file
,
'w'
)
# Here, the default behaviour of the official logger is 'a'. Thus, we
# provide an interface to change the file mode to the default
# behaviour.
file_handler
=
logging
.
FileHandler
(
log_file
,
file_mode
)
handlers
.
append
(
file_handler
)
formatter
=
logging
.
Formatter
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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