mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 00:18:12 +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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,5 +2,6 @@
|
||||
*~
|
||||
/zephyrdb
|
||||
/all_messages_log.*
|
||||
/event_log/*
|
||||
/server.log
|
||||
*.sw[po]
|
||||
|
||||
@@ -263,7 +263,7 @@ DEFAULT_FROM_EMAIL = "Humbug <humbug@humbughq.com>"
|
||||
|
||||
LOGIN_REDIRECT_URL='/'
|
||||
|
||||
MESSAGE_LOG="all_messages_log." + platform.node()
|
||||
EVENT_LOG_DIR = 'event_log'
|
||||
|
||||
# Polling timeout for get_updates, in milliseconds.
|
||||
# We configure this here so that the client test suite can override it.
|
||||
|
||||
@@ -19,7 +19,7 @@ POLL_TIMEOUT = 1000
|
||||
ENABLE_NOTIFICATIONS = False
|
||||
|
||||
# Don't use the real message log for tests
|
||||
MESSAGE_LOG = "/tmp/test-message-log"
|
||||
EVENT_LOG_DIR = '/tmp/humbug-test-event-log'
|
||||
|
||||
# Print our emails rather than sending them
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -20,8 +20,10 @@ from zephyr.models import MAX_MESSAGE_LENGTH
|
||||
import simplejson
|
||||
import datetime
|
||||
import random
|
||||
import glob
|
||||
import sys
|
||||
import os
|
||||
from os import path
|
||||
from optparse import make_option
|
||||
|
||||
settings.TORNADO_SERVER = None
|
||||
@@ -352,7 +354,9 @@ def restore_saved_messages():
|
||||
else:
|
||||
raise ValueError('Bad message type')
|
||||
|
||||
with file(settings.MESSAGE_LOG, "r") as message_log:
|
||||
event_glob = path.join(settings.EVENT_LOG_DIR, 'events.*')
|
||||
for filename in sorted(glob.glob(event_glob)):
|
||||
with file(filename, "r") as message_log:
|
||||
for line in message_log.readlines():
|
||||
process_line(line)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user