Last modified: Mar 27, 2025 By Alexander Williams
How to Install Loguru in Python
Loguru is a popular logging library for Python. It simplifies logging with a clean API. This guide will show you how to install and use it.
Table Of Contents
What Is Loguru?
Loguru is an easy-to-use logging library. It requires minimal setup. It also provides powerful features like file rotation and colorized logs.
Prerequisites
Before installing Loguru, ensure you have Python installed. You can check by running python --version
in your terminal.
python --version
Python 3.9.0
If you get a ModuleNotFoundError, check our guide on solving Python module errors.
Install Loguru Using pip
The easiest way to install Loguru is via pip. Run the following command in your terminal.
pip install loguru
This will download and install the latest version. Wait for the installation to complete.
Verify Installation
After installation, verify it works. Open a Python shell and import Loguru.
from loguru import logger
logger.success("Loguru installed successfully!")
2023-10-01 12:00:00 | SUCCESS | Loguru installed successfully!
If you see a success message, Loguru is ready to use.
Basic Loguru Usage
Loguru makes logging simple. Here’s a basic example to log messages.
from loguru import logger
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning")
logger.error("This is an error")
2023-10-01 12:00:01 | DEBUG | This is a debug message
2023-10-01 12:00:01 | INFO | This is an info message
2023-10-01 12:00:01 | WARNING | This is a warning
2023-10-01 12:00:01 | ERROR | This is an error
Configure Loguru Output
You can customize where logs go. For example, save logs to a file.
from loguru import logger
logger.add("app.log") # Logs will be saved to app.log
logger.info("This will be saved to the file")
Loguru also supports rotation and retention. This keeps log files manageable.
Conclusion
Loguru is a powerful yet simple logging tool for Python. It’s easy to install and use. Follow this guide to get started quickly.
For more advanced features, check the official Loguru documentation.