Some text some message..
Back Logging Module in Python: import logging 26 Jul, 2025

Yes, in Python, the standard and most widely used library for logging is the built-in logging module. You don’t need to install anything — it comes with Python by default.

✅ Importing Logging

import logging

🔧 Basic Configuration Example

import logging

logging.basicConfig(level=logging.INFO)
logging.info("This is an info message")
logging.warning("This is a warning")
logging.error("This is an error message")

💡 Key Features of logging Module

  • Multiple severity levels: DEBUG, INFO, WARNING, ERROR, CRITICAL

  • Logging to console or file

  • Custom formatting

  • Log rotation using logging.handlers


🛠️ Advanced Example: Logging to a File with Format

import logging

logging.basicConfig(
    filename='app.log',
    filemode='a',  # append mode
    level=logging.DEBUG,
    format='%(asctime)s - %(levelname)s - %(message)s'
)

logging.debug("Debug message")
logging.info("Info message")
logging.error("Error message")

🧰 Alternative Libraries (Advanced Use)

If you need more advanced logging features, consider:

  1. loguru
    A modern and easier-to-use alternative to logging.

    pip install loguru
    
    from loguru import logger
    logger.info("This is a loguru info message")
    
  2. structlog (for structured logging, often used in async apps or microservices)