commit 48da99388163157f8c371b0207958d8804f7d574 Author: Arturo Filastò art@fuffa.org Date: Fri Dec 7 03:52:35 2012 +0100
Improve the appearance of stdout output * No longer use the python logging interface * Include only the timestamp and component name in the ooniprobe log --- ooni/reporter.py | 3 ++- ooni/runner.py | 3 +-- ooni/utils/log.py | 33 ++++++++++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/ooni/reporter.py b/ooni/reporter.py index 602b687..12e4dc8 100644 --- a/ooni/reporter.py +++ b/ooni/reporter.py @@ -116,7 +116,7 @@ def getTestDetails(options): config.privacy.includeasn or \ config.privacy.includecountry or \ config.privacy.includecity: - log.msg("Running geo IP lookup via check.torproject.org") + log.msg("We will include some geo data in the report") client_geodata = geodata.IPToLocation(config.probe_ip)
if config.privacy.includeip: @@ -132,6 +132,7 @@ def getTestDetails(options): # XXX this regexp should probably go inside of geodata client_geodata['asn'] = \ re.search('AS\d+', client_geodata['asn']).group(0) + log.msg("Your AS number is: %s" % client_geodata['asn'])
if client_geodata and not config.privacy.includecity: client_geodata['city'] = None diff --git a/ooni/runner.py b/ooni/runner.py index 2936a99..53e4e55 100644 --- a/ooni/runner.py +++ b/ooni/runner.py @@ -171,7 +171,7 @@ def runTestCasesWithInput(test_cases, test_input, yaml_reporter, tests_report = {}
def test_done(result, test_instance, test_name): - log.msg("Successfully finished running %s" % test_name) + log.msg("Finished running %s" % test_name) log.debug("Deferred callback result: %s" % result) tests_report[test_name] = dict(test_instance.report) if not oonib_reporter: @@ -356,7 +356,6 @@ def updateProgressMeters(test_filename, input_unit_factory, """ Update the progress meters for keeping track of test state. """ - log.msg("Setting up progress meters") if not config.state.test_filename: config.state[test_filename] = Storage()
diff --git a/ooni/utils/log.py b/ooni/utils/log.py index 9ab8880..0740c10 100644 --- a/ooni/utils/log.py +++ b/ooni/utils/log.py @@ -1,9 +1,10 @@ import sys import os -import traceback import logging +import traceback
from twisted.python import log as txlog +from twisted.python import util from twisted.python.failure import Failure from twisted.python.logfile import DailyLogFile
@@ -14,6 +15,15 @@ from ooni import config ## IPv6 destination warnings": logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
+class LogWithNoPrefix(txlog.FileLogObserver): + def emit(self, eventDict): + text = txlog.textFromEventDict(eventDict) + if text is None: + return + + util.untilConcludes(self.write, "%s\n" % text) + util.untilConcludes(self.flush) # Hoorj! + def start(logfile=None, application_name="ooniprobe"): daily_logfile = None
@@ -27,29 +37,22 @@ def start(logfile=None, application_name="ooniprobe"):
txlog.msg("Starting %s on %s (%s UTC)" % (application_name, otime.prettyDateNow(), otime.utcPrettyDateNow())) - logging.basicConfig() - python_logging = txlog.PythonLoggingObserver(application_name) - - if config.advanced.debug: - python_logging.logger.setLevel(logging.DEBUG) - else: - python_logging.logger.setLevel(logging.INFO) - - txlog.startLoggingWithObserver(python_logging.emit)
+ txlog.startLoggingWithObserver(LogWithNoPrefix(sys.stdout).emit) txlog.addObserver(txlog.FileLogObserver(daily_logfile).emit)
def stop(): - txlog.msg("Stopping OONI") + print "Stopping OONI"
def msg(msg, *arg, **kw): - txlog.msg(msg, logLevel=logging.INFO, *arg, **kw) + print "%s" % msg
def debug(msg, *arg, **kw): - txlog.msg(msg, logLevel=logging.DEBUG, *arg, **kw) + if config.advanced.debug: + print "[D] %s" % msg
def err(msg, *arg, **kw): - txlog.err("Error: " + str(msg), logLevel=logging.ERROR, *arg, **kw) + print "[!] %s" % msg
def exception(error): """ @@ -71,7 +74,7 @@ class LoggerFactory(object):
def start(self, application): # XXX parametrize this - start('/tmp/oonib.log', "OONIB") + start('oonib.log', "OONIB")
def stop(self): txlog.msg("Stopping OONIB")
tor-commits@lists.torproject.org