# HG changeset patch # User Paul Crowley # Date 1292596765 0 # Node ID 675474f5be324b6df9c03a9a203e81e36b042509 # Parent 57dcdb212d00805283d4826e1c5ade441984e633 New log file format based on JSON/YAML diff -r 57dcdb212d00 -r 675474f5be32 src/mercurialserver/servelog.py --- a/src/mercurialserver/servelog.py Tue Nov 30 11:26:08 2010 -0500 +++ b/src/mercurialserver/servelog.py Fri Dec 17 14:39:25 2010 +0000 @@ -8,6 +8,8 @@ import os import time +import fcntl +import json from mercurialserver import ruleset, changes def hook(ui, repo, hooktype, node=None, source=None, **kwargs): @@ -18,13 +20,18 @@ else: raise mercurial.util.Abort(_('servelog installed as wrong hook type,' ' must be changegroup or outgoing but is %s') % hooktype) - t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime()) - user = ruleset.rules.get('user') - # FIXME: lock it - log = open(repo.join("serve-log"), "a+") + log = open(repo.join("mercurial-server.log"), "a+") try: - for ctx in changes.changes(repo, node): - log.write("%s %s key=%s changeset=%s\n" % - (t, op, user, mercurial.node.hex(ctx.node()))) + fcntl.flock(log.fileno(), fcntl.LOCK_EX) + log.seek(0, os.SEEK_END) + # YAML log file format + log.write("- {0}\n".format(json.dumps(dict( + timestamp=time.strftime("%Y-%m-%d_%H:%M:%S Z", time.gmtime()), + op=op, + key=ruleset.rules.get('user'), + ssh_connection=os.environ['SSH_CONNECTION'], + nodes=[mercurial.node.hex(ctx.node()) + for ctx in changes.changes(repo, node)], + )))) finally: log.close()