Merge pull request #540 from ungleich/enable_logging_custom_modules

Enable logging custom modules
This commit is contained in:
Pcoder 2017-12-03 22:59:59 +01:00 committed by GitHub
commit 2d26c58f9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 23 deletions

View file

@ -573,27 +573,47 @@ if DCL_ERROR_EMAILS_TO is not None:
if 'info@ungleich.ch' not in DCL_ERROR_EMAILS_TO_LIST: if 'info@ungleich.ch' not in DCL_ERROR_EMAILS_TO_LIST:
DCL_ERROR_EMAILS_TO_LIST.append('info@ungleich.ch') DCL_ERROR_EMAILS_TO_LIST.append('info@ungleich.ch')
ENABLE_DEBUG_LOGGING = bool_env('ENABLE_DEBUG_LOGGING') ENABLE_LOGGING = bool_env('ENABLE_LOGGING')
MODULES_TO_LOG = env('MODULES_TO_LOG')
LOG_LEVEL = env('LOG_LEVEL')
if ENABLE_DEBUG_LOGGING: if LOG_LEVEL is None:
LOG_LEVEL = 'DEBUG'
if ENABLE_LOGGING:
loggers_dict = {}
handlers_dict = {}
if MODULES_TO_LOG is None:
# set MODULES_TO_LOG to django, if it is not set
MODULES_TO_LOG = 'django'
modules_to_log_list = MODULES_TO_LOG.split(',')
for custom_module in modules_to_log_list:
logger_item = {
custom_module: {
'handlers': ['custom_file'],
'level': LOG_LEVEL,
'propagate': True
}
}
loggers_dict.update(logger_item)
custom_handler_item = {
'custom_file': {
'level': LOG_LEVEL,
'class': 'logging.FileHandler',
'filename':
"{PROJECT_DIR}/{LEVEL}.log".format(
LEVEL=LOG_LEVEL.lower(),
PROJECT_DIR=PROJECT_DIR
)
}
}
handlers_dict.update(custom_handler_item)
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
'handlers': { 'handlers': handlers_dict,
'file': { 'loggers': loggers_dict
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': "{PROJECT_DIR}/debug.log".format(
PROJECT_DIR=PROJECT_DIR),
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
} }
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'],