Fixed the logging by overriding the root logger

This commit is contained in:
Anton Beloglazov 2012-09-28 11:31:13 +10:00
parent bf075744aa
commit 48f090ff42
3 changed files with 19 additions and 4 deletions

View File

@ -172,8 +172,16 @@ def init_logging(log_directory, log_file, log_level):
else:
level = logging.WARNING
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(name)s %(message)s',
filename=os.path.join(log_directory, log_file),
level=level)
logger = logging.root
logger.handlers = []
logger.filters = []
logger.setLevel(level)
handler = logging.FileHandler(
os.path.join(log_directory, log_file))
handler.setFormatter(
logging.Formatter(
'%(asctime)s %(levelname)-8s %(name)s %(message)s'))
logger.addHandler(handler)
return True

View File

@ -115,6 +115,11 @@ def start():
config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
REQUIRED_FIELDS)
common.init_logging(
config['log_directory'],
'collector.log',
int(config['log_level']))
vm_path = common.build_local_vm_path(config.get('local_data_directory'))
if not os.access(vm_path, os.F_OK):
os.makedirs(vm_path)

View File

@ -1,6 +1,8 @@
#!/usr/bin/python
import neat.locals.collector as collector
print 'Starting the data collector'
collector.start()