Files
fn_registry/python/functions/infra/setup_logger.md
T
egutierrez 5a324f6554 feat: funciones Python infra y tipos Python (core, datascience, infra)
Infra: cache_to_file, cache_to_sqlite, http_download_file, http_get_json,
http_post_json, read_file_with_encoding, safe_extract_zip, scan_directory,
setup_logger, normalize_zip_filenames.
Tipos: 30+ tipos core (agent_action, context, task, message, parse_result...),
6 tipos datascience (entity_candidate, extraction_result...), 2 tipos infra.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 17:11:43 +02:00

1.9 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path
setup_logger function py infra 1.0.0 impure def setup_logger(name: str = 'app', log_dir: str = 'logs', level: int = logging.DEBUG) -> logging.Logger Configura un logger con dual output: archivo con rotacion por tamano (DEBUG+, 10MB, 5 backups) y consola (INFO+). Crea log_dir si no existe. Idempotente: no duplica handlers si el logger ya esta configurado.
logging
logger
rotation
file
console
infra
debug
false error_go_core
logging
logging.handlers
os
sys
datetime
true
logger se crea con 2 handlers
segundo call no duplica handlers
archivo se crea en log_dir
get_logger retorna logger configurado
logger level es debug
python/functions/infra/setup_logger_test.py python/functions/infra/setup_logger.py

Ejemplo

from setup_logger import setup_logger, get_logger

# Configurar al inicio de la aplicacion
logger = setup_logger(name="mi_app", log_dir="logs", level=logging.DEBUG)
logger.info("Aplicacion iniciada")
logger.debug("Detalle de debug")

# En modulos internos: obtener logger ya configurado
log = get_logger("mi_app")
log.warning("Algo inesperado ocurrio")

Notas

Funcion impura: crea el directorio log_dir en disco y modifica el estado global del sistema de logging de Python.

El archivo de log tiene nombre YYYY-MM-DD.log segun la fecha de inicio. La rotacion es por tamano (10 MB), no por tiempo — por eso el nombre es fijo para cada dia de inicio de la aplicacion.

En Windows se reconfigura sys.stdout a UTF-8 para evitar mojibake con caracteres no-ASCII.

La funcion companion get_logger es util en modulos que no controlan la inicializacion: devuelve el logger si ya fue configurado, o lo crea con defaults.