HowTo: Change Log Defaults In CloudBolt

CloudBolt uses the native Logging facility for python. The documentation for this module is located at: https://docs.python.org/2/library/logging.html.

You'll see from this documentation that it's a hierarchical module-based logging system that allows you to not only control what classes are logged to what handlers, but also their log level.

To start overriding the default Logging configuration for CloudBolt, copy the LOGGING definition from /opt/cloudbolt/settings.py (approx lines 513 to 588) to /var/opt/cloudbolt/proserv/customer_settings.py. Here's an example that you could copy into customer_settings.py that also removes a few variables:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'logfile': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': logfile,
            'maxBytes': 1024 * 1024 * 5,  # 5 MB
            'backupCount': 5,
            'formatter': 'standard',
        },
        'jobengine_logfile': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': jobengine_logfile,
            'maxBytes': 1024 * 1024 * 5,  # 5 MB
            'backupCount': 5,
            'formatter': 'standard',
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'standard'
        }
    },
    'loggers': {
        '': {
            'handlers': default_handlers,
            'level': 'INFO',
            'propagate': True
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        'standard': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
        # We set the DB log messages to level ERROR, otherwise the logs
        # get a ton of DEBUG SQL dumped into them
        'django.db.backends': {
            'handlers': [],
            'level': 'ERROR',
            'propagate': True,
        },
        'jobengine': {
            'handlers': jobengine_handlers,
            'level': 'INFO',
            'propagate': False,
        },
        # Logger for individual jobs
        'jobengine.job': {
            'handlers': [],   # Must be populated uniquely, per job
            'level': 'INFO',
            'propagate': False,
        },
        'ase_sa_common': {
            'handlers': non_console_handlers,
            'level': 'INFO',
            'propagate': False,
        }
    }
}

 

For a real-world example, the following customer_settings.py file redirects all logging to syslogd in addition to the default locations::

from settings import LOGGING

# Logging overrides
LOGGING['handlers']['syslogger'] = {
    'class': 'logging.handlers.SysLogHandler',
    'level': 'DEBUG',
    'formatter': 'standard',
}
LOGGING['loggers']['']['handlers'].append('syslogger')
utilities_models_logger = {
    'handlers': LOGGING['loggers']['']['handlers'],
    'level': 'ERROR',
    'propagate': True,
}
LOGGING['loggers']['utilities.models'] = utilities_models_logger

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.