Skip to main content

8 posts tagged with "logging"

logging tag description

View All Tags

The Right Way to Print Stack Traces in Python

· 8 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

🖨️ The Right Way to Print Stack Traces in Python

In Python, displaying the stack trace (or traceback) is essential for debugging. It provides a historical record of all function calls leading up to the point where an exception occurred. However, simply using print() within an except block is insufficient and incorrect.

This article details the correct methods for capturing, formatting, and logging the stack trace, emphasizing the difference between developer debugging and production logging.

Linking Logs Across Python Microservices(Distributed Tracing)

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

🔗 Distributed Tracing: Linking Logs Across Python Microservices

In modern microservices architectures, a single user request might flow through an API Gateway, an authentication service, a business logic service, and several data services. While structured logging makes each service's log output clean, it doesn't automatically connect the dots.

Distributed Tracing is the operational practice of adding unique identifiers to every log and header related to a single request, allowing you to reconstruct the entire request path across all services.

Python Logging Best Practices: The Expert's Handbook

· 9 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

⭐ The Expert's Handbook: Python Logging Best Practices

Logging is not just about tracing execution; it's about creating an intelligent, observable, and auditable application. A truly experienced software engineer approaches Python logging with a strategic mindset, treating log data as a primary source of truth for operations and debugging.

This guide outlines the critical best practices, complete with detailed code examples, to elevate your Python logging from simple print statements to a powerful operational asset.

Structured Logging in Python: The Key to Observability

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

🪵 Structured Logging in Python: The Key to Observability

While the logging module is powerful, its default output is unstructured plain text, making it difficult for tools like ELK Stack or Splunk to search, aggregate, and analyze messages efficiently. Structured logging solves this by outputting logs in a standard format (usually JSON) where every event detail is an easily parsable key-value pair.

This article details how to integrate structured logging into a Python application using the popular library python-json-logger and how to leverage it for operational insight.

Python Logging to File: A Comprehensive Guide

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

While printing logs to the console (stdout or stderr) is useful during development, directing logs to a file is mandatory for production environments. File logging provides a persistent record of application events, crucial for debugging, auditing, and long-term monitoring.

The Python logging module manages file output through File Handlers. This guide covers the simplest setup, advanced rotation, and common configuration patterns.

Python logging basicconfig format and examples

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

The logging.basicConfig() function is the easiest way to perform basic setup for the Python logging module. It sets the configuration for the root logger, which is the parent of all other loggers in your application.

This function is ideal for simple scripts, development environments, and applications where you only need a single, global logging configuration.

Python Logging Levels Enum Usage

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

While Python's built-in logging module uses integer constants (logging.DEBUG, logging.INFO, etc.) for log levels, modern Python practice encourages using the enum.Enum class for defining symbolic names, especially for configurations and custom values.

Using an Enum to wrap or reference standard logging levels significantly enhances code readability, prevents hard-to-debug typos, and aids type checking when passing levels as function arguments.

Everything You Need to Know About Python Logging Levels

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Logging is a critical tool for debugging, monitoring, and auditing applications. Unlike simple print() statements, Python's built-in logging module allows you to categorize messages by severity. This categorization is done using Logging Levels, which are numerical constants that determine which messages are recorded and which are ignored.

Understanding and correctly configuring logging levels is essential for running a robust production system.