Skip to main content

Lightweight Python logging tool for visual call tracing, tree-structured colored logs, and easy debugging with a simple decorator. Optimized for both standard and AI-generated codebases.

Project description

pyhunt_logo

pyhunt

pyhunt is a lightweight logging tool that visually represents logs for quick structural understanding and debugging.
Simply add a decorator to your functions, and all logs are automatically traced and displayed in your terminal.

PyPI version Python Versions

English | 한국어


https://github.com/user-attachments/assets/3d4389fe-4708-423a-812e-25f2e7200053

pyhunt_description

Features

  • Automatic Function/Method Call Tracing: Automatically records the flow of synchronous/asynchronous functions and classes with a single @trace decorator.
  • Rich Colors and Tree-Structured Logs: Enhances readability with color and indentation based on call depth.
  • Multiple Log Levels Supported: DEBUG, INFO, WARNING, ERROR, CRITICAL.
  • Set Log Level via CLI: Manage and store HUNT_LEVEL in a .env file.
  • Optimized for AI Workflows: Easily trace code generated by AI.
  • Detailed Exception Information: Includes call arguments, location, and stack trace on exceptions.

Installation

Install with pip

pip install pyhunt

Install with uv

uv add pyhunt

Quick Start

1. Set Up and Manage Environment Variable File

You can set up and manage the .env file by running the hunt command.

hunt

Executing the above command sets HUNT_LEVEL=DEBUG and ROOT_DIR to the current directory in the .env file.

2. Apply @trace to Functions or Classes

See more examples in the examples folder.

Basic Example

from pyhunt import trace

@trace
def test(value):
    return value

Asynchronous Function

@trace
async def test(value):
    return value

Class

@trace
class MyClass:
    def first_method(self, value):
        return value

    def second_method(self, value):
        return value

Using with AI

Rule Setup

Add the following rules to .cursorrules, .clinerules, or .roorules:

<logging-rules>

**Import:** Import the decorator with `from pyhunt import trace`.
**Tracing:** Use the `@trace` decorator to automatically log function calls and execution times.
**Avoid `print()`:** Do not use the `print()` function.
**Exception Handling:** Use `try`/`except Exception as e: raise e` blocks to maintain traceback.

</logging-rules>

Modifying Existing Codebase

Prompt: "Modify the code according to the logging rules."

Logger Usage

The logger interface is recommended for use only in important sections.
Most actions are traced via @trace, and excessive use may reduce readability.

from pyhunt import logger

logger.debug("This is a debug log.")
logger.info("This is an info log.")
logger.warning("This is a warning log.")
logger.error("This is an error log.")
logger.critical("This is a critical log.")

CLI Usage

You can manage log levels and other settings using the hunt command.

hunt [options]

Supported Options

  • --debug : DEBUG level (most detailed)
  • --info : INFO level
  • --warning : WARNING level
  • --error : ERROR level
  • --critical : CRITICAL level
  • --root : Sets the ROOT_DIR environment variable to the current directory.
  • --repeat <count> : Sets the HUNT_MAX_REPEAT environment variable to the specified count. (Log repetition limit)
  • --color <true|false> : Enable or disable color output in logs.
  • --log-file [file] : Set log file output. If no file is specified, defaults to .pyhunt.log.

If no option is specified, the default is DEBUG.

Environment Variables

pyhunt supports the following environment variables through the .env file:

  • HUNT_LEVEL: Sets the log level (DEBUG, INFO, WARNING, ERROR, CRITICAL). Default is DEBUG.
  • HUNT_MAX_REPEAT: The number of times the same log is displayed when repeated. Default is 3.
  • ELAPSED: Sets whether to display function execution time in logs (True or False). Default is True.
  • HUNT_COLOR: Sets whether to enable color output (True or False). Default is True.
  • HUNT_LOG_FILE: Sets the file path for log output. If not specified, logs are only displayed in the terminal.
  • ROOT_DIR: Sets the base directory for log output. Displays paths more accurately.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhunt-1.2.0.tar.gz (151.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhunt-1.2.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file pyhunt-1.2.0.tar.gz.

File metadata

  • Download URL: pyhunt-1.2.0.tar.gz
  • Upload date:
  • Size: 151.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for pyhunt-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d3c8b4407e1d075ec34ed83f1af7d620dd22dc2618ee976b31c5d6d1023ba5c2
MD5 d3290fe8e4ee0eae596784183e77a732
BLAKE2b-256 effd92bf65c3dcd21a30b7e453c1ce78fdad3b5cc42e2e11ad0654893a912d3d

See more details on using hashes here.

File details

Details for the file pyhunt-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyhunt-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for pyhunt-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7b2a7f9683658c0703944e156232544f3b861e37a05cf8d22f491c2125a2d93
MD5 833c871dbd2202f9c6c8d21aa52ce7e3
BLAKE2b-256 0b1176eb67591ec148245169d3ec125f6547f79b324b82077f48623375c62e81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page