picologging
picologging copied to clipboard
Add support for %f (format microseconds) to datefmt
Closes https://github.com/microsoft/picologging/issues/184
Since libc strftime doesn't support %f specifier the implementation works it around by
- first, creating a temporary format string for strftime where %f is replaced with actual microseconds.
- passing this temporary format string to strftime
The first step is optional, it will be only invoked if %f is detected by the Formatter constructor
import picologging as logging
logging.basicConfig(format="%(levelname)s - %(asctime)s - %(name)s - %(module)s - %(message)s", datefmt="%F %T.%f")
logger = logging.getLogger()
logger.setLevel(logging.INFO)
if __name__ == '__main__':
for i in range(5):
logger.info("Hello world! %d", i)
INFO - 2024-07-23 04:15:56.170199 - root - <unknown> - Hello world! 0
INFO - 2024-07-23 04:15:56.170242 - root - <unknown> - Hello world! 1
INFO - 2024-07-23 04:15:56.170255 - root - <unknown> - Hello world! 2
INFO - 2024-07-23 04:15:56.170265 - root - <unknown> - Hello world! 3
INFO - 2024-07-23 04:15:56.170274 - root - <unknown> - Hello world! 4