Enable logging custom modules

This commit is contained in:
M.Ravi 2017-11-29 06:45:09 +01:00
parent 35d6c90b14
commit 137b45c12c
2 changed files with 65 additions and 19 deletions

View file

@ -575,25 +575,69 @@ if 'info@ungleich.ch' not in DCL_ERROR_EMAILS_TO_LIST:
ENABLE_DEBUG_LOGGING = bool_env('ENABLE_DEBUG_LOGGING') ENABLE_DEBUG_LOGGING = bool_env('ENABLE_DEBUG_LOGGING')
if ENABLE_DEBUG_LOGGING: loggers_dict = {
LOGGING = { 'django': {
'version': 1, 'handlers': ['file'],
'disable_existing_loggers': False, 'level': 'DEBUG',
'handlers': { 'propagate': True,
},
}
handlers_dict = {
'file': { 'file': {
'level': 'DEBUG', 'level': 'DEBUG',
'class': 'logging.FileHandler', 'class': 'logging.FileHandler',
'filename': "{PROJECT_DIR}/debug.log".format( 'filename': "{PROJECT_DIR}/debug.log".format(
PROJECT_DIR=PROJECT_DIR), PROJECT_DIR=PROJECT_DIR),
}, },
}, }
'loggers': {
'django': { MODULES_TO_LOG = env('MODULES_TO_LOG')
'handlers': ['file'], MODULES_TO_LOG_LEVEL = env('MODULES_TO_LOG_LEVEL')
'level': 'DEBUG',
'propagate': True, if MODULES_TO_LOG_LEVEL is None:
}, MODULES_TO_LOG_LEVEL = 'DEBUG'
},
if MODULES_TO_LOG:
if ',' in MODULES_TO_LOG:
modules_to_log_list = MODULES_TO_LOG.split(',')
for custom_module in modules_to_log_list:
logger_item = {
custom_module: {
'handlers': ['custom_file'],
'level': MODULES_TO_LOG_LEVEL,
'propagate': True
}
}
loggers_dict.update(logger_item)
else:
logger_item = {
MODULES_TO_LOG: {
'handlers': ['custom_file'],
'level': MODULES_TO_LOG_LEVEL,
'propagate': True
}
}
loggers_dict.update(logger_item)
custom_handler_item = {
'custom_file': {
'level': MODULES_TO_LOG_LEVEL,
'class': 'logging.FileHandler',
'filename':
"{PROJECT_DIR}/custom_{LEVEL}.log".format(
LEVEL=MODULES_TO_LOG_LEVEL.lower(),
PROJECT_DIR=PROJECT_DIR
)
}
}
handlers_dict.update(custom_handler_item)
if ENABLE_DEBUG_LOGGING:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': handlers_dict,
'loggers': loggers_dict
} }
TEST_MANAGE_SSH_KEY_PUBKEY = env('TEST_MANAGE_SSH_KEY_PUBKEY') TEST_MANAGE_SSH_KEY_PUBKEY = env('TEST_MANAGE_SSH_KEY_PUBKEY')

View file

@ -301,12 +301,14 @@ class OpenNebulaManager():
</CONTEXT> </CONTEXT>
</TEMPLATE> </TEMPLATE>
""" """
vm_id = self.client.call(oca.VmTemplate.METHODS['instantiate'], try:
template.id, vm_id = self.client.call(
'', oca.VmTemplate.METHODS['instantiate'], template.id, '', True,
True, vm_specs, False
vm_specs, )
False) except OpenNebulaException as err:
logger.error("OpenNebulaException: {0}".format(err))
return None
self.oneadmin_client.call( self.oneadmin_client.call(
oca.VirtualMachine.METHODS['action'], oca.VirtualMachine.METHODS['action'],