picologging icon indicating copy to clipboard operation
picologging copied to clipboard

Fix asctime formatting, don't print uninitialized buffer's content (issue #203)

Open tarasko opened this issue 9 months ago • 4 comments

Closes https://github.com/microsoft/picologging/issues/203 Correctly format and print LogRecord.asctime field

Please merge this PR or https://github.com/microsoft/picologging/pull/209 where %f support in datefmt was also added.

import time
import picologging as logging

logging.basicConfig(format="%(levelname)s - %(asctime)s - %(name)s - %(module)s - %(message)s")
logger = logging.getLogger()
logger.setLevel(logging.INFO)

if __name__ == '__main__':
    for i in range(5):
        time.sleep(0.4)
        logger.info("Hello world! %d", i)
INFO - 2024-07-23 04:35:30,285 - root - <unknown> - Hello world! 0
INFO - 2024-07-23 04:35:30,685 - root - <unknown> - Hello world! 1
INFO - 2024-07-23 04:35:31,085 - root - <unknown> - Hello world! 2
INFO - 2024-07-23 04:35:31,485 - root - <unknown> - Hello world! 3
INFO - 2024-07-23 04:35:31,886 - root - <unknown> - Hello world! 4

tarasko avatar May 08 '24 22:05 tarasko