Skip to content

Instantly share code, notes, and snippets.

@xhjkl
Created April 12, 2016 13:50
Show Gist options
  • Save xhjkl/26ae2f56c781fbe87dd1bd7cccbe840e to your computer and use it in GitHub Desktop.
Save xhjkl/26ae2f56c781fbe87dd1bd7cccbe840e to your computer and use it in GitHub Desktop.
Logger in about twenty lines
""" 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