Search code examples
pythonloggingbunyan

More precise time for python-bunyan logger?


I've been using bunyan logger for nodejs, so when I had to program in python again I went out and found a compatible logger for python.

https://github.com/Sagacify/logger-python

https://pypi.python.org/pypi/bunyan/0.1.2

The problem is, this formatter only log time to second but I need at least millisecond precision. What would be the easiest way of achieving this?


Solution

  • Milliseconds would be a bit of a hack, but you can add microseconds really easily.

    Here:

    https://github.com/Sagacify/logger-python/blob/master/bunyan/formatter.py#L106

    You would need to replace "%Y-%m-%dT%H:%M:%SZ" by "%Y-%m-%dT%H:%M:%S%fZ"

    Notice the added %f . (I'm actually the maintainer of saga-logger and we should be doing this as well but I haven't had the time to do it as of now.)