Created
April 12, 2016 13:50
-
-
Save xhjkl/26ae2f56c781fbe87dd1bd7cccbe840e to your computer and use it in GitHub Desktop.
Logger in about twenty lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Logging micro-facility | |
""" | |
import os | |
from time import time, strftime, gmtime | |
def log(value=None, *formatting, **named_formatting): | |
""" Record an event | |
""" | |
if value is None: | |
value = '' | |
if isinstance(value, str): | |
value = value.format(*formatting, **named_formatting) | |
print('[{timestamp}.{ms:03} {pid:05}] {msg}'.format( | |
msg=value, | |
timestamp=strftime('%y-%m-%d %H:%M:%S', gmtime()), | |
ms=int(time() * 1000.0 % 1000), | |
pid=os.getpid())) | |
__all__ = (log,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment