
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.
English | 한국어
pyhunt.mp4

- 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.
pip install pyhunt
uv add pyhunt
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.
See more examples in the examples folder.
from pyhunt import trace
@trace
def test(value):
return value
@trace
async def test(value):
return value
@trace
class MyClass:
def first_method(self, value):
return value
def second_method(self, value):
return value
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>
Prompt: "Modify the code according to the logging rules."
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.")
You can manage log levels and other settings using the hunt
command.
hunt [options]
--debug
: DEBUG level (most detailed)--info
: INFO level--warning
: WARNING level--error
: ERROR level--critical
: CRITICAL level--root
: Sets theROOT_DIR
environment variable to the current directory.--repeat <count>
: Sets theHUNT_MAX_REPEAT
environment variable to the specified count. (Log repetition limit)
If no option is specified, the default is DEBUG
.
pyhunt
supports the following environment variables through the .env
file:
HUNT_LEVEL
: Sets the log level (DEBUG, INFO, WARNING, ERROR, CRITICAL). Default isDEBUG
.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
orFalse
). Default isTrue
.ROOT_DIR
: Sets the base directory for log output. Displays paths more accurately.