This directory contains scripts to help integrate LogLama into existing PyLama ecosystem components, migrate projects from various logging systems to LogLama, and fix linting and syntax issues in the codebase.
This script helps you integrate LogLama into any component of the PyLama ecosystem. It will:
logging_config.py
module in the target component.env
and .env.example
files with LogLama configuration# Integrate LogLama into a specific component
./integrate_loglama.py --component apilama
# Integrate LogLama into all components in the PyLama ecosystem
./integrate_loglama.py --all
# Specify a custom base directory
./integrate_loglama.py --all --dir /path/to/py-lama
# Generate a report without making any changes
./integrate_loglama.py --all --report-only
The script can generate a comprehensive report of the LogLama integration status across all components using the --report-only
flag. This is useful for checking which components have already been integrated and which ones still need work.
The report includes the following information for each component:
logging_config.py
file.env
file includes LogLama configuration.env.example
file includes LogLama configurationExample report output:
=== LogLama Integration Report ===
Component Status:
apilama | ✅ Fully integrated
bexy | ✅ Fully integrated
getllm | ✅ Fully integrated
devlama | ✅ Fully integrated
shellama | ✅ Fully integrated
weblama | ✅ Fully integrated
After running the script, you’ll need to update your component’s main module to use LogLama. Add the following at the very top of your main module (before any other imports):
# Initialize logging first, before any other imports
from your_component.logging_config import init_logging, get_logger
# Initialize logging with LogLama
init_logging()
# Now import other standard libraries
import os
import sys
# ... other imports
# Get a logger
logger = get_logger('your_module')
The following PyLama ecosystem components have been integrated with LogLama:
You can check the integration status of each component using the --report-only
flag as described above.
Early Environment Loading: LogLama loads environment variables from .env
files before any other libraries, preventing issues with incorrect configuration.
Structured Logging: LogLama provides structured logging capabilities, making it easier to search and analyze logs.
Multiple Outputs: Logs can be sent to console, files, SQLite database, and more.
Context-Aware Logging: Add context to your logs for better debugging.
Consistent Interface: All components use the same logging interface, making it easier to understand and maintain.
Web Interface: Access and filter logs through a convenient web interface using the loglama web
command.
LogLama can be configured through environment variables in your .env
file:
# LogLama configuration
COMPONENT_LOG_LEVEL=INFO # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
COMPONENT_LOG_DIR=./logs # Directory to store log files
COMPONENT_DB_LOGGING=true # Enable database logging for advanced querying
COMPONENT_DB_PATH=./logs/component.db # Path to SQLite database for logs
COMPONENT_JSON_LOGS=false # Use JSON format for logs (useful for log processors)
# LogLama advanced settings
LOGLAMA_STRUCTURED_LOGGING=false # Use structured logging with structlog
LOGLAMA_MAX_LOG_SIZE=10485760 # Maximum log file size in bytes (10 MB)
LOGLAMA_BACKUP_COUNT=5 # Number of backup log files to keep
Replace COMPONENT
with your component name (e.g., APILAMA
, WEBLAMA
, etc.).
This script helps you migrate projects from LogLama to LogLama. It will automatically update import statements, variable names, function calls, environment variables, and file names.
# Run in report-only mode to see what would change without making any changes
python migrate_to_loglama.py --path /path/to/your/project --report-only --verbose
# Run for real to make the changes
python migrate_to_loglama.py --path /path/to/your/project --verbose
# Specify a custom output file for the migration report
python migrate_to_loglama.py --path /path/to/your/project --output migration_results.json
The following scripts are designed to fix various linting and syntax issues in the LogLama codebase. They are organized by purpose and severity.
This script automatically fixes common linting issues in the LogLama codebase.
Fixes:
Usage:
python scripts/fix_lint.py
This script addresses more complex linting issues that require more sophisticated fixes.
Fixes:
Usage:
python scripts/fix_advanced_lint.py
This script focuses on the most critical syntax issues that are preventing the package from being published.
Fixes:
Usage:
python scripts/fix_basic_syntax.py
This script adds # noqa comments to lines with linting issues to allow the package to pass linting checks without fixing all errors immediately.
Fixes:
Usage:
python scripts/add_noqa.py
This comprehensive script fixes critical issues blocking the publish process in LogLama.
Fixes:
Usage:
python scripts/fix_publish.py
This script specifically targets docstring-related issues in the codebase.
Fixes:
Usage:
python scripts/fix_docstrings.py
These scripts address specific syntax issues that are preventing the package from being published. The v2 version contains improvements over the original.
Fixes:
Usage:
python scripts/fix_syntax_v2.py # Recommended version
This script addresses critical linting issues that should be run after the other linting scripts.
Fixes:
Usage:
python scripts/fix_critical_lint.py
For the most effective linting and syntax fixing, run the scripts in the following order:
fix_basic_syntax.py
- Fix critical syntax errors firstfix_docstrings.py
- Fix docstring issuesfix_syntax_v2.py
- Fix remaining syntax issuesfix_lint.py
- Fix common linting issuesfix_advanced_lint.py
- Fix more complex linting issuesfix_critical_lint.py
- Fix critical remaining issuesadd_noqa.py
- Add noqa comments to remaining issuesfix_publish.py
- Final comprehensive fixes for publishingAlternatively, you can run just fix_publish.py
for a quick solution that focuses on making the minimal necessary changes to allow the package to pass linting checks for publication.
The migration script will:
import loglama
to import loglama
loglama.xyz
to loglama.xyz
loglama
to use loglama
insteadloglama_get_logger()
to loglama_get_logger()
LOGLAMA_
to LOGLAMA_
loglama_config.json
to loglama_config.json
loglama
in their namesFor a comprehensive migration guide, see the MIGRATION_GUIDE.md file in this directory.
If you need to maintain compatibility with both LogLama and LogLama during a transition period, you can use the compatibility layer provided in loglama.compat
.
# Instead of importing directly from loglama or loglama
from loglama.compat import get_logger, setup_logging, LogContext
# Then use as normal
logger = get_logger(__name__)
logger.info("This works with both LogLama and LogLama!")
This script provides a comprehensive solution for migrating projects from various logging systems to LogLama. It supports multiple source logging systems and provides a unified interface for migration.
# Migrate from Python's standard logging module
python universal_log_migrator.py --path /path/to/your/project --source logging --verbose
# Migrate from Loguru
python universal_log_migrator.py --path /path/to/your/project --source loguru
# Migrate from structlog
python universal_log_migrator.py --path /path/to/your/project --source structlog
# Migrate from a custom logging implementation
python universal_log_migrator.py --path /path/to/your/project --source custom
# Migrate from LogLama
python universal_log_migrator.py --path /path/to/your/project --source loglama
# Run in report-only mode to see what would change without making any changes
python universal_log_migrator.py --path /path/to/your/project --source logging --report-only
The universal log migrator will:
After running the migrator, a detailed report is generated showing all changes made. This report includes:
The report is saved as JSON for easy parsing and can be viewed with any text editor or JSON viewer.