Пример #1
0
 def get_db(self):
     assert self.db is not None
     # Enable SQL logging with db_log.
     #
     # FIXME: Conditionalize on an is_production variable.
     show_sql = bool(self.args.get('db_log') or self.form.get('db_log'))
     if show_sql:
         g.db_log = StringIO.StringIO()
         logger = logging.getLogger("sqlalchemy")
         logger.addHandler(logging.StreamHandler(g.db_log))
     return self.db
Пример #2
0
 def get_db(self):
     assert self.db is not None
     # Enable SQL logging with db_log.
     #
     # FIXME: Conditionalize on an is_production variable.
     show_sql = bool(self.args.get('db_log') or self.form.get('db_log'))
     if show_sql:
         g.db_log = StringIO.StringIO()
         logger = logging.getLogger("sqlalchemy")
         logger.addHandler(logging.StreamHandler(g.db_log))
     return self.db
Пример #3
0
def init_logger(loglevel, show_sql=False, stream=None):
    handler = logging.StreamHandler(stream)
    handler.setLevel(loglevel)
    handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S'))
    logger.addHandler(handler)
    logger.setLevel(loglevel)

    # Enable full SQL logging, if requested.
    if show_sql:
        sa_logger = logging.getLogger("sqlalchemy")
        sa_logger.setLevel(loglevel)
        sa_logger.addHandler(handler)