How to use logging in an extension?

Hello, I need to manipulate log files via my 3d slicer extension.

I tried with the logging library (without success).
Example:

import logging

logging.basicConfig(
    filename=r'D:\FEALINX\Extension_Pack\compare_segment\segment\logs\Compare_Segment.log',
    encoding='utf-8',
    level=logging.DEBUG,
    format='%(process)d--%(asctime)s-%(levelname)s-%(message)s'
)

logging.info('This is a warning.')

Do you have any information that could help me?

Thanks a lot for your help !

A default Python logger is already configured allows you to see all kinds of errors (coming from Python, VTK, ITK, Qt, CTK, etc.) at one place, giving you a clear picture of what is happening in the application. In Slicer-5.2 and later these logs also appear in the Python console (you can adjust the Python console log level in application settings / Python). If you change the default logger configuration then you might make some Python logs not show up in the application log, which may make user support/troubleshooting a bit more difficult.

For debugging on your own computer, I would highly recommend using a Python debugger instead of relying on logging - see setup instructions here.

Overall, we rarely see a need for custom Python logging, but if you find that you need it anyway then you should be able to set it up. You can see how to make the logs show up in various places (Python console, application log, etc.) here, where the default Python logger is set up.