Skip to main content

158 posts tagged with "python"

python 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.

Custom Classes for Python Exceptions: Extending the Error Toolkit

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

✨ Custom Classes for Python Exceptions: Extending the Error Toolkit

Defining custom exception classes is a hallmark of professional-grade Python code. Instead of relying on generic built-in exceptions (like ValueError or TypeError) for every application-specific failure, custom exceptions provide clear, unambiguous signals about why an operation failed.

This article details the necessity, structure, and best practices for creating and utilizing your own exception hierarchy.

Understanding the Python Exception Hierarchy

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

🌳 Understanding the Python Exception Hierarchy

In Python, all exceptions are organized into a strict, single-rooted hierarchy of classes. Understanding this hierarchy is not just academic; it is fundamental to writing reliable exception handlers. When you catch an exception, you are actually catching that specific class and all classes that inherit from it.

This article breaks down the core structure of the Python exception hierarchy and demonstrates how inheritance dictates the behavior of your except blocks.

Everything You Want to Know About Python Error Handling

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

🚨 Everything You Want to Know About Python Error Handling

Effective error handling is the foundation of writing robust, maintainable, and reliable Python code. It ensures that your application can gracefully manage unexpected conditions without crashing, providing clean feedback to the user or logging useful data for debugging.

This article details the comprehensive toolkit Python provides for managing errors, covering structure, best practices, and advanced techniques.

Python Exception Propagation: How Errors Travel Up the Python Call Stack

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

🔥 Exception Propagation: How Errors Travel Up the Python Call Stack

When an exception occurs deep inside a function call, the Python interpreter stops the normal flow of execution and immediately begins searching for a way to handle that exception. This search process, where the exception moves outward from the point of failure, is known as propagation.

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.