Skip to main content

An advanced indentation-based logging library for Python. Easily trace and format function calls with nested ASCII boxes or minimal pipes.

Project description

indentlogger

indentlogger is an indentation-based logging library for Python, offering:

  • Function-call tracing with nested indentation or ASCII-box style.
  • Automatic decoration for modules/classes (no manual decorators needed).
  • Optional replacement for print (use logger.info(), etc.).

Installation

From PyPI (once published):

pip install indentlogger

Quick Start

import logging
from indentlogger import IndentLogger, LogStyle

logger = IndentLogger()
logger.configure(
    style=LogStyle.DASHED_BOX, 
    level=logging.DEBUG,         # integer constant from logging
    auto_log_level=logging.DEBUG # function entry/exit logs
)

@logger.log_entry_exit
def sample_function(x):
    logger.info(f"Inside sample_function with x={x}")

sample_function(42)

When run, you’ll see ASCII “boxes” showing function entry, your log, and function exit.

Configuration

  • style: SIMPLE, DASHED_BOX, NO_PIPES, or DISABLED.
  • level: Overall logging threshold (e.g., logging.INFO, logging.DEBUG).
  • auto_log_level: Logging level for function entry/exit calls.
  • dash_line_length: (default 60) ASCII-box width in DASHED_BOX mode.
  • stream: Output stream (sys.stdout, file, etc.).

Example:

logger.configure(style=LogStyle.SIMPLE, level=logging.INFO, auto_log_level=logging.DEBUG)

Automatic Logging (No Decorators)

Auto-Log an Entire Module

If you don’t want to decorate each function, let the logger scan and decorate everything for you:

import logging
from indentlogger import IndentLogger, LogStyle

logger = IndentLogger()
logger.configure(style=LogStyle.DASHED_BOX, level=logging.DEBUG)

def fun1():
    logger.info("Hello from fun1")
    fun2(x=42)

def fun2(x):
    logger.debug(f"fun2 got x={x}")
    fun3(y=100)
    fun4()

def fun3(y):
    logger.info(f"fun3 got y={y}")

def fun4():
    logger.info("Hello from fun4")

def fun5():
    logger.info("Hello from fun5")

# No manual decorators here!
if __name__ == "__main__":
    # This decorates all top-level functions except those starting with '_'
    logger.auto_log_module(__name__)
    fun1()
    fun5()

Output:

.--fun1():--------------------------------------------------
|
│   Hello from fun1
│   .--fun2(x=42):------------------------------------------
│   |
│   │   fun2 got x=42
│   │   .--fun3(y=100):-------------------------------------
│   │   |
│   │   │   fun3 got y=100
│   │   '---------------------------------------------------
│   │   .--fun4():------------------------------------------
│   │   |
│   │   │   Hello from fun4
│   │   '---------------------------------------------------
│   '-------------------------------------------------------
'-----------------------------------------------------------
.--fun5():--------------------------------------------------
|
│   Hello from fun5
'-----------------------------------------------------------

Auto-Log a Class

class DataProcessor:
    def process(self, data):
        logger.info(f"Processing data={data}")
        return data * 2

# Decorate all public methods
logger.auto_log_class(DataProcessor)

dp = DataProcessor()
dp.process("Hello")

Styles

  1. SIMPLE – Minimal indentation with , no explicit end line.
  2. DASHED_BOX – ASCII boxes (top line: .--fun(...):, bottom line: '--...).
  3. NO_PIPES – Same as SIMPLE but uses spaces instead of .
  4. DISABLED – Skips all logging entirely.

Example Outputs

SIMPLE

fun1():
│ fun2(num=123):
│ │ Inside fun2
│ fun3():
│ │ Inside fun3

DASHED_BOX

.--fun1():--------------------------------------
|
│   .--fun2(num=123):---------------------------
│   |
│   │   Inside fun2
│   |
│   '-------------------------------------------
│   .--fun3():----------------------------------
│   |
│   │   Inside fun3
│   |
│   '-------------------------------------------
|
'-----------------------------------------------

NO_PIPES

fun1():
  fun2(num=123):
    Inside fun2
  fun3():
    Inside fun3

DISABLED

No output at all.

License

MIT. Free to use, extend, and modify.

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

indentlogger-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

indentlogger-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file indentlogger-0.1.0.tar.gz.

File metadata

  • Download URL: indentlogger-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for indentlogger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee4b92d22aa45ad416ab517bedc0d3c2ee97ab281f77cbda3b14a22463fe3025
MD5 df02fcf049a8192e3eeb0c98090ac74d
BLAKE2b-256 a3b3539024e2080c2c806803cbf416d4cede3771b77b10738267db8ca91b41ab

See more details on using hashes here.

File details

Details for the file indentlogger-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: indentlogger-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for indentlogger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb73d1ab695fc40f3e590b679464a237dc14aba9e14e4cde305bcad28bc984be
MD5 cae1154e83c96f9143eee445401dd796
BLAKE2b-256 e8e762459b445b89fa3eb2a8a0746f99ca50619019e1ee6d1e9577958ce00330

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