update default logger (#100) (#101)

pull/111/head
ver217 2022-01-04 20:03:26 +08:00 committed by GitHub
parent 96780e6ee4
commit a951bc6089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import inspect
import sys import sys
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader
from pathlib import Path from pathlib import Path
from colossalai.logging import get_dist_logger
class Config(dict): class Config(dict):
@ -88,8 +89,8 @@ class Config(dict):
else: else:
config._add_item(k, v) config._add_item(k, v)
# TODO: replace with logger warning here when logger is done logger = get_dist_logger()
print('warning: variables which starts with __, is a module or class declaration are omitted') logger.debug('variables which starts with __, is a module or class declaration are omitted in config file')
# remove module # remove module
del sys.modules[module_name] del sys.modules[module_name]

View File

@ -1,9 +1,11 @@
from typing import List
from .logging import DistributedLogger from .logging import DistributedLogger
import logging
__all__ = ['get_dist_logger', 'DistributedLogger'] __all__ = ['get_dist_logger', 'DistributedLogger']
def get_dist_logger(name='root'): def get_dist_logger(name='colossalai'):
"""Get logger instance based on name. The DistributedLogger will create singleton instances, """Get logger instance based on name. The DistributedLogger will create singleton instances,
which means that only one logger instance is created per name. which means that only one logger instance is created per name.
@ -14,3 +16,14 @@ def get_dist_logger(name='root'):
:rtype: :class:`colossalai.logging.DistributedLogger` :rtype: :class:`colossalai.logging.DistributedLogger`
""" """
return DistributedLogger.get_instance(name=name) return DistributedLogger.get_instance(name=name)
def disable_existing_loggers(except_loggers: List[str] = ['colossalai']):
"""Set the level of existing loggers to `WARNING`.
:param except_loggers: loggers in this `list` will be ignored when disabling, defaults to ['colossalai']
:type except_loggers: list, optional
"""
for log_name in logging.Logger.manager.loggerDict.keys():
if log_name not in except_loggers:
logging.getLogger(log_name).setLevel(logging.WARNING)