xpra icon
Bug tracker and wiki

Ticket #786: remote-logging.patch

File remote-logging.patch, 10.6 KB (added by Antoine Martin, 6 years ago)

work in progress patch

  • setup.py

     
    761761    with open(build_base + "/xpra.conf", "w") as f_out:
    762762        f_out.write(template % {'xvfb_command'  : xvfb_command,
    763763                                'ssh_command'   : ssh_command,
     764                                'remote-logging': OSX or WIN32,
    764765                                'env'           : "\n".join(envstr(*x) for x in env_strs),
    765766                                'has_displayfd' : ["no", "yes"][int(has_displayfd)]})
    766767
  • man/xpra.1

     
    3131[\fB\-\-xsettings\fP=\fIyes\fP|\fIno\fP]
    3232[\fB\-\-system\-tray\fP=\fIyes\fP|\fIno\fP]
    3333[\fB\-\-bell\fP=\fIyes\fP|\fIno\fP]
     34[\fB\-\-remote\-logging\fP=\fIyes\fP|\fIno\fP]
    3435[\fB\-\-sound\-source\fP=\fIPLUGIN\fP]
    3536[\fB\-\-speaker\fP=\fIyes\fP|\fIno\fP]
    3637[\fB\-\-speaker\-codec\fP=\fICODEC\fP]
     
    6061[\fB\-\-xsettings\fP=\fIyes\fP|\fIno\fP]
    6162[\fB\-\-system\-tray\fP=\fIyes\fP|\fIno\fP]
    6263[\fB\-\-bell\fP=\fIyes\fP|\fIno\fP]
     64[\fB\-\-remote\-logging\fP=\fIyes\fP|\fIno\fP]
    6365[\fB\-\-keyboard\-sync\fP=\fIyes\fP|\fIno\fP]
    6466[\fB\-\-tray\fP=\fIyes\fP|\fIno\fP]
    6567[\fB\-\-sound\-source\fP=\fIPLUGIN\fP]
     
    715717.TP
    716718\fB\-\-bell\fP=\fIyes\fP|\fIno\fP
    717719Enable or disable forwarding of the system bell.
     720.TP
     721\fB\-\-remote\-logging\fP=\fIyes\fP|\fIno\fP
     722Allow the client to forward its log output to the server.
    718723
    719724.SS Options for attach
    720725.TP
  • etc/xpra/xpra.conf.in

     
    5454# Send ping packets more regularly (every second):
    5555pings = no
    5656
     57# Allow the client to forward its log output to the server:
     58#remote-logging = yes
     59remote-logging = %(remote-logging)
    5760
     61
    5862################################################################################
    5963# Picture Encoding
    6064
  • xpra/client/ui_client_base.py

     
    99import sys
    1010import time
    1111import datetime
     12import traceback
    1213from collections import deque
    1314
    14 from xpra.log import Logger
     15from xpra.log import Logger, set_global_logging_handler
    1516log = Logger("client")
    1617windowlog = Logger("client", "window")
    1718paintlog = Logger("client", "paint")
     
    196197        self.client_supports_cursors = False
    197198        self.client_supports_bell = False
    198199        self.client_supports_sharing = False
     200        self.client_supports_remote_logging = False
    199201        self.notifications_enabled = False
    200202        self.clipboard_enabled = False
    201203        self.cursors_enabled = False
     
    212214        self.menu_helper = None
    213215        self.tray = None
    214216        self.notifier = None
     217        self.in_remote_logging = False
     218        self.local_logging = None
    215219
    216220        #state:
    217221        self._focused = None
     
    271275        self.client_supports_cursors = opts.cursors
    272276        self.client_supports_bell = opts.bell
    273277        self.client_supports_sharing = opts.sharing
     278        self.client_supports_remote_logging = opts.remote_logging
    274279
    275280        #until we add the ability to choose decoders, use all of them:
    276281        #(and default to non grahics card csc modules if not specified)
     
    12311236        if not XpraClientBase.parse_server_capabilities(self):
    12321237            return  False
    12331238        c = self.server_capabilities
     1239        #enable remote logging asap:
     1240        if self.client_supports_remote_logging and c.boolget("remote-logging"):
     1241            log.info("enabled remote logging, see server log file for output")
     1242            self.local_logging = set_global_logging_handler(self.remote_logging_handler)
    12341243        if not self.session_name:
    12351244            self.session_name = c.strget("session_name", "")
    12361245        set_application_name(self.session_name or "Xpra")
     
    13921401            self.tray.ready()
    13931402
    13941403
     1404    def remote_logging_handler(self, log, level, msg, *args, **kwargs):
     1405        #prevent loops (if our send call ends up firing another logging call):
     1406        if self.in_remote_logging:
     1407            return
     1408        self.in_remote_logging = True
     1409        try:
     1410            self.send("logging", level, msg % args)
     1411            exc_info = kwargs.get("exc_info")
     1412            if exc_info:
     1413                for x in traceback.format_tb(exc_info[2]):
     1414                    self.send("logging", level, x)
     1415        except Exception, e:
     1416            import logging
     1417            self.local_logging(logging.WARNING, "failed to send logging packet: %s" % e)
     1418        finally:
     1419            self.in_remote_logging = False
     1420
    13951421    def dbus_call(self, wid, bus_name, path, interface, function, reply_handler=None, error_handler=None, *args):
    13961422        if not self.server_dbus_proxy:
    13971423            log.error("cannot use dbus_call: this server does not support dbus-proxying")
  • xpra/log.py

     
    9090    default_level = level
    9191
    9292
     93#this allows us to capture all logging and redirect it:
     94def standard_logging(log, level, msg, *args, **kwargs):
     95    #this is just the regular logging:
     96    log(level, msg, *args, **kwargs)
     97
     98global_logging_handler = standard_logging
     99
     100def set_global_logging_handler(h):
     101    global global_logging_handler
     102    saved = global_logging_handler
     103    global_logging_handler = h
     104    return saved
     105
     106
    93107KNOWN_FILTERS = ["auth", "cairo", "client", "clipboard", "codec", "loader", "video",
    94108                 "score", "encoding", "scaling", "subregion", "regiondetect", "regionrefresh", "refresh", "compress", "mouse",
    95109                 "error", "verbose",
     
    167181    def log(self, level, msg, *args, **kwargs):
    168182        if kwargs.get("exc_info") is True:
    169183            kwargs["exc_info"] = sys.exc_info()
    170         self.logger.log(level, msg, *args, **kwargs)
     184        global global_logging_handler
     185        global_logging_handler(self.logger.log, level, msg, *args, **kwargs)
    171186
    172187    def __call__(self, msg, *args, **kwargs):
    173188        if self.debug_enabled:
  • xpra/scripts/config.py

     
    311311                    "mdns"              : bool,
    312312                    "swap-keys"         : bool,
    313313                    "start-new-commands": bool,
     314                    "remote-logging"    : bool,
    314315                    #arrays of strings:
    315316                    "encodings"         : list,
    316317                    "video-encoders"    : list,
     
    404405                    "exit-with-children": False,
    405406                    "exit-with-client"  : False,
    406407                    "start-new-commands": False,
     408                    "remote-logging"    : sys.platform.startswith("win") or sys.platform.startswith("darwin"),
    407409                    "exit-ssh"          : True,
    408410                    "opengl"            : OPENGL_DEFAULT,
    409411                    "mdns"              : False,
  • xpra/scripts/main.py

     
    445445    group.add_option("--sharing", action="store", metavar="yes|no",
    446446                      dest="sharing", default=defaults.sharing,
    447447                      help="Allow more than one client to connect to the same session. Default: %s." % enabled_str(defaults.sharing))
     448    group.add_option("--remote-logging", action="store", metavar="yes|no",
     449                      dest="remote_logging", default=defaults.remote_logging,
     450                      help="Forward all the client's log output to the server. Default: %s." % enabled_str(defaults.remote_logging))
    448451    if has_sound_support:
    449452        legacy_bool_parse("speaker")
    450453        group.add_option("--speaker", action="store", metavar="on|off|disabled",
  • xpra/server/server_base.py

     
    1616focuslog = Logger("focus")
    1717commandlog = Logger("command")
    1818soundlog = Logger("sound")
     19clientlog = Logger("client")
    1920
    2021from xpra.keyboard.mask import DEFAULT_MODIFIER_MEANINGS
    2122from xpra.server.server_core import ServerCore
     
    9798        self.dbus_helper = None
    9899        self.exit_with_children = False
    99100        self.start_new_commands = False
     101        self.remote_logging = False
    100102        self.env = []
    101103        self.child_reaper = ChildReaper(self.reaper_exit)
    102104        self.send_pings = False
     
    178180        self.supports_dbus_proxy = opts.dbus_proxy
    179181        self.exit_with_children = opts.exit_with_children
    180182        self.start_new_commands = opts.start_new_commands
     183        self.remote_logging = opts.remote_logging
    181184        self.env = parse_env(opts.env)
    182185        self.send_pings = opts.pings
    183186        self.notifications_forwarder = None
     
    417420            "set-cursors":                          self._process_set_cursors,
    418421            "set-notify":                           self._process_set_notify,
    419422            "set-bell":                             self._process_set_bell,
     423            "logging":                              self._process_logging,
    420424            "command_request":                      self._process_command_request,
    421425                                          }
    422426        self._authenticated_ui_packet_handlers = self._default_packet_handlers.copy()
     
    877881                     "key_repeat_modifiers" : True})
    878882        if server_source.wants_features:
    879883            capabilities["clipboard"] = self._clipboard_helper is not None and self._clipboard_client == server_source
     884            capabilities["remote-logging"] = self.remote_logging
    880885        if self._reverse_aliases and server_source.wants_aliases:
    881886            capabilities["aliases"] = self._reverse_aliases
    882887        if server_cipher:
     
    884889        server_source.hello(capabilities)
    885890
    886891
     892    def _process_logging(self, proto, packet):
     893        assert self.remote_logging
     894        level, msg = packet[1:3]
     895        for x in msg.splitlines():
     896            clientlog.log(level, x)
     897
    887898    def _process_command_request(self, proto, packet):
    888899        """ client sent a command request through its normal channel """
    889900        assert len(packet)>=2, "invalid command request packet (too small!)"