Changeset 101918 in vbox
- Timestamp:
- Nov 7, 2023 9:44:49 AM (15 months ago)
- Location:
- trunk/src/libs/xpcom18a4/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/python/__init__.py
r59798 r101918 90 90 Exception.__init__(self, errno, *args, **kw) 91 91 92 # Logging support - setup the 'xpcom' logger to write to the Mozilla93 # 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. 94 94 # Environment variables supports: 95 95 # PYXPCOM_LOG_FILE=filename - if set, used instead of sys.stderr. … … 97 97 # constant (eg, 'debug', 'error') 98 98 # 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. 100 100 import logging 101 class ConsoleServiceStream:102 # enough of a stream to keep logging happy103 def flush(self):104 pass105 def write(self, msg):106 import xpcom._xpcom as _xpcom107 _xpcom.LogConsoleMessage(msg)108 def close(self):109 pass110 111 101 def setupLogging(): 112 102 import os 113 103 if sys.version_info[0] <= 2: 114 104 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't119 # 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" style122 # handler and update its lock123 if sys.version_info[0] <= 2:124 if type(hdlr.lock) == thread.LockType:125 hdlr.lock = threading.RLock()126 105 127 logger.addHandler(hdlr)128 # The console handler in mozilla does not go to the console!?129 106 # Add a handler to print to stderr, or optionally a file 130 107 # PYXPCOM_LOG_FILE can specify a filename … … 171 148 # Cleanup namespace - but leave 'logger' there for people to use, so they 172 149 # don't need to know the exact name of the logger. 173 del ConsoleServiceStream,logging, setupLogging150 del logging, setupLogging -
trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
r90537 r101918 551 551 } 552 552 553 // Writes a message to the console service. This could be done via pure554 // Python code, but is useful when the logging code is actually the555 // xpcom .py framework itself (ie, we don't want our logging framework to556 // 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 worth568 // the warning, and not worth reporting an error to Python about - its569 // log handler would just need to catch and ignore it.570 // And as this is only called by this logging setup, any messages should571 // 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 579 553 #ifdef VBOX 580 554 … … 740 714 {"GetSpecialDirectory", PyGetSpecialDirectory, 1}, 741 715 {"AllocateBuffer", AllocateBuffer, 1}, 742 {"LogConsoleMessage", LogConsoleMessage, 1, "Write a message to the xpcom console service"},743 716 {"MakeVariant", PyXPCOMMethod_MakeVariant, 1}, 744 717 {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1},
Note:
See TracChangeset
for help on using the changeset viewer.