1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
from logging import ERROR, INFO, DEBUG, WARNING, CRITICAL
try:
from ._utils import _log_to_postgres
from ._utils import check_interrupts
except ImportError as e:
from warnings import warn
warn("Not executed in a postgresql server,"
" disabling log_to_postgres", ImportWarning)
def _log_to_postgres(message, level=0, hint=None, detail=None):
pass
REPORT_CODES = {
DEBUG: 0,
INFO: 1,
WARNING: 2,
ERROR: 3,
CRITICAL: 4
}
def log_to_postgres(message, level=INFO, hint=None, detail=None):
code = REPORT_CODES.get(level, None)
if code is None:
raise KeyError("Not a valid log level")
_log_to_postgres(message, code, hint=hint, detail=detail)
|