def __init__(self, config_root): """ Prepare Python logger based on a configuration file. :param: config_root - current package to configure logger for it. """ config_file_name = TVBSettings.LOGGER_CONFIG_FILE_NAME package = __import__(config_root, globals(), locals(), ['__init__'], 0) package_path = package.__path__[0] #Specify logging configuration file for current package. if not TvbProfile.is_library_mode(): logging.config.fileConfig(os.path.join(package_path, config_file_name), disable_existing_loggers=True)
def build_logger(self, parent_module): """ Build a logger instance and return it """ self._loggers[parent_module] = logger = logging.getLogger(parent_module) return logger def set_loggers_level(self, level): for logger in self._loggers.values(): logger.setLevel(level) ### We make sure a single instance of logger-builder is created. if "GLOBAL_LOGGER_BUILDER" not in globals(): if TvbProfile.is_library_mode(): GLOBAL_LOGGER_BUILDER = LoggerBuilder('tvb.basic.logger') else: GLOBAL_LOGGER_BUILDER = LoggerBuilder('tvb.config.logger') def get_logger(parent_module=''): """ Function to retrieve a new Python logger instance for current module. :param parent_module: module name for which to create logger. """ return GLOBAL_LOGGER_BUILDER.build_logger(parent_module)
""" Return a folder, where all log files are to be stored. """ tmp_path = os.path.join(LibraryProfile.TVB_STORAGE, "logs") if not os.path.exists(tmp_path): os.makedirs(tmp_path) return tmp_path @classmethod def initialize_profile(cls): """No initialization needed for this particular profile. But useful in general""" pass ### ### Dependent of the selected profile and framework classes being present or not, load the correct configuration. ### if TvbProfile.is_library_mode(): ## TVB-Simulator-Library is used stand-alone. TVBSettings = LibraryProfile else: ## Initialization based on profile is further done in Framework. from tvb.config.settings import FrameworkSettings TVBSettings = FrameworkSettings TVBSettings.initialize_profile()