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(uselogger.info(), etc.).
From PyPI:
pip install indentloggerFrom GitHub:
pip install git+https://github.com/gaviral/indentlogger.gitDevelopment setup:
git clone https://github.com/gaviral/indentlogger.git
cd indentlogger
pip install -e .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.
style:SIMPLE,DASHED_BOX,NO_PIPES, orDISABLED.level: Overall logging threshold (e.g.,logging.INFO,logging.DEBUG).auto_log_level: Logging level for function entry/exit calls.dash_line_length: (default60) ASCII-box width inDASHED_BOXmode.stream: Output stream (sys.stdout, file, etc.).
Example:
logger.configure(style=LogStyle.SIMPLE, level=logging.INFO, auto_log_level=logging.DEBUG)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
'-----------------------------------------------------------
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")- SIMPLE – Minimal indentation with
│, no explicit end line. - DASHED_BOX – ASCII boxes (top line:
.--fun(...):, bottom line:'--...). - NO_PIPES – Same as SIMPLE but uses spaces instead of
│. - DISABLED – Skips all logging entirely.
fun1():
│ fun2(num=123):
│ │ Inside fun2
│ fun3():
│ │ Inside fun3
.--fun1():--------------------------------------
|
│ .--fun2(num=123):---------------------------
│ |
│ │ Inside fun2
│ |
│ '-------------------------------------------
│ .--fun3():----------------------------------
│ |
│ │ Inside fun3
│ |
│ '-------------------------------------------
|
'-----------------------------------------------
fun1():
fun2(num=123):
Inside fun2
fun3():
Inside fun3
No output at all.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT. Free to use, extend, and modify. See the LICENSE file for details.
- GitHub: https://github.com/gaviral/indentlogger
- Bug Reports: https://github.com/gaviral/indentlogger/issues