Skip to content

Latest commit

 

History

History
75 lines (65 loc) · 8.08 KB

File metadata and controls

75 lines (65 loc) · 8.08 KB

My Python Logging Reminders


logpai/logparser

These examples are just reminders/demonstrations to help me get started on any given python script.

For a more detailed description of Python logging refer to the official manual. There is a useful diagram outlining the flow of log event information in loggers and handlers at: https://docs.python.org/3.10/howto/logging.html#logging-flow. And don't ignore the logging cookbook if you have the urge to do your own thing https://docs.python.org/3/howto/logging-cookbook.html

Approaches

  • The old print way:
def log(loglevel, component, message):
    print(f"{datetime.now(timezone('UCT'))} \
[{loglevel}] {component}: {message}", file=sys.stderr)

Then log something with:

log("INFO", __file__, f"Using important_var: {important_var}")

Install

None. These are not modules, just little code reminders.
That said, tryloguru/LogTestLoGuru.py requires pip3 install loguru --user.

What Should You Log?

See some ideas at: https://github.com/mccright/rand-notes/blob/master/Application-Logging.md

Explore later

Logparser provides a machine learning toolkit and benchmarks for automated log parsing, which is a crucial step for structured log analytics. By applying logparser, users can automatically extract event templates from unstructured logs and convert raw log messages into a sequence of structured events. The process of log parsing is also known as message template extraction, log key extraction, or log message clustering in the literature.

Additional References