Skip to content

Commit

Permalink
[MetaSchedule] Allow Easy Logging Level Setting (apache#11305)
Browse files Browse the repository at this point in the history
This PR allowed users to set logging level without giving a logger config. Previous implementation hard-coded `logging.INFO` as the default logging level and requires a logger config to change it. Now the logging level and handlers can be inherited from the current `tvm.meta_schedule` logger setting.
  • Loading branch information
zxybazh authored and Yuanjing Shi committed May 17, 2022
1 parent 250882f commit 1d348e4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions python/tvm/meta_schedule/tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,23 @@ def create_loggers(
else:
config = self.logger_config

global_logger_name = "tvm.meta_schedule"
config.setdefault("loggers", {})
config.setdefault("handlers", {})
config.setdefault("formatters", {})

global_logger_name = "tvm.meta_schedule"
global_logger = logging.getLogger(global_logger_name)
if global_logger.level is logging.NOTSET:
global_logger.setLevel(logging.INFO)

config["loggers"].setdefault(
global_logger_name,
{
"level": "INFO",
"handlers": [global_logger_name + ".console", global_logger_name + ".file"],
"level": logging._levelToName[ # pylint: disable=protected-access
global_logger.level
],
"handlers": [handler.get_name() for handler in global_logger.handlers]
+ [global_logger_name + ".console", global_logger_name + ".file"],
"propagate": False,
},
)
Expand Down Expand Up @@ -502,12 +509,11 @@ def create_loggers(
logging.config.dictConfig(p_config)

# check global logger
global_logger = logging.getLogger(global_logger_name)
if global_logger.level not in [logging.DEBUG, logging.INFO]:
global_logger.critical(
global_logger.warning(
"Logging level set to %s, please set to logging.INFO"
" or logging.DEBUG to view full log.",
logging._levelToName[logger.level], # pylint: disable=protected-access
logging._levelToName[global_logger.level], # pylint: disable=protected-access
)
global_logger.info("Logging directory: %s", log_dir)

Expand Down

0 comments on commit 1d348e4

Please sign in to comment.