Add log configuration

This commit is contained in:
Arinerron 2018-02-22 18:53:49 -08:00
parent c87bf15146
commit 39c81ae7d1
No known key found for this signature in database
GPG Key ID: 99383627861C62F0
2 changed files with 26 additions and 1 deletions

View File

@ -108,6 +108,21 @@ def get_level():
return _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): def raw(data):
''' '''
Outputs raw data to console without formatting Outputs raw data to console without formatting

View File

@ -48,9 +48,19 @@ class Onionr:
# Load global configuration data # Load global configuration data
exists = os.path.exists(config.get_config_file()) 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 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): if config.get('devmode', True):
self._developmentMode = True self._developmentMode = True
logger.set_level(logger.LEVEL_DEBUG) logger.set_level(logger.LEVEL_DEBUG)