Skip to content

Instantly share code, notes, and snippets.

@Invisi
Last active October 28, 2020 22:38
Show Gist options
  • Save Invisi/6f1f2c55e5dc768e7b20e959def729e6 to your computer and use it in GitHub Desktop.
Save Invisi/6f1f2c55e5dc768e7b20e959def729e6 to your computer and use it in GitHub Desktop.
Ideolog config for python's logging

Message pattern

^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\s-\s(\w+)\s-\s([\w.]+)\s-\s(.+)

Message start pattern

^\d

Time format

yyyy-MM-dd HH:mm:ss

Capture groups

  • Time: 1
  • Severity: 3
  • Category: 2

logging init

fmt = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s", "%Y-%m-%d %H:%M:%S")
logging.getLogger().setFormatter(fmt)
# or simply
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S",
    handlers=[logging.StreamHandler(), logging.FileHandler("stuff.log")],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment