mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user