2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 19:10:10 +00:00

Merge pull request #69 from jjohnson42/unbufferedlogs

Change the stdout/stderr/trace logs to not buffer things over time
This commit is contained in:
chenglch 2017-04-12 10:38:19 +08:00 committed by GitHub
commit d4329ab0f1
2 changed files with 11 additions and 7 deletions

View File

@ -494,7 +494,7 @@ class Logger(object):
False, events will be formatted like syslog:
date: message<CR>
"""
def __new__(cls, logname, console=False, tenant=None):
def __new__(cls, logname, console=False, tenant=None, buffered=True):
global _loggers
if console:
relpath = 'consoles/' + logname
@ -505,11 +505,12 @@ class Logger(object):
else:
return object.__new__(cls)
def __init__(self, logname, console=False, tenant=None):
def __init__(self, logname, console=False, tenant=None, buffered=True):
if hasattr(self, 'initialized'):
# we are just a copy of the same object
return
self.initialized = True
self.buffered = buffered
self.filepath = confluent.config.configmanager.get_global("logdirectory")
if self.filepath is None:
if os.name == 'nt':
@ -727,8 +728,11 @@ class Logger(object):
else:
self.logentries.append(
[ltype, timestamp, logdata, event, eventdata])
if self.writer is None:
self.writer = eventlet.spawn_after(2, self.writedata)
if self.buffered:
if self.writer is None:
self.writer = eventlet.spawn_after(2, self.writedata)
else:
self.writedata()
def closelog(self):
self.handler.close()
@ -746,6 +750,6 @@ def log(logdata=None, ltype=None, event=0, eventdata=None):
def logtrace():
global tracelog
if tracelog is None:
tracelog = Logger('trace')
tracelog = Logger('trace', buffered=False)
tracelog.log(traceback.format_exc(), ltype=DataTypes.event,
event=Events.stacktrace)

View File

@ -77,8 +77,8 @@ def _daemonize():
os.open(os.devnull, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
sys.stdout = log.Logger('stdout')
sys.stderr = log.Logger('stderr')
sys.stdout = log.Logger('stdout', buffered=False)
sys.stderr = log.Logger('stderr', buffered=False)
def _updatepidfile():