diff --git a/src/xpra/client/gl/gl_check.py b/src/xpra/client/gl/gl_check.py index a888a17229..bb16c8fe70 100755 --- a/src/xpra/client/gl/gl_check.py +++ b/src/xpra/client/gl/gl_check.py @@ -490,9 +490,11 @@ def main(): from xpra.platform import init,clean from xpra.platform.gui import init as gui_init from xpra.util import pver + from xpra.log import enable_color try: init("OpenGL-Check") gui_init() + enable_color() verbose = "-v" in sys.argv or "--verbose" in sys.argv if verbose: log.enable_debug() diff --git a/src/xpra/client/gtk_base/client_launcher.py b/src/xpra/client/gtk_base/client_launcher.py index 40bce8ed94..98026eeba1 100755 --- a/src/xpra/client/gtk_base/client_launcher.py +++ b/src/xpra/client/gtk_base/client_launcher.py @@ -742,10 +742,11 @@ def main(): from xpra.platform import init as platform_init, clean as platform_clean from xpra.platform.gui import ready as gui_ready + from xpra.log import enable_color try: platform_init("Xpra-Launcher", "Xpra Connection Launcher") + enable_color() gui_init() - try: from xpra.scripts.main import parse_cmdline, fixup_debug_option options, args = parse_cmdline(sys.argv) diff --git a/src/xpra/codecs/loader.py b/src/xpra/codecs/loader.py index 232465d052..dee59c635c 100755 --- a/src/xpra/codecs/loader.py +++ b/src/xpra/codecs/loader.py @@ -257,8 +257,10 @@ def encoding_help(encoding): def main(): from xpra.platform import init, clean + from xpra.log import enable_color try: init("Loader", "Encoding Info") + enable_color() verbose = "-v" in sys.argv or "--verbose" in sys.argv if verbose: log.enable_debug() diff --git a/src/xpra/codecs/video_helper.py b/src/xpra/codecs/video_helper.py index fbcf3e8d48..f96f7d72bb 100755 --- a/src/xpra/codecs/video_helper.py +++ b/src/xpra/codecs/video_helper.py @@ -427,18 +427,27 @@ def getVideoHelper(): def main(): from xpra.codecs.loader import log as loader_log, load_codecs - if "-v" in sys.argv or "--verbose" in sys.argv: - loader_log.enable_debug() - log.enable_debug() - load_codecs() - vh = getVideoHelper() - vh.set_modules(ALL_VIDEO_ENCODER_OPTIONS, ALL_CSC_MODULE_OPTIONS, ALL_VIDEO_DECODER_OPTIONS) - vh.init() - log.info("VideoHelper.get_info():") - info = vh.get_info() - for k in sorted(info.keys()): - v = info.get(k) - log.info("%s=%s", k, v) + from xpra.log import enable_color + from xpra.platform import init, clean + try: + init("Video Helper") + enable_color() + if "-v" in sys.argv or "--verbose" in sys.argv: + loader_log.enable_debug() + log.enable_debug() + load_codecs() + vh = getVideoHelper() + vh.set_modules(ALL_VIDEO_ENCODER_OPTIONS, ALL_CSC_MODULE_OPTIONS, ALL_VIDEO_DECODER_OPTIONS) + vh.init() + log.info("VideoHelper.get_info():") + info = vh.get_info() + for k in sorted(info.keys()): + v = info.get(k) + if type(v) in (list, tuple): + v = csv(v) + log.info("%s=%s", k, v) + finally: + clean() if __name__ == "__main__": diff --git a/src/xpra/gtk_common/gtk_view_clipboard.py b/src/xpra/gtk_common/gtk_view_clipboard.py index 5625ea05f5..2086ca6de2 100755 --- a/src/xpra/gtk_common/gtk_view_clipboard.py +++ b/src/xpra/gtk_common/gtk_view_clipboard.py @@ -239,8 +239,10 @@ def destroy(self, *args): def main(): from xpra.platform import init, clean + from xpra.log import enable_color try: init("Clipboard-Test", "Clipboard Test Tool") + enable_color() ClipboardStateInfoWindow() gtk.main() finally: diff --git a/src/xpra/gtk_common/gtk_view_keyboard.py b/src/xpra/gtk_common/gtk_view_keyboard.py index 62ca64dda8..21042096c2 100755 --- a/src/xpra/gtk_common/gtk_view_keyboard.py +++ b/src/xpra/gtk_common/gtk_view_keyboard.py @@ -120,8 +120,10 @@ def destroy(self, *args): def main(): from xpra.platform import init, clean + from xpra.log import enable_color try: init("Keyboard-Test", "Keyboard Test Tool") + enable_color() KeyboardStateInfoWindow() gtk.main() finally: diff --git a/src/xpra/gtk_common/keymap.py b/src/xpra/gtk_common/keymap.py old mode 100644 new mode 100755 index 0899f55d09..115e632f52 --- a/src/xpra/gtk_common/keymap.py +++ b/src/xpra/gtk_common/keymap.py @@ -56,9 +56,11 @@ def get_gtk_keymap(ignore_keys=[None, "VoidSymbol", "0xffffff"]): def main(): import sys from xpra.platform import init, clean + from xpra.log import enable_color try: init("Keymap-Tool", "Keymap Information Tool") - if "-v" in sys.argv: + enable_color() + if "-v" in sys.argv or "--verbose" in sys.argv: log.enable_debug() gtk_keymap = get_gtk_keymap() def pkey(*entries): diff --git a/src/xpra/log.py b/src/xpra/log.py index 9687e68181..7adcd42afe 100644 --- a/src/xpra/log.py +++ b/src/xpra/log.py @@ -107,6 +107,19 @@ def set_global_logging_handler(h): global_logging_handler = h return saved + +def setloghandler(lh): + logging.root.handlers = [] + logging.root.addHandler(lh) + +def enable_color(to=sys.stdout, formatter=NOPREFIX_FORMAT): + from xpra.colorstreamhandler import ColorStreamHandler + from logging import Formatter + csh = ColorStreamHandler(to) + csh.setFormatter(Formatter(formatter)) + setloghandler(csh) + + #the order will be preserved with Python 2.7 onwards: try: from collections import OrderedDict diff --git a/src/xpra/net/net_util.py b/src/xpra/net/net_util.py index a9ecbbe7ed..3fbde86863 100755 --- a/src/xpra/net/net_util.py +++ b/src/xpra/net/net_util.py @@ -160,8 +160,10 @@ def get_info(): def main(): from xpra.platform import init, clean + from xpra.log import enable_color try: init("Network-Info", "Network Info") + enable_color() verbose = "-v" in sys.argv or "--verbose" in sys.argv if verbose: log.enable_debug() diff --git a/src/xpra/platform/gui.py b/src/xpra/platform/gui.py old mode 100644 new mode 100755 index ab93e06315..2ffc9c4ac6 --- a/src/xpra/platform/gui.py +++ b/src/xpra/platform/gui.py @@ -190,8 +190,10 @@ def fnames(l): def main(): from xpra.platform import init as platform_init,clean from xpra.util import nonl + from xpra.log import enable_color try: platform_init("GUI-Properties") + enable_color() init() verbose = "-v" in sys.argv or "--verbose" in sys.argv if verbose: diff --git a/src/xpra/platform/printing.py b/src/xpra/platform/printing.py old mode 100644 new mode 100755 index d7f77cc081..cc0630ae26 --- a/src/xpra/platform/printing.py +++ b/src/xpra/platform/printing.py @@ -84,8 +84,10 @@ def print_dict(d): v = d[k] print("* %s : %s" % (k.ljust(32), nonl(pver(v)))) from xpra.platform import init, clean + from xpra.log import enable_color try: init("Printing", "Printing") + enable_color() if len(sys.argv)<3: print_dict(get_printers()) else: diff --git a/src/xpra/scripts/bug_report.py b/src/xpra/scripts/bug_report.py old mode 100644 new mode 100755 index 444b8e65e7..2cad2933c0 --- a/src/xpra/scripts/bug_report.py +++ b/src/xpra/scripts/bug_report.py @@ -9,6 +9,8 @@ def main(): from xpra.platform import init as platform_init platform_init("Xpra-Bug-Report", "Xpra Bug Report") + from xpra.log import enable_color + enable_color() from xpra.log import Logger, enable_debug_for log = Logger("util") diff --git a/src/xpra/scripts/config.py b/src/xpra/scripts/config.py old mode 100644 new mode 100755 index 0301e60db4..1b5c147b1a --- a/src/xpra/scripts/config.py +++ b/src/xpra/scripts/config.py @@ -752,10 +752,12 @@ def print_options(o): v = ", ".join(str(x) for x in v) print("* %-32s : %s" % (k, nonl(v))) from xpra.platform import init, clean + from xpra.log import enable_color try: init("Config-Info", "Config Info") + enable_color() args = list(sys.argv[1:]) - if "-v" in args: + if "-v" in args or "--verbose" in sys.argv: global debug def debug(*args): print(args[0] % args[1:]) diff --git a/src/xpra/scripts/main.py b/src/xpra/scripts/main.py index 533dd40183..cbbd556d43 100755 --- a/src/xpra/scripts/main.py +++ b/src/xpra/scripts/main.py @@ -788,28 +788,21 @@ def show_sound_codec_help(is_server, speaker_codecs, microphone_codecs): microphone_codecs += all_microphone_codecs return info -def setloghandler(lh): - logging.root.handlers = [] - logging.root.addHandler(lh) - def configure_logging(options, mode): to = sys.stderr if mode in ("showconfig", "info", "control", "list", "attach", "stop", "version", "print"): to = sys.stdout - if mode in ("start", "upgrade", "attach", "shadow", "proxy", "_sound_record", "_sound_play", "stop", "version", "print"): + if mode in ("start", "upgrade", "attach", "shadow", "proxy", "_sound_record", "_sound_play", "stop", "version", "print", "showconfig"): if "help" in options.speaker_codec or "help" in options.microphone_codec: info = show_sound_codec_help(mode!="attach", options.speaker_codec, options.microphone_codec) raise InitInfo("\n".join(info)) if (hasattr(to, "fileno") and os.isatty(to.fileno())) or os.environ.get("XPRA_FORCE_COLOR_LOG", "0")=="1": - from xpra.colorstreamhandler import ColorStreamHandler - from xpra.log import LOG_FORMAT - from logging import Formatter - csh = ColorStreamHandler(to) - csh.setFormatter(Formatter(LOG_FORMAT)) - setloghandler(csh) + from xpra.log import LOG_FORMAT, enable_color + enable_color(to, LOG_FORMAT) else: #a bit naughty here, but it's easier to let xpra.log initialize #the logging system every time, and just undo things here.. + from xpra.log import setloghandler setloghandler(logging.StreamHandler(to)) from xpra.log import add_debug_category, add_disabled_category, enable_debug_for, disable_debug_for @@ -1689,15 +1682,10 @@ def run_list(error_cb, opts, extra_args): return 0 def run_showconfig(options, args): - from xpra.colorstreamhandler import ColorStreamHandler - from xpra.log import Logger, NOPREFIX_FORMAT - from xpra.util import nonl - from logging import Formatter - csh = ColorStreamHandler(sys.stdout) - csh.setFormatter(Formatter(NOPREFIX_FORMAT)) - setloghandler(csh) + from xpra.log import Logger log = Logger("util") from xpra.scripts.config import dict_to_validated_config, print_env + from xpra.util import nonl d = dict_to_validated_config({}) fixup_options(d) VIRTUAL = ["mode"] #no such option! (it's a virtual one for the launch by config files) diff --git a/src/xpra/sound/gstreamer_util.py b/src/xpra/sound/gstreamer_util.py index ab90f40619..c1d239c7ac 100755 --- a/src/xpra/sound/gstreamer_util.py +++ b/src/xpra/sound/gstreamer_util.py @@ -583,8 +583,10 @@ def sound_option_or_all(name, options, all_values): def main(): global pygst_version, gst_version, gst_vinfo from xpra.platform import init, clean + from xpra.log import enable_color try: init("GStreamer-Info", "GStreamer Information") + enable_color() if "-v" in sys.argv or "--verbose" in sys.argv: log.enable_debug() import_gst() diff --git a/src/xpra/sound/pulseaudio_util.py b/src/xpra/sound/pulseaudio_util.py index e8bea35350..25926b4703 100755 --- a/src/xpra/sound/pulseaudio_util.py +++ b/src/xpra/sound/pulseaudio_util.py @@ -54,11 +54,18 @@ def add_audio_tagging_env(env_dict=os.environ, icon_path=None): def main(): - if "-v" in sys.argv: - log.enable_debug() - i = get_info() - for k in sorted(i): - log.info("%s : %s", k.ljust(64), i[k]) + from xpra.platform import init, clean + from xpra.log import enable_color + try: + init("Pulseaudio-Info") + enable_color() + if "-v" in sys.argv or "--verbose" in sys.argv: + log.enable_debug() + i = get_info() + for k in sorted(i): + log.info("%s : %s", k.ljust(64), i[k]) + finally: + clean() if __name__ == "__main__": main()