On 10/30/2012 11:53 AM, corrado maurini wrote: > Johan, > > Thanks a lot for taking care of this. Well, we see how far it goes :) > If redirecting ostream through python is too difficult, for the specific > case a possible alternative can be to have a function similar to > list_timings(), but giving a dolfin Table as output. Sure that would be pretty trivial to implement, and we have them same analogy for list_linear_algebra_backends and linear_algebra_backends, where the later return a list of strings instead of printing them to the screen. So adding a free function called timings would fit fine here. > Then the Table is a python object and one can use the associated methods > to access data or print it out (event in latex format!). Good point! > I have not done this directly because I do not if this may conflict with > your general design principles for the logger. Should work just fine. Johan > Corrado > > Le 30 oct. 2012 à 11:02, Marco Morandini a écrit : > >> On 10/30/2012 08:00 AM, Johan Hake wrote: >>> Marco, what would the syntax be for adding a file as the log output. Is >>> it possible to add an already existing file pointer or just the file >>> name as a string? This would be the ultimate solution as we then can >>> merge the two log streams from dolfin and logging dependent python >>> modules such as UFL. >>> >>> My boost python skills are really limited so following the inner >>> workings of this small file is hard for me... >>> >> >> In my old code (where everything is wrapped with boost) >> >> after >> >> fileout = ostream(cout_buf()) >> >> fileout will point to std::cout, >> >> and after >> >> fileout = ostream('new_file_name.txt') >> >> fileout will point to a newly opened ofstream. >> >> Then, fileout can be passed to any wrapped c++ function that >> has an std::ostream & argument. >> >> I.e., if I have this c++ function >> >> void DxOutput(std::ostream & out, const MyFloat t); >> >> and I wrap it as >> >> BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ofstream_open_overloads, >> std::ofstream::open, 1, 2); >> BOOST_PYTHON_MODULE_INIT(_python_util) >> { >> .... >> >> the wrapping code I've attached >> >> .... >> >> python::def("DxOutput", DxOutput); >> } >> >> in python I can do >> >> t=0.01 >> fileout = ostream('new_file_name.txt') >> DxOutput(fileout, t) >> >> if I want to write with DxOutput into new_file_name.txt, >> >> or >> >> fileout = ostream(cout_buf()) >> DxOutput(fileout, t) >> >> If I want DxOuptut's output on the screen. >> >> Note however that I can't write directly from python into fileout >> (and I fear that this is what you are looking for :( . >> At least, I've not even tried to do it (perhaps one should start >> extractig the file descriptor, as explained here: >> >> http://www.ginac.de/~kreckel/fileno/ >> >> ) >> >> Or >> http://stackoverflow.com/questions/2378005/c-iostreams-and-python >> >> >> Hope this helps. >> >> -- >> You received this bug notification because you are a member of DOLFIN >> Team, which is subscribed to DOLFIN. >> https://bugs.launchpad.net/bugs/1072694 >> >> Title: >> list_timings() cannot be redirected to a file or a variable in python >> >> Status in DOLFIN: >> Confirmed >> >> Bug description: >> In python it is not possible to redirect the output of list_timings() >> to a file. >> >> set_output_stream(std::ostream& out) in log.ccp is not working in >> python because of problems in wrapping cpp ostream >> >> see also https://answers.launchpad.net/dolfin/+question/211271 >> >> To manage notifications about this bug go to: >> https://bugs.launchpad.net/dolfin/+bug/1072694/+subscriptions >