fenics team mailing list archive
-
fenics team
-
Mailing list archive
-
Message #00391
Re: Logging in Python
2008/3/19, Anders Logg <logg@xxxxxxxxx>:
> On Wed, Mar 19, 2008 at 09:00:55PM +0100, Martin Sandve Alnæs wrote:
> > 2008/3/18, Anders Logg <logg@xxxxxxxxx>:
> > > On Tue, Mar 18, 2008 at 10:54:09AM -0500, Andy Ray Terrel wrote:
> > > > Matthew Knepley wrote:
> > > > > On Tue, Mar 18, 2008 at 10:34 AM, Anders Logg <logg@xxxxxxxxx> wrote:
> > > > >
> > > > >> On Sun, Mar 16, 2008 at 04:50:07PM +0100, Martin Sandve Alnæs wrote:
> > > > >> > I highly recommend that all Python projects in FEniCS use the module
> > > > >> > "logging" that comes with Python from version 2.3. It is very simple
> > > > >> > and very flexible, in particular for creating cross-module logs. For
> > > > >> > the most basic usage, look at output.py and the tests in UFL.
> > > > >> >
> > > > >> > Basic tutorial (good site for handy python modules):
> > > > >> > http://blog.doughellmann.com/2007/05/pymotw-logging.html
> > > > >> >
> > > > >> > Reference:
> > > > >> > http://docs.python.org/lib/module-logging.html
> > > > >>
> > > > >> Sounds good, but the big problem is more likely to coordinate logging
> > > > >> from C++ (DOLFIN) and Python. Is there a nice solution for this?
> > > > >>
> > > > >
> > > > > As long as whole lines are always written, and the file is line buffered, I
> > > > > think writing from two different file descriptors should be fine. The nice
> > > > > thing would be to replicate the format in C++.
> > > > >
> > > > > Matt
> > > > >
> > > > >
> > > >
> > > > Or you could just write a C api that calls into python. Is there any
> > > > reason you would be needing to log from C++ and python at the same time?
> > >
> > > Yes, when running DOLFIN from Python. We then call DOLFIN C++ code,
> > > DOLFIN Python code (not everything is done in SWIG), FFC Python code
> > > and FIAT Python code (which is quiet most of the time).
> >
> > You can subclass the "logging.Logger" class (or something similar) in
> > PyDOLFIN, simply passing the log messages to the C++ DOLFIN log
> > system. So nothing (or very little) needs to change in C++ DOLFIN.
(Maybe we want something more though, I might have oversimplified things here.)
> Then what's the point of using the logging module in PyDOLFIN, instead
> of just calling the DOLFIN log system directly?
Python libraries can't depend on the DOLFIN log system.
If UFL, FFC, SyFi, Instant, PyDOLFIN, and other non-fenics Python
projects all use the Python logging module, the end application (in
Python) can combine log output from multiple libraries into a single
log in whatever combination is wanted, and there is a single standard
way to redirect log output to screen and/or file and set logging
levels for all libraries (and submodules of libraries) independently.
--
Martin
Follow ups
References