Exemple #1
0
    def register_loggers(self, app):
        if not app.debug:
            lf = LoggerFactory(app)

            if app.config['LOG_FILE']:
                if not os.path.exists(os.path.dirname(app.config['LOG_FILENAME'])):
                    try:
                        print('Creating file {0}'.format(app.config['LOG_FILENAME']))
                        os.makedirs(os.path.dirname(app.config['LOG_FILENAME']))
                    except OSError as exc:
                        if exc.errno != errno.EEXIST:
                            raise
                lf.add_logger(app.logger, logging.handlers.RotatingFileHandler)

            if app.config['LOG_ADDRESS']:
                lf.add_logger(app.logger, logging.handlers.SysLogHandler)

            if app.config['LOG_STDOUT']:
                lf.add_logger(app.logger, logging.StreamHandler)

            lf.add_logger(app.logger, logging.handlers.SMTPHandler, level=logging.ERROR)

            lf.add_request_logger(app)

            app.logger.setLevel(logging.INFO)
            lf.add_context_filter(app.logger)

            app.logger.info(u'{0} startup'.format(app.config['PROJECT_NAME']))
Exemple #2
0
    def register_loggers(self, app):
        lf = LoggerFactory(app)

        lf.add_logger(app.logger, logging.StreamHandler)
        lf.add_request_logger(app)
        app.logger.setLevel(logging.INFO)
        lf.add_context_filter(app.logger)

        feed_logger = logging.getLogger('feedfinder3')
        feed_logger.setLevel(logging.DEBUG)

        import sys
        handler = logging.StreamHandler(sys.stdout)
        handler._name = 'StreamHandler'
        handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s %(name)s %(message)s'))
        feed_logger.addHandler(handler)
        app.logger.info(u'{0} startup'.format(app.config['PROJECT_NAME']))