Logging for the lazy: Python library makes logging simple
Why do you have to go and make things so complicated? Keep it simple! For Python users, Loguru provides an easier, pain-free logging experience. Let’s explore this library and see how it can help even the laziest of us.
Sometimes the best solution is to keep things simple. One library holds true to this helpful mantra. Loguru is a Python library for logging and its description on GitHub reads “Python logging made (stupidly) simple“. Designed by Delgan on GitHub, this project has already received its fair share of stars and forks.
How simple and pain-free? Let’s take a lesson from the guru and see.
The guru is in
From the project’s GitHub repo:
Did you ever feel lazy about configuring a logger and used print() instead?… I did, yet logging is fundamental to every application and eases the process of debugging. Using Loguru you have no excuse not to use logging from the start, this is as simple as from loguru import logger.
Also, this library is intended to make Python logging less painful by adding a bunch of useful functionalities that solve caveats of the standard loggers. Using logs in your application should be an automatism, Loguru tries to make it both pleasant and powerful.
The concept of “automate everything!” is one of the great tenants about this library. It streamlines Python logging.
First of all, a key concept in keeping a library simple are ready to use, out of the box features. Since Loguru comes pre-configured, it’s like unwrapping a toy on your birthday with the batteries already included!
Out of the box, Loguru outputs to
Python logging made simple
While not an exhaustive list, here are some other features of Loguru:
- Colors! Add color markups to your log. (Based off of python-ansimarksup)
- Customize levels. Add new levels with the
add()function is multi-purpose. It is used for adding a handler, setting up log formatting, filtering messages and setting levels.
- Bloat-free, better datetime handling: Less bloat compared to standard logging
- Suitable for scripts and libraries: Use Loguru from inside a library
- Compatible with standard logging
- Customizable defaults
- Alert notifications: When paired with the
notifierslibrary (on GitHub here, must be installed separately) you can receive e-mail notifications when your program fails, or any other kinds of error alerts you choose.
- Identify problems in your code with fully descriptive exceptions
- Asynchronous, Thread-safe, Multiprocess-safe
Setting up & future plans
Is this simple logging library for you? Read this thread on the r/Python subreddit for reactions, reviews, and feedback.
Installation is done through pip install loguru.
View the Loguru change log here. The most recent Python version to receive support is Python 3.5 (and support for PyPy).
This update arrived on December 16, 2018. Since the developer has added recent updates, can we assume that the future holds more goodies and support?
On GitHub, the developer alludes to an “upcoming release” where “Loguru’s critical functions will be implemented in C for maximum speed”. So, a future update will hopefully make Loguru faster than built-in logging! In the changelog, we see a teaser regarding an unreleased feature: “Fix race condition permitting to write on a stopped handler”.