Refined utils.log.log() to flush stdout before logging if we're writing log messages to stderr.

- Legacy-Id: 15463
This commit is contained in:
Henrik Levkowetz 2018-09-16 14:14:26 +00:00
parent debaf83ba2
commit a389e24fb6

View file

@ -36,10 +36,14 @@ def getcaller():
def log(msg):
"Uses syslog by preference. Logs the given calling point and message."
global logfunc
def _flushfunc():
pass
_logfunc = logfunc
if settings.SERVER_MODE == 'test':
return
elif settings.DEBUG == True:
logfunc = debug.say
_logfunc = debug.say
_flushfunc = sys.stdout.flush
if isinstance(msg, unicode):
msg = msg.encode('unicode_escape')
try:
@ -52,7 +56,8 @@ def log(msg):
where = " in " + func + "()"
except IndexError:
file, line, where = "/<UNKNOWN>", 0, ""
logfunc("ietf%s(%d)%s: %s" % (file, line, where, msg))
_flushfunc()
_logfunc("ietf%s(%d)%s: %s" % (file, line, where, msg))
logger = logging.getLogger('django')