Created
August 1, 2012 23:16
-
-
Save jmatt/3231478 to your computer and use it in GitHub Desktop.
Logging for Atmosphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Logging for atmosphere. | |
| Provides two separate log levels. One for dependencies and one for the application. | |
| django's settings.py: | |
| ## logging imports | |
| import logging | |
| import atmosphere.logger | |
| ## logging | |
| DEBUG = True | |
| TEMPLATE_DEBUG = DEBUG | |
| LOGGING_LEVEL = logging.DEBUG | |
| DEP_LOGGING_LEVEL = logging.WARN#Logging level for dependencies. | |
| atmosphere.logger.initialize(LOGGING_LEVEL, DEP_LOGGING_LEVEL) | |
| ## use | |
| from atmosphere.logger import logger | |
| ... | |
| logger.debug('debugorz') | |
| logger.info('infoz') | |
| """ | |
| from __future__ import absolute_import | |
| import atmosphere | |
| import logging | |
| import os.path | |
| logger = None | |
| def logger_initialize(logger): | |
| """ | |
| Customize the application logger. | |
| Examples of customization: Set formatter or change, add, remove handlers. | |
| """ | |
| pass | |
| def initialize(app_log_level, dep_log_level): | |
| """ | |
| Initialize the root and application logger. | |
| """ | |
| format = "%(asctime)s %(name)s-%(levelname)s [%(pathname)s %(funcName)s %(lineno)d] %(message)s" | |
| formatter = logging.Formatter(format) | |
| log_file = os.path.abspath(os.path.join( | |
| os.path.dirname(atmosphere.__file__), | |
| 'logs/atmosphere.log')) | |
| # Setup the root logging for dependencies, etc. | |
| logging.basicConfig( | |
| level = dep_log_level, | |
| format = format, | |
| filename = log_file, | |
| filemode = 'a+') | |
| # Setup and add separate application logging. | |
| global logger | |
| logger = logging.getLogger('atmosphere') | |
| logger_initialize(logger) | |
| logger.setLevel(app_log_level) # required to get level to apply. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment