def log_sql(cur, sql, params=None, level=logging.INFO): db = cur._get_db() msg_tpl = '[SQL]: {}' if params is None: msg = msg_tpl.format(sql) else: if not isinstance(params, (list, tuple, dict)): params = (params, ) msg = msg_tpl.format(sql % tuple(map(db.literal, params))) logger.log(msg=msg, level=level)
def log(self, sql, params=None, level=logging.INFO): db = self._get_db() literal = sql_literal_factory(db) msg_tpl = '[SQL]: {}' if params is None: msg = msg_tpl.format(sql) else: if not isinstance(params, (list, tuple, dict)): params = (params, ) msg = msg_tpl.format(sql % tuple(map(literal, params))) logger.log(msg=msg, level=level)
def beansdb_log(self, cmd, args, kwargs, level=logging.INFO): if not self.enable_log: return def mapper(x): if isinstance(x, str_types): return x try: return json.dumps(x) except Exception: return '<UNKNOWN>' msg = '[BEANSDB]: {} {}'.format(cmd, ' '.join(map(mapper, args))) logger.log(msg=msg, level=level)
def beansdb_log(self, cmd, args, kwargs, level=logging.INFO): if not self.enable_log: return def mapper(x): if isinstance(x, basestring): return x try: return json.dumps(x) except Exception: return '<UNKOWN>' try: msg = '[BEANSDB]: {} {}'.format(cmd, ' '.join(map(mapper, args))) logger.log(msg=msg, level=level) except Exception: # pragma: no cover pass # pragma: no cover
def log(self, sql: str, params: Optional[Tuple] = None, level: int = logging.INFO) -> None: logger.log(msg=self.mogrify(sql, params).decode('utf8'), level=level)