Author: Armin Rigo <ar...@tunes.org> Branch: remove-py-log Changeset: r82983:eaeeea383e67 Date: 2016-03-11 17:39 +0100 http://bitbucket.org/pypy/pypy/changeset/eaeeea383e67/
Log: Trying to change all places that use the logger diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py --- a/rpython/annotator/annrpython.py +++ b/rpython/annotator/annrpython.py @@ -3,7 +3,7 @@ import types from collections import defaultdict -from rpython.tool.ansi_print import ansi_log +from rpython.tool.ansi_print import AnsiLogger from rpython.tool.pairtype import pair from rpython.tool.error import (format_blocked_annotation_error, gather_error, source_lines) @@ -15,9 +15,7 @@ from rpython.annotator.bookkeeper import Bookkeeper from rpython.rtyper.normalizecalls import perform_normalizations -import py -log = py.log.Producer("annrpython") -py.log.setconsumer("annrpython", ansi_log) +log = AnsiLogger("annrpython") class RPythonAnnotator(object): diff --git a/rpython/jit/backend/ppc/runner.py b/rpython/jit/backend/ppc/runner.py --- a/rpython/jit/backend/ppc/runner.py +++ b/rpython/jit/backend/ppc/runner.py @@ -1,4 +1,3 @@ -import py from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper.llinterp import LLInterpreter from rpython.rlib import rgc @@ -9,9 +8,6 @@ from rpython.jit.backend.ppc.codebuilder import PPCBuilder from rpython.jit.backend.ppc import register as r -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer('jitbackend') -py.log.setconsumer('jitbackend', ansi_log) class PPC_CPU(AbstractLLCPU): diff --git a/rpython/jit/backend/x86/runner.py b/rpython/jit/backend/x86/runner.py --- a/rpython/jit/backend/x86/runner.py +++ b/rpython/jit/backend/x86/runner.py @@ -10,10 +10,6 @@ import sys -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer('jitbackend') -py.log.setconsumer('jitbackend', ansi_log) - class AbstractX86CPU(AbstractLLCPU): debug = True diff --git a/rpython/jit/codewriter/policy.py b/rpython/jit/codewriter/policy.py --- a/rpython/jit/codewriter/policy.py +++ b/rpython/jit/codewriter/policy.py @@ -1,10 +1,8 @@ from rpython.jit.metainterp import history from rpython.tool.udir import udir +from rpython.tool.ansi_print import AnsiLogger -import py -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer('jitcodewriter') -py.log.setconsumer('jitcodewriter', ansi_log) +log = AnsiLogger('jitcodewriter') class JitPolicy(object): diff --git a/rpython/memory/gctransform/log.py b/rpython/memory/gctransform/log.py --- a/rpython/memory/gctransform/log.py +++ b/rpython/memory/gctransform/log.py @@ -1,4 +1,3 @@ -import py -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("gctransform") -py.log.setconsumer("gctransform", ansi_log) +from rpython.tool.ansi_print import AnsiLogger + +log = AnsiLogger("gctransform") diff --git a/rpython/memory/test/gc_test_base.py b/rpython/memory/test/gc_test_base.py --- a/rpython/memory/test/gc_test_base.py +++ b/rpython/memory/test/gc_test_base.py @@ -3,6 +3,7 @@ from rpython.memory import gcwrapper from rpython.memory.test import snippet +from rpython.rtyper import llinterp from rpython.rtyper.test.test_llinterp import get_interpreter from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem.lloperation import llop @@ -15,11 +16,11 @@ WORD = LONG_BIT // 8 -def stdout_ignore_ll_functions(msg): - strmsg = str(msg) - if "evaluating" in strmsg and "ll_" in strmsg: - return - print >>sys.stdout, strmsg +## def stdout_ignore_ll_functions(msg): +## strmsg = str(msg) +## if "evaluating" in strmsg and "ll_" in strmsg: +## return +## print >>sys.stdout, strmsg class GCTest(object): @@ -31,13 +32,11 @@ WREF_IS_INVALID_BEFORE_DEL_IS_CALLED = False def setup_class(cls): - cls._saved_logstate = py.log._getstate() - py.log.setconsumer("llinterp", py.log.STDOUT) - py.log.setconsumer("llinterp frame", stdout_ignore_ll_functions) - py.log.setconsumer("llinterp operation", None) + # switch on logging of interp to show more info on failing tests + llinterp.log.output_disabled = False def teardown_class(cls): - py.log._setstate(cls._saved_logstate) + llinterp.log.output_disabled = True def interpret(self, func, values, **kwds): interp, graph = get_interpreter(func, values, **kwds) diff --git a/rpython/rlib/clibffi.py b/rpython/rlib/clibffi.py --- a/rpython/rlib/clibffi.py +++ b/rpython/rlib/clibffi.py @@ -22,9 +22,6 @@ import sys import ctypes.util -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("libffi") -py.log.setconsumer("libffi", ansi_log) # maaaybe isinstance here would be better. Think _MSVC = platform.name == "msvc" diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py --- a/rpython/rtyper/llinterp.py +++ b/rpython/rtyper/llinterp.py @@ -14,9 +14,15 @@ r_uint, r_longlong, r_ulonglong, r_longlonglong) from rpython.rtyper.lltypesystem import lltype, llmemory, lloperation, llheap from rpython.rtyper import rclass +from rpython.tool.ansi_print import AnsiLogger -log = py.log.Producer('llinterp') +# by default this logger's output is disabled. +# e.g. tests can then switch on logging to get more help +# for failing tests +log = AnsiLogger('llinterp') +log.output_disabled = True + class LLException(Exception): def __init__(self, *args): @@ -1367,10 +1373,3 @@ class _address_of_thread_local(object): _TYPE = llmemory.Address is_fake_thread_local_addr = True - - -# by default we route all logging messages to nothingness -# e.g. tests can then switch on logging to get more help -# for failing tests -from rpython.tool.ansi_print import ansi_log -py.log.setconsumer('llinterp', ansi_log) diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py --- a/rpython/rtyper/rmodel.py +++ b/rpython/rtyper/rmodel.py @@ -454,13 +454,9 @@ # logging/warning -import py -from rpython.tool.ansi_print import ansi_log +from rpython.tool.ansi_print import AnsiLogger -log = py.log.Producer("rtyper") -py.log.setconsumer("rtyper", ansi_log) -py.log.setconsumer("rtyper translating", None) -py.log.setconsumer("rtyper debug", None) +log = AnsiLogger("rtyper") def warning(msg): log.WARNING(msg) diff --git a/rpython/rtyper/test/test_llinterp.py b/rpython/rtyper/test/test_llinterp.py --- a/rpython/rtyper/test/test_llinterp.py +++ b/rpython/rtyper/test/test_llinterp.py @@ -2,7 +2,7 @@ import py import sys from rpython.rtyper.lltypesystem.lltype import typeOf, Void, malloc, free -from rpython.rtyper.llinterp import LLInterpreter, LLException +from rpython.rtyper.llinterp import LLInterpreter, LLException, log from rpython.rtyper.rmodel import inputconst from rpython.rtyper.annlowlevel import hlstr, llhelper from rpython.rtyper.exceptiondata import UnknownException @@ -16,13 +16,10 @@ from rpython.rtyper.rtyper import llinterp_backend # switch on logging of interp to show more info on failing tests - def setup_module(mod): - mod.logstate = py.log._getstate() - py.log.setconsumer("llinterp", py.log.STDOUT) - + log.output_disabled = False def teardown_module(mod): - py.log._setstate(mod.logstate) + log.output_disabled = True def gengraph(func, argtypes=[], viewbefore='auto', policy=None, diff --git a/rpython/rtyper/test/test_rtyper.py b/rpython/rtyper/test/test_rtyper.py --- a/rpython/rtyper/test/test_rtyper.py +++ b/rpython/rtyper/test/test_rtyper.py @@ -1,5 +1,3 @@ -import py - from rpython.annotator import model as annmodel, annrpython from rpython.flowspace.model import Constant from rpython.rtyper import rmodel @@ -9,14 +7,6 @@ from rpython.translator.translator import TranslationContext, graphof -def setup_module(mod): - mod.logstate = py.log._getstate() - py.log.setconsumer("rtyper", py.log.STDOUT) - py.log.setconsumer("annrpython", None) - -def teardown_module(mod): - py.log._setstate(mod.logstate) - def test_reprkeys_dont_clash(): stup1 = annmodel.SomeTuple((annmodel.SomeFloat(), annmodel.SomeInteger())) diff --git a/rpython/tool/ansi_print.py b/rpython/tool/ansi_print.py --- a/rpython/tool/ansi_print.py +++ b/rpython/tool/ansi_print.py @@ -16,6 +16,8 @@ # def logger_method(self, text): global wrote_dot + if self.output_disabled: + return text = "[%s%s] %s" % (self.name, subname, text) if isatty(): col = colors @@ -30,6 +32,7 @@ class AnsiLogger(object): + output_disabled = False def __init__(self, name): self.name = name @@ -44,6 +47,13 @@ info = _make_method(':info', (35,)) stub = _make_method(':stub', (34,)) + # some more methods used by sandlib + call = _make_method(':call', (34,)) + result = _make_method(':result', (34,)) + exception = _make_method(':exception', (34,)), + vpath = _make_method(':vpath', (35,)), + timeout = _make_method('', (1, 31)), + # directly calling the logger writes "[name] text" with no particular color __call__ = _make_method('', ()) diff --git a/rpython/tool/error.py b/rpython/tool/error.py --- a/rpython/tool/error.py +++ b/rpython/tool/error.py @@ -8,12 +8,8 @@ from rpython.flowspace.model import Variable from rpython.rlib import jit -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("error") -py.log.setconsumer("error", ansi_log) - SHOW_TRACEBACK = False SHOW_ANNOTATIONS = True SHOW_DEFAULT_LINES_OF_CODE = 0 diff --git a/rpython/tool/test/test_ansi_print.py b/rpython/tool/test/test_ansi_print.py --- a/rpython/tool/test/test_ansi_print.py +++ b/rpython/tool/test/test_ansi_print.py @@ -74,3 +74,11 @@ assert output == [('[test:foo] Hello\n', ()), ('[test:foo] World\n', ()), ('[test:BAR] !\n', ())] + +def test_output_disabled(): + log = ansi_print.AnsiLogger('test') + with FakeOutput() as output: + log('Hello') + log.output_disabled = True + log('World') + assert output == [('[test] Hello\n', ())] diff --git a/rpython/tool/version.py b/rpython/tool/version.py --- a/rpython/tool/version.py +++ b/rpython/tool/version.py @@ -10,9 +10,8 @@ if not err: return - from rpython.tool.ansi_print import ansi_log - log = py.log.Producer("version") - py.log.setconsumer("version", ansi_log) + from rpython.tool.ansi_print import AnsiLogger + log = AnsiLogger("version") log.WARNING('Errors getting %s information: %s' % (repo_type, err)) def get_repo_version_info(hgexe=None, root=rpythonroot): diff --git a/rpython/translator/backendopt/canraise.py b/rpython/translator/backendopt/canraise.py --- a/rpython/translator/backendopt/canraise.py +++ b/rpython/translator/backendopt/canraise.py @@ -1,11 +1,8 @@ -import py - from rpython.rtyper.lltypesystem.lloperation import LL_OPERATIONS -from rpython.tool.ansi_print import ansi_log +from rpython.tool.ansi_print import AnsiLogger from rpython.translator.backendopt import graphanalyze -log = py.log.Producer("canraise") -py.log.setconsumer("canraise", ansi_log) +log = AnsiLogger("canraise") class RaiseAnalyzer(graphanalyze.BoolGraphAnalyzer): diff --git a/rpython/translator/backendopt/support.py b/rpython/translator/backendopt/support.py --- a/rpython/translator/backendopt/support.py +++ b/rpython/translator/backendopt/support.py @@ -1,13 +1,9 @@ -import py - from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.rmodel import inputconst -from rpython.tool.ansi_print import ansi_log +from rpython.tool.ansi_print import AnsiLogger from rpython.translator.simplify import get_graph - -log = py.log.Producer("backendopt") -py.log.setconsumer("backendopt", ansi_log) +log = AnsiLogger("backendopt") def graph_operations(graph): diff --git a/rpython/translator/backendopt/test/test_removenoops.py b/rpython/translator/backendopt/test/test_removenoops.py --- a/rpython/translator/backendopt/test/test_removenoops.py +++ b/rpython/translator/backendopt/test/test_removenoops.py @@ -12,8 +12,6 @@ from rpython.rtyper.llinterp import LLInterpreter from rpython.conftest import option -import py -log = py.log.Producer('test_backendoptimization') def get_graph(fn, signature, all_opts=True): t = TranslationContext() diff --git a/rpython/translator/c/support.py b/rpython/translator/c/support.py --- a/rpython/translator/c/support.py +++ b/rpython/translator/c/support.py @@ -166,7 +166,5 @@ # logging -import py -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("c") -py.log.setconsumer("c", ansi_log) +from rpython.tool.ansi_print import AnsiLogger +log = AnsiLogger("c") diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py --- a/rpython/translator/driver.py +++ b/rpython/translator/driver.py @@ -14,9 +14,9 @@ annotated_jit_entrypoints import py -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("translation") -py.log.setconsumer("translation", ansi_log) +from rpython.tool.ansi_print import AnsiLogger + +log = AnsiLogger("translation") def taskdef(deps, title, new_state=None, expected_states=[], @@ -524,7 +524,6 @@ @taskdef([STACKCHECKINSERTION, '?'+BACKENDOPT, RTYPE], "LLInterpreting") def task_llinterpret_lltype(self): from rpython.rtyper.llinterp import LLInterpreter - py.log.setconsumer("llinterp operation", None) translator = self.translator interp = LLInterpreter(translator.rtyper) @@ -534,7 +533,7 @@ self.extra.get('get_llinterp_args', lambda: [])()) - log.llinterpret.event("result -> %s" % v) + log.llinterpret("result -> %s" % v) def proceed(self, goals): if not goals: diff --git a/rpython/translator/goal/timing.py b/rpython/translator/goal/timing.py --- a/rpython/translator/goal/timing.py +++ b/rpython/translator/goal/timing.py @@ -5,9 +5,8 @@ import time import py -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("Timer") -py.log.setconsumer("Timer", ansi_log) +from rpython.tool.ansi_print import AnsiLogger +log = AnsiLogger("Timer") class Timer(object): def __init__(self, timer=time.time): diff --git a/rpython/translator/goal/translate.py b/rpython/translator/goal/translate.py --- a/rpython/translator/goal/translate.py +++ b/rpython/translator/goal/translate.py @@ -83,9 +83,8 @@ ]) import optparse -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("translation") -py.log.setconsumer("translation", ansi_log) +from rpython.tool.ansi_print import AnsiLogger +log = AnsiLogger("translation") def load_target(targetspec): log.info("Translating target as defined by %s" % targetspec) diff --git a/rpython/translator/platform/__init__.py b/rpython/translator/platform/__init__.py --- a/rpython/translator/platform/__init__.py +++ b/rpython/translator/platform/__init__.py @@ -5,8 +5,9 @@ from rpython.tool.runsubprocess import run_subprocess as _run_subprocess from rpython.tool.udir import udir from rpython.tool.version import rpythonroot +from rpython.tool.ansi_print import AnsiLogger -log = py.log.Producer("platform") +log = AnsiLogger("platform") class CompilationError(Exception): diff --git a/rpython/translator/sandbox/rsandbox.py b/rpython/translator/sandbox/rsandbox.py --- a/rpython/translator/sandbox/rsandbox.py +++ b/rpython/translator/sandbox/rsandbox.py @@ -17,10 +17,9 @@ from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.llannotation import lltype_to_annotation from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator -from rpython.tool.ansi_print import ansi_log +from rpython.tool.ansi_print import AnsiLogger -log = py.log.Producer("sandbox") -py.log.setconsumer("sandbox", ansi_log) +log = AnsiLogger("sandbox") # a version of os.read() and os.write() that are not mangled diff --git a/rpython/translator/sandbox/sandlib.py b/rpython/translator/sandbox/sandlib.py --- a/rpython/translator/sandbox/sandlib.py +++ b/rpython/translator/sandbox/sandlib.py @@ -15,21 +15,8 @@ def create_log(): """Make and return a log for the sandbox to use, if needed.""" - # These imports are local to avoid importing pypy if we don't need to. - from rpython.tool.ansi_print import AnsiLog - - class MyAnsiLog(AnsiLog): - KW_TO_COLOR = { - 'call': ((34,), False), - 'result': ((34,), False), - 'exception': ((34,), False), - 'vpath': ((35,), False), - 'timeout': ((1, 31), True), - } - - log = py.log.Producer("sandlib") - py.log.setconsumer("sandlib", MyAnsiLog()) - return log + from rpython.tool.ansi_print import AnsiLogger + return AnsiLogger("sandlib") # Note: we use lib_pypy/marshal.py instead of the built-in marshal # for two reasons. The built-in module could be made to segfault diff --git a/rpython/translator/translator.py b/rpython/translator/translator.py --- a/rpython/translator/translator.py +++ b/rpython/translator/translator.py @@ -10,13 +10,11 @@ from rpython.translator import simplify from rpython.flowspace.model import FunctionGraph, checkgraph, Block from rpython.flowspace.objspace import build_flow -from rpython.tool.ansi_print import ansi_log +from rpython.tool.ansi_print import AnsiLogger from rpython.tool.sourcetools import nice_repr_for_func from rpython.config.translationoption import get_platform -import py -log = py.log.Producer("flowgraph") -py.log.setconsumer("flowgraph", ansi_log) +log = AnsiLogger("flowgraph") class TranslationContext(object): FLOWING_FLAGS = { @@ -50,14 +48,12 @@ graph = self._prebuilt_graphs.pop(func) else: if self.config.translation.verbose: - log.start(nice_repr_for_func(func)) + log(nice_repr_for_func(func)) graph = build_flow(func) simplify.simplify_graph(graph) if self.config.translation.list_comprehension_operations: simplify.detect_list_comprehension(graph) - if self.config.translation.verbose: - log.done(func.__name__) - elif not mute_dot: + if not self.config.translation.verbose and not mute_dot: log.dot() self.graphs.append(graph) # store the graph in our list return graph _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit