3

Currently, we are using Python's vtk wrapper and also Pyvista (a more pythonist vtk wrapper).

At some parts of the process we have some log lines from .cxx files:

2022-03-17 17:21:56.031 ( 156.058s) [        4CC78740]      vtkDelaunay3D.cxx:518   WARN| vtkDelaunay3D (0x559d2b180400): 1 degenerate triangles encountered, mesh quality suspect
2022-03-17 17:21:58.045 ( 158.072s) [        4CC78740]            vtkMath.cxx:522   WARN| Unable to factor linear system
2022-03-17 17:21:58.288 ( 158.314s) [        4CC78740]      vtkDelaunay3D.cxx:518   WARN| vtkDelaunay3D (0x559d0877c080): 3 degenerate triangles encountered, mesh quality suspect

Is it possible to suppress or to manage those logs from python logging module?

Gonzalo Matheu
  • 8,984
  • 5
  • 35
  • 58
  • 2
    If they are errors then the [`pyvista.utilities.VtkErrorCatcher`](https://docs.pyvista.org/api/utilities/_autosummary/pyvista.utilities.VtkErrorCatcher.html) context manager will work, but I don't know about other kinds of output (warnings for instance). The implementation is at https://github.com/pyvista/pyvista/blob/main/pyvista/utilities/errors.py#L40 but I don't understand it enough to tell how easy it would be to extend it in case it only catches actual VTK errors. – Andras Deak -- Слава Україні Mar 17 '22 at 19:10
  • 1
    Awesome! didn't know about the VtkErrorCatcher, it will work partially for this. – Gonzalo Matheu Mar 17 '22 at 19:54
  • 1
    In the general case I've used https://stackoverflow.com/a/17954769/5067311 to suppress printing coming from the C world (for pure Python we have https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions). But that's probably overkill as long as there are other options. – Andras Deak -- Слава Україні Mar 17 '22 at 19:58

1 Answers1

6

you have the vtkLogger class to manage your logs (I know, c++ docs but VTK has a lack of python doc).

e.g.:

vtk.vtkLogger.SetStderrVerbosity(vtk.vtkLogger.VERBOSITY_OFF)
Nico Vuaille
  • 2,310
  • 1
  • 6
  • 14