diff --git a/onionr/logger.py b/onionr/logger.py index 96d30ad1..12b61702 100644 --- a/onionr/logger.py +++ b/onionr/logger.py @@ -108,6 +108,21 @@ def get_level(): return _level +def set_file(outputfile): + ''' + Set the file to output to, if enabled + ''' + + global _outputfile + _outputfile = outputfile + +def get_file(): + ''' + Get the file to output to + ''' + + return _outputfile + def raw(data): ''' Outputs raw data to console without formatting diff --git a/onionr/onionr.py b/onionr/onionr.py index f06d1268..8591322b 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -48,9 +48,19 @@ class Onionr: # Load global configuration data exists = os.path.exists(config.get_config_file()) - config.set_config({'devmode': True}) # this is the default config, it will be overwritten if a config file already exists. Else, it saves it + config.set_config({'devmode': True, 'log.file': True, 'log.console': True, 'log.outputfile': 'data/output.log', 'log.color': True}) # this is the default config, it will be overwritten if a config file already exists. Else, it saves it config.reload() # this will read the configuration file into memory + settings = 0b000 + if config.get('log.color', True): + settings = settings | logger.USE_ANSI + if config.get('log.console', True): + settings = settings | logger.OUTPUT_TO_CONSOLE + if config.get('log.file', False): + settings = settings | logger.OUTPUT_TO_FILE + logger.set_file(config.get('log.outputfile', 'data/output.log')) + logger.set_settings(settings) + if config.get('devmode', True): self._developmentMode = True logger.set_level(logger.LEVEL_DEBUG)