1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Is there a way to print incremental time instead of absolute time with Python logging

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    When using Python logging, asctime is very handy in looking at the hotspots in code. However, I have to decode or post-process the log to show incremental time taken between each log message.

    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')


    Is there a way to print incremental time instead?

    I understand logging is meant to handle parallel threads etc., so incremental may not make much sense, but it helps a lot in simple cases.

    What I get now

    2024-09-13 12:37:19,981 - INFO - Got a Chunk of Data in 1.662097 seconds
    2024-09-13 12:37:19,989 - INFO - Processed the Chunk in 0.008471 seconds
    2024-09-13 12:37:19,993 - INFO - Optimized the Data in 0.002940 seconds


    What I am looking for

    1.662097 - INFO - Got a Chunk of Data in 1.662097 seconds
    0.008471 - INFO - Processed the Chunk in 0.008471 seconds
    0.002940 - INFO - Optimized the Data in 0.002940 seconds


    Or something similar

    Continue reading...

Compartilhe esta Página