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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,5 +2,6 @@
|
|||||||
*~
|
*~
|
||||||
/zephyrdb
|
/zephyrdb
|
||||||
/all_messages_log.*
|
/all_messages_log.*
|
||||||
|
/event_log/*
|
||||||
/server.log
|
/server.log
|
||||||
*.sw[po]
|
*.sw[po]
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ DEFAULT_FROM_EMAIL = "Humbug <humbug@humbughq.com>"
|
|||||||
|
|
||||||
LOGIN_REDIRECT_URL='/'
|
LOGIN_REDIRECT_URL='/'
|
||||||
|
|
||||||
MESSAGE_LOG="all_messages_log." + platform.node()
|
EVENT_LOG_DIR = 'event_log'
|
||||||
|
|
||||||
# Polling timeout for get_updates, in milliseconds.
|
# Polling timeout for get_updates, in milliseconds.
|
||||||
# We configure this here so that the client test suite can override it.
|
# We configure this here so that the client test suite can override it.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ POLL_TIMEOUT = 1000
|
|||||||
ENABLE_NOTIFICATIONS = False
|
ENABLE_NOTIFICATIONS = False
|
||||||
|
|
||||||
# Don't use the real message log for tests
|
# 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
|
# Print our emails rather than sending them
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||||
|
|||||||
@@ -21,13 +21,25 @@ import re
|
|||||||
import requests
|
import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
from os import path
|
||||||
|
|
||||||
# Store an event in the log for re-importing messages
|
# Store an event in the log for re-importing messages
|
||||||
def log_event(event):
|
def log_event(event):
|
||||||
if "timestamp" not in event:
|
if "timestamp" not in event:
|
||||||
event["timestamp"] = time.time()
|
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')
|
log.write(simplejson.dumps(event) + '\n')
|
||||||
|
|
||||||
# create_user_hack is the same as Django's User.objects.create_user,
|
# 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 simplejson
|
||||||
import datetime
|
import datetime
|
||||||
import random
|
import random
|
||||||
|
import glob
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
from os import path
|
||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
|
|
||||||
settings.TORNADO_SERVER = None
|
settings.TORNADO_SERVER = None
|
||||||
@@ -352,7 +354,9 @@ def restore_saved_messages():
|
|||||||
else:
|
else:
|
||||||
raise ValueError('Bad message type')
|
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():
|
for line in message_log.readlines():
|
||||||
process_line(line)
|
process_line(line)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user