Minimal color logger for Python terminals (print-compatible)
Project description
colorstreak
Minimal color logging for Python terminals. Two loggers in one package:
Logger— zero-dependency ANSI logger that works likeprint()RichLogger— feature-rich logger powered by Rich with tables, JSON, trees, benchmarks, and more
Instalacion
pip install colorstreak
Logger (basico)
ANSI puro, sin dependencias. Se siente como print().
from colorstreak import Logger
Logger.info("Servidor arriba")
Logger.warning("Cache fria")
Logger.error("No se pudo conectar")
Logger.success("Deploy OK")
Niveles disponibles
| Metodo | Color |
|---|---|
Logger.debug() |
Verde |
Logger.info() |
Azul |
Logger.warning() |
Amarillo |
Logger.error() |
Rojo |
Logger.success() |
Verde |
Logger.library() |
Magenta |
Logger.step() |
Cyan |
Logger.note() |
Gris |
Logger.title() |
Azul bold |
Logger.metric() |
Magenta |
Estilos
Logger.configure(style="soft") # "full" (default) | "prefix" | "soft"
O por variable de entorno:
export COLORSTREAK_STYLE=prefix
Compatible con print()
Logger.info("Multiple", "args", 123, sep=" | ")
Logger.warning("Sin salto...", end="")
Desactivar colores
export NO_COLOR=1
RichLogger (avanzado)
Logger con Rich para output profesional en terminal.
from colorstreak import RichLogger
log = RichLogger(style="inline")
Configuracion
log = RichLogger(
level="DEBUG", # nivel minimo: DEBUG, INFO, WARNING, ERROR, CRITICAL
style="inline", # "panel" | "inline" | "minimal"
metadata=True, # muestra archivo:linea en cada log
timestamp=True, # muestra hora
)
Niveles
log.debug("Mensaje de debug")
log.info("Servidor iniciado en puerto 8080")
log.warning("Cache expirado")
log.error("No se pudo conectar a la DB")
log.critical("Sistema de archivos lleno")
log.success("Deploy completado")
log.library("Cargando modulo: colorstreak")
log.step("Paso 1/3: Verificando...")
log.note("Nota de baja prioridad")
log.metric("loss=0.1234 acc=0.9876")
log.title("=== Seccion: Resultados ===")
Filtrado por nivel
log = RichLogger(level="WARNING")
log.debug("No se muestra")
log.warning("Esto si")
Tablas
# Desde lista de dicts
log.table([
{"ID": 1, "Nombre": "Carlos", "Rol": "Admin"},
{"ID": 2, "Nombre": "Maria", "Rol": "Editor"},
], title="Usuarios")
# Desde columns + rows
log.table(
columns=["Metrica", "Valor"],
rows=[["CPU", "42%"], ["RAM", "78%"]],
)
JSON
log.json({
"status": "ok",
"config": {"timeout": 30, "retries": 3},
})
Excepciones
try:
result = 1 / 0
except ZeroDivisionError:
log.exception("Algo salio mal")
Benchmark
with log.benchmark("Operacion pesada", slow_threshold=1.0):
time.sleep(0.5)
Grupos
with log.group("Inicializando servicios"):
log.info("Conectando a Redis...")
log.success("Listo")
HTTP
log.http("GET", "/api/users", status=200, duration=0.045)
log.http("POST", "/api/login", status=201, duration=0.12)
log.http("DELETE", "/api/sessions", status=500, duration=3.2)
SQL
log.sql("""
SELECT u.name, COUNT(o.id) as orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.active = true
LIMIT 10
""")
Header (banner de inicio)
log.header(
"Mi API",
version="1.0.0",
env="production",
port=8080,
)
Variables de entorno
# Explicito: muestra solo las que pidas
log.env("DATABASE_URL", "REDIS_URL", "SECRET_KEY")
# Auto-discover: lee las variables de los archivos .env* del proyecto
log.env()
El auto-discover parsea todos los archivos .env, .env.local, .env.secret, etc. del root del proyecto. Las variables con nombres como SECRET, KEY, TOKEN, PASSWORD se enmascaran automaticamente.
Tree (estructura de directorios)
# Manual: pasa tu propio dict
log.tree("Mi Proyecto", {
"src": {"main.py": None, "utils.py": None},
"tests": {"test_main.py": None},
"README.md": None,
})
# Auto-discover: escanea el proyecto desde el root
log.tree()
# Con profundidad maxima
log.tree(max_depth=2)
El auto-discover detecta el root del proyecto buscando pyproject.toml, package.json, .git, etc. Ignora carpetas como .git, __pycache__, .venv, node_modules.
Inspect
log.inspect(mi_objeto)
log.inspect(mi_objeto, methods=True)
Code
log.code("""
def fibonacci(n: int) -> int:
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
""", title="Fibonacci", language="python")
Diff
log.diff(old_text, new_text, context="config.ini")
Panel
log.panel(
"El servidor se reiniciara en 30 segundos.",
title="Mantenimiento",
style="warning", # "info" | "warning" | "error" | "success"
)
Contadores
for request in requests:
log.count("requests_processed")
log.count_summary(title="Resumen")
Log a archivo
log.to_file("output.log")
# A partir de aqui, todo se escribe tambien al archivo (sin colores)
Regla visual
log.rule("Seccion importante")
Requisitos
- Python >= 3.10
rich(se instala automaticamente)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colorstreak-2.2.1.tar.gz.
File metadata
- Download URL: colorstreak-2.2.1.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25eb20291df1e872228bb6c3066289f2e3f46ced84cb6bf77b313658d1f15a0b
|
|
| MD5 |
4c946e9baf0c25da445a67b523901f82
|
|
| BLAKE2b-256 |
4fb81ff23232bbc374f19a86ffbb099bd90984e8d9d15f89bd64f039b8894a2d
|
File details
Details for the file colorstreak-2.2.1-py3-none-any.whl.
File metadata
- Download URL: colorstreak-2.2.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4585d1082571d8e1694853ae7c00294feb736e050d314a655188b6800fc8cbe0
|
|
| MD5 |
9f40bfc3a1c2e62c3b01211839a8a7d6
|
|
| BLAKE2b-256 |
c03cc272e94bad5322a248856d5bd92c19db314172cb8884d18fd4bb9b2e7a53
|