Skip to content

Instantly share code, notes, and snippets.

@photofroggy
Created November 7, 2011 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save photofroggy/1343853 to your computer and use it in GitHub Desktop.
Save photofroggy/1343853 to your computer and use it in GitHub Desktop.
BufferedLogger.push method
def push(self, limit=None):
""" Push some queued items out of the queue.
This method causes queued items to be written to be saved to a file.
Only `limit` items will be pushed out of the queue. If `limit` is
`0`, then all items will be pushed from the queue.
"""
if limit is None:
limit = self.default_push
if limit < 0:
return
if self.queue.empty():
return
sdata = {}
iter = 0
# First we sort the data we want into lists of messages that will be
# saved in the same file. This way we don't have to keep opening and
# closing files.
while not self.queue.empty():
item = self.queue.get()
fname = self._fname(item[3], **item[4])
try:
sdata[fname].append(item)
except KeyError:
sdata[fname] = []
sdata[fname].append(item)
iter+= 1
if limit == iter:
break
# The following two lines make the above loop pointless save for the
# purpose of syphoning the queue.
if not self.save_logs:
return
for fname in sdata:
self._save(fname, sdata[fname])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment