Skip to main content

8 posts tagged with "debugging"

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

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.

Dataclass AttributeError Solutions

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

The AttributeError is one of the most common exceptions in Python, indicating an attempt to access or set a class attribute that simply doesn't exist. When it occurs within the context of a @dataclass, it often points to a misunderstanding of how the decorator automatically generates methods like __init__ and __setattr__.

Here is a breakdown of the most frequent AttributeError scenarios involving dataclasses and the high-level solutions to resolve them.

Understanding Off-by-One Errors in JavaScript

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

Off-by-one errors (OBOEs) are among the most common logic bugs, even for seasoned developers. These bugs occur when a loop or operation goes one iteration too far or one iteration too short-leading to incorrect results, missed elements, or crashes.

They usually occur in:

  • Loops
  • Array indexing
  • Ranges
  • Substring operations

What is an Off-by-One Error in Python? (Explained for Kids!)

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

Have you ever counted your toys and accidentally said you had 11, but really only had 10? That’s kind of what an off-by-one error is in Python!

It’s a tiny mistake where your program counts 1 too many or 1 too few. These mistakes are super common, even for professional programmers.