VirtualBox

Changeset 101918 in vbox


Ignore:
Timestamp:
Nov 7, 2023 9:44:49 AM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom/python: Get rid of the log to mozilla console service code because it isn't used (and even if there is no listener ever registered for the console service anywhere so it would just go straight to /dev/null anyway), bugref:10545

Location:
trunk/src/libs/xpcom18a4/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/__init__.py

    r59798 r101918  
    9090        Exception.__init__(self, errno, *args, **kw)
    9191
    92 # Logging support - setup the 'xpcom' logger to write to the Mozilla
    93 # console service, and also to sys.stderr, or optionally a file.
     92# Logging support - setup the 'xpcom' logger to write to sys.stderr,
     93# or optionally a file.
    9494# Environment variables supports:
    9595# PYXPCOM_LOG_FILE=filename - if set, used instead of sys.stderr.
     
    9797#                           constant (eg, 'debug', 'error')
    9898# Later it may make sense to allow a different log level to be set for
    99 # the file than for the console service.
     99# the file.
    100100import logging
    101 class ConsoleServiceStream:
    102     # enough of a stream to keep logging happy
    103     def flush(self):
    104         pass
    105     def write(self, msg):
    106         import xpcom._xpcom as _xpcom
    107         _xpcom.LogConsoleMessage(msg)
    108     def close(self):
    109         pass
    110 
    111101def setupLogging():
    112102    import os
    113103    if sys.version_info[0] <= 2:
    114104        import threading, thread
    115     hdlr = logging.StreamHandler(ConsoleServiceStream())
    116     fmt = logging.Formatter(logging.BASIC_FORMAT)
    117     hdlr.setFormatter(fmt)
    118     # There is a bug in 2.3 and 2.4.x logging module in that it doesn't
    119     # use an RLock, leading to deadlocks in some cases (specifically,
    120     # logger.warning("ob is %r", ob), and where repr(ob) itself tries to log)
    121     # Later versions of logging use an RLock, so we detect an "old" style
    122     # handler and update its lock
    123     if sys.version_info[0] <= 2:
    124         if type(hdlr.lock) == thread.LockType:
    125             hdlr.lock = threading.RLock()
    126105
    127     logger.addHandler(hdlr)
    128     # The console handler in mozilla does not go to the console!?
    129106    # Add a handler to print to stderr, or optionally a file
    130107    # PYXPCOM_LOG_FILE can specify a filename
     
    171148# Cleanup namespace - but leave 'logger' there for people to use, so they
    172149# don't need to know the exact name of the logger.
    173 del ConsoleServiceStream, logging, setupLogging
     150del logging, setupLogging
  • trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

    r90537 r101918  
    551551}
    552552
    553 // Writes a message to the console service.  This could be done via pure
    554 // Python code, but is useful when the logging code is actually the
    555 // xpcom .py framework itself (ie, we don't want our logging framework to
    556 // call back into the very code generating the log messages!
    557 PyObject *LogConsoleMessage(PyObject *self, PyObject *args)
    558 {
    559         char *msg;
    560         if (!PyArg_ParseTuple(args, "s", &msg))
    561                 return NULL;
    562 
    563         nsCOMPtr<nsIConsoleService> consoleService = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
    564         if (consoleService)
    565                 consoleService->LogStringMessage(NS_ConvertASCIItoUCS2(msg).get());
    566         else {
    567         // This either means no such service, or in shutdown - hardly worth
    568         // the warning, and not worth reporting an error to Python about - its
    569         // log handler would just need to catch and ignore it.
    570         // And as this is only called by this logging setup, any messages should
    571         // still go to stderr or a logfile.
    572                 NS_WARNING("pyxpcom can't log console message.");
    573         }
    574 
    575         Py_INCREF(Py_None);
    576         return Py_None;
    577 }
    578 
    579553#ifdef VBOX
    580554
     
    740714        {"GetSpecialDirectory", PyGetSpecialDirectory, 1},
    741715        {"AllocateBuffer", AllocateBuffer, 1},
    742         {"LogConsoleMessage", LogConsoleMessage, 1, "Write a message to the xpcom console service"},
    743716        {"MakeVariant", PyXPCOMMethod_MakeVariant, 1},
    744717        {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1},
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette