text: """Copyright 2008 Orbitz WorldWide
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
     http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License."""
  
  import os
  import logging
  from logging.handlers import TimedRotatingFileHandler as Rotater
  from logging import NullHandler, FileHandler, StreamHandler
  
  import socket
  from logging.handlers import SysLogHandler
  import syslog_rfc5424_formatter
  
  from django.conf import settings
  
  
  class GraphiteLogger:
      def __init__(self):
          self.infoLogger = self._config_logger(
              settings.LOG_FILE_INFO,
              'info',
              settings.LOG_INFO_PERFORMANCE,
              level = logging.DEBUG if settings.DEBUG else logging.INFO,
          )
          self.exceptionLogger = self._config_logger(
              settings.LOG_FILE_EXCEPTION,
              'exception',
              True,
          )
          self.cacheLogger = self._config_logger(
              settings.LOG_FILE_CACHE,
              'cache',
              settings.LOG_CACHE_PERFORMANCE,
              level = logging.DEBUG if settings.DEBUG else logging.INFO,
          )
          self.renderingLogger = self._config_logger(
              settings.LOG_FILE_RENDERING,
              'rendering',
              settings.LOG_RENDERING_PERFORMANCE,
              level = logging.DEBUG if settings.DEBUG else logging.INFO,
          )
  
      @staticmethod
      def _config_logger(log_file_name, name, activate,
                         level=None, when='midnight',
                         backupCount=settings.LOG_ROTATION_COUNT):
          logger = logging.getLogger(name)
          if level is not None:
              logger.setLevel(level)
          if activate:  # if want to log this one
              if 'LOG_DGRAM_SYSLOG' in os.environ:
                  address = os.environ.get('LOG_DGRAM_SYSLOG')
                  socktype = socket.SOCK_DGRAM
                  handler = SysLogHandler(address, facility=SysLogHandler.LOG_DAEMON, socktype=socktype)
                  formatter = syslog_rfc5424_formatter.RFC5424Formatter('%(message)s')
              elif log_file_name == '-':
                  formatter = logging.Formatter(
                      fmt='[%(asctime)s.%(msecs)03d] %(name)s %(levelname)s %(message)s',
                      datefmt='%d/%b/%Y %H:%M:%S')
                  handler = StreamHandler()
              handler.setFormatter(formatter)
              logger.addHandler(handler)
          else:
              logger.addHandler(NullHandler())
          return logger
  
      def info(self,msg,*args,**kwargs):
          return self.infoLogger.info(msg,*args,**kwargs)
  
      def debug(self,msg,*args,**kwargs):
          return self.infoLogger.debug(msg,*args,**kwargs)
  
      def warning(self,msg,*args,**kwargs):
          return self.infoLogger.warn(msg,*args,**kwargs)
  
      def exception(self,msg="Exception Caught",**kwargs):
          return self.exceptionLogger.exception(msg,**kwargs)
  
      def cache(self,msg,*args,**kwargs):
          return self.cacheLogger.info(msg,*args,**kwargs)
  
      def rendering(self,msg,*args,**kwargs):
          return self.renderingLogger.info(msg,*args,**kwargs)
  
  
  log = GraphiteLogger() # import-shared logger instance
  