Merge pull request #559 from tahoe-lafs/2981.send-eliot-logs.somewhere

Send Eliot logs somewhere.

Fixes: ticket:2981
This commit is contained in:
Jean-Paul Calderone 2019-03-04 11:26:00 -05:00 committed by GitHub
commit 95745b9467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 7 deletions

View File

@ -12,6 +12,12 @@ import pytest_twisted
# tests converted from check_magicfolder_smoke.py
# see "conftest.py" for the fixtures (e.g. "magic_folder")
def test_eliot_logs_are_written(temp_dir):
# The integration test configuration arranges for this logging
# configuration. Verify it actually does what we want.
assert exists(join(temp_dir, "alice", "logs", "eliot.json"))
assert exists(join(temp_dir, "bob", "logs", "eliot.json"))
def test_alice_writes_bob_receives(magic_folder):
alice_dir, bob_dir = magic_folder

0
newsfragments/2981.other Normal file
View File

View File

@ -13,6 +13,7 @@ from allmydata.util.encodingutil import quote_output, quote_local_unicode_path,
from allmydata.util.eliotutil import (
opt_eliot_destination,
opt_help_eliot_destinations,
eliot_logging_service,
)
def GROUP(s):
@ -183,13 +184,28 @@ def dispatch(config,
d.addCallback(_raise_sys_exit)
return d
def _maybe_enable_eliot_logging(options, reactor):
if options.get("destinations"):
service = eliot_logging_service(reactor, options["destinations"])
# There is no Twisted "Application" around to hang this on so start
# and stop it ourselves.
service.startService()
reactor.addSystemEventTrigger("after", "shutdown", service.stopService)
# Pass on the options so we can dispatch the subcommand.
return options
def run():
assert sys.version_info < (3,), ur"Tahoe-LAFS does not run under Python 3. Please use Python 2.7.x."
if sys.platform == "win32":
from allmydata.windows.fixups import initialize
initialize()
# doesn't return: calls sys.exit(rc)
task.react(_run_with_reactor)
def _run_with_reactor(reactor):
d = defer.maybeDeferred(parse_or_exit_with_explanation, sys.argv[1:])
d.addCallback(_maybe_enable_eliot_logging, reactor)
d.addCallback(dispatch)
def _show_exception(f):
# when task.react() notices a non-SystemExit exception, it does
@ -201,7 +217,7 @@ def run():
f.printTraceback(file=sys.stderr)
sys.exit(1)
d.addErrback(_show_exception)
task.react(lambda _reactor: d) # doesn't return: calls sys.exit(rc)
return d
if __name__ == "__main__":
run()

View File

@ -458,12 +458,14 @@ class _DestinationParser(object):
10,
arg_list,
))
get_file = lambda: LogFile(
path.basename(),
path.dirname(),
rotateLength=rotate_length,
maxRotatedFiles=max_rotated_files,
)
def get_file():
path.parent().makedirs(ignoreExistingDirectory=True)
return LogFile(
path.basename(),
path.dirname(),
rotateLength=rotate_length,
maxRotatedFiles=max_rotated_files,
)
return lambda reactor: FileDestination(get_file())