utilities into separate files. * Added a log() function in ietf/utils. It uses syslog, but adds some information about where it was called from. - Legacy-Id: 130
33 lines
920 B
Python
33 lines
920 B
Python
import syslog
|
|
import inspect
|
|
import os.path
|
|
import ietf
|
|
from settings import BASE_DIR
|
|
|
|
syslog.openlog("django", syslog.LOG_PID, syslog.LOG_USER)
|
|
|
|
def getclass(frame):
|
|
cls = None
|
|
argnames, varargs, varkw, defaults = inspect.getargvalues(frame)
|
|
if len(argnames) > 0:
|
|
selfname = argnames[0]
|
|
cls = defaults[selfname].__class__
|
|
return cls
|
|
|
|
def getcaller():
|
|
parent, pfile, pline, pfunction, lines, index = inspect.stack()[2]
|
|
pmodule = inspect.getmoduleinfo(pfile)[0]
|
|
pclass = getclass(parent)
|
|
return (pmodule, pclass, pfunction, pfile, pline)
|
|
|
|
def log(msg):
|
|
mod, cls, func, file, line = getcaller()
|
|
file = os.path.abspath(file)
|
|
file = file.replace(BASE_DIR, "")
|
|
if func == "<module>":
|
|
where = ""
|
|
else:
|
|
where = " in " + func + "()"
|
|
syslog.syslog("ietf%s(%d)%s: %s" % (file, line, where, msg))
|
|
|
|
log("IETFdb v%s started" % ietf.__version__) |