Gustavo J. A. M. Carneiro wrote:
A Qua, 2004-06-16 ās 23:32, Tim Newsham escreveu:

Hi,  Is there any way to set the log handler in pygtk?  I couldn't
find any.  I did notice a previous related thread on
"turning tk warnings into exceptions."   I am interested
in altering the default warning logging mechanism.  Currently
under windows it forces a console window to open up to
emit these warnings.  I know that ideally the code would
be warning free, but I still get occasional harmless warnings
from gtk and glade.


  I think pygtk should install a log handler to turn all log messages
into python warnings.  Then, the pygtk programmer may use the standard
'warnings' module to do whatever he wishes to such warnings: hide them,
turn them to exceptions, show in a text/list widget, etc.

  If you are interested in this, you should open a bug report in
bugzilla.gnome.org, product pygtk, type enhancement.  A patch will speed
up the bug progress, but otherwise I will eventually do this, but it may
take some time.

I think that maybe the Python 'logging' module would be a better choice than Python warnings.


   http://docs.python.org/lib/module-logging.html

The different levels of g_log would be translated into the equivalent Python logging levels as follows:

  G_LOG_LEVEL_ERROR      logging.CRITICAL
  G_LOG_LEVEL_CRITICAL   logging.ERROR
  G_LOG_LEVEL_WARNING    logging.WARNING
  G_LOG_LEVEL_MESSAGE    25 (between WARNING and INFO)
  G_LOG_LEVEL_INFO       logging.INFO
  G_LOG_LEVEL_DEBUG      logging.DEBUG

The transposition of meanings for "critical" and "error" is unfortunate, but I guess we could live with it. Handling fatal G_LOG_LEVEL_ERROR messages may not be useful anyway.

A heirachy of loggers would be created, with something like 'glog' at the top, and a child logger for each log domain, i.e.:

   'glog.Gtk', 'glog.GLib', 'glog.Pango', etc.

We would also need to define a few useful gtk-related logging.Handler classes, such as TextBufferHandler, ListStoreHandler, etc. I think that all of this should go into a module called 'glog'. If anyone else likes this idea I could try putting together an initial version of such a module.

--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to