Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refine] Dump all level logging messages to the log file. #434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mmengine/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def __init__(self,
# without color to avoid garbled code saved in files.
file_handler.setFormatter(
MMFormatter(color=False, datefmt='%Y/%m/%d %H:%M:%S'))
file_handler.setLevel(log_level)
self.handlers.append(file_handler)

@classmethod
Expand Down
27 changes: 8 additions & 19 deletions mmengine/model/base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import warnings
from abc import ABCMeta
from collections import defaultdict
from logging import FileHandler
from typing import Iterable, Optional

import torch.nn as nn
Expand Down Expand Up @@ -142,24 +141,14 @@ def _dump_init_info(self):

logger = MMLogger.get_current_instance()
logger_name = logger.instance_name
with_file_handler = False
# dump the information to the logger file if there is a `FileHandler`
for handler in logger.handlers:
if isinstance(handler, FileHandler):
handler.stream.write(
'Name of parameter - Initialization information\n')
for name, param in self.named_parameters():
handler.stream.write(
f'\n{name} - {param.shape}: '
f"\n{self._params_init_info[param]['init_info']} \n")
handler.stream.flush()
with_file_handler = True
if not with_file_handler:
for name, param in self.named_parameters():
print_log(
f'\n{name} - {param.shape}: '
f"\n{self._params_init_info[param]['init_info']} \n ",
logger=logger_name)

# dump the information to the logger file.
for name, param in self.named_parameters():
print_log(
f'\n{name} - {param.shape}: '
f"\n{self._params_init_info[param]['init_info']} \n ",
logger=logger_name,
level=logging.DEBUG)
Comment on lines +145 to +151
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to check whether the message will fill the whole terminal if debug is set and whether this will make users unhappy.

Copy link
Collaborator Author

@HAOCHENYE HAOCHENYE Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all level messages will be dumped to the log file, users can check the debug information in the saved file, I think only the advanced terminal user will set the log_level to debug, to see search the debug information in the terminal.


def __repr__(self):
s = super().__repr__()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_logging/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_init_rank1(self, tmp_path):
log_file=str(tmp_file),
distributed=True)
assert logger.handlers[0].level == logging.ERROR
assert logger.handlers[1].level == logging.INFO
assert logger.handlers[1].level == logging.NOTSET
assert len(logger.handlers) == 2
assert os.path.exists(log_path)
logging.shutdown()
Expand Down