Log events to a file named after today's date

We need this so that we can safely expunge old events without interfering with
the running server.  See #414.

(imported from commit 4739e59e36ea69f877c158c13ee752bf6a2dacfe)
This commit is contained in:
Keegan McAllister
2013-01-14 14:09:25 -05:00
parent 3a127871f0
commit b5a0147e26
5 changed files with 24 additions and 7 deletions

View File

@@ -21,13 +21,25 @@ import re
import requests
import hashlib
import base64
import datetime
import os
import platform
from os import path
# Store an event in the log for re-importing messages
def log_event(event):
if "timestamp" not in event:
event["timestamp"] = time.time()
with lockfile(settings.MESSAGE_LOG + '.lock'):
with open(settings.MESSAGE_LOG, 'a') as log:
if not path.exists(settings.EVENT_LOG_DIR):
os.mkdir(settings.EVENT_LOG_DIR)
template = path.join(settings.EVENT_LOG_DIR,
'%s.' + platform.node()
+ datetime.datetime.now().strftime('.%Y-%m-%d'))
with lockfile(template % ('lock',)):
with open(template % ('events',), 'a') as log:
log.write(simplejson.dumps(event) + '\n')
# create_user_hack is the same as Django's User.objects.create_user,