Skip to content

CLI Reference

Command-line interface documentation for Ezpl logging framework.

Overview

The Ezpl CLI provides comprehensive tools for managing configuration, viewing logs, and performing various operations from the command line.

Features

  • 📊 Log Management: View, search, tail, export, and clean log files
  • ⚙️ Configuration: Get, set, and reset configuration values
  • 🔍 Statistics: Analyze log statistics with temporal distribution
  • 📤 Export: Export logs to JSON, CSV, or TXT formats
  • 🌍 Environment: Manage environment variables

Quick Start

Installation

The CLI is automatically available when Ezpl is installed:

pip install ezplog

Basic Usage

# Display help
ezpl --help

# View logs
ezpl logs view --lines 50

# Search logs
ezpl logs search --pattern "error" --level ERROR

# Get configuration
ezpl config show

# Set configuration
ezpl config set log_level DEBUG

# Display version
ezpl version

Command Categories

Category Commands Description
Logs view, search, stats, tail, list, clean, export Log file operations
Config show, set, reset, export Configuration management
Info version, info Package information

Logs Commands

ezpl logs view

View log file contents with optional filtering.

ezpl logs view [OPTIONS]

Options:

  • --file, -f PATH: Path to log file (default: from config)
  • --lines, -n N: Number of lines to display (default: 50)
  • --level, -l LEVEL: Filter by log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • --follow, -F: Follow log file (like tail -f)

Examples:

# View last 100 lines
ezpl logs view --lines 100

# View errors only and follow
ezpl logs view --level ERROR --follow

# View specific file
ezpl logs view --file /path/to/app.log

Search log entries using regex patterns.

ezpl logs search --pattern PATTERN [OPTIONS]

Options:

  • --pattern, -p PATTERN: Search pattern (regex supported) [required]
  • --file, -f PATH: Path to log file (default: from config)
  • --level, -l LEVEL: Filter by log level
  • --case-sensitive, -c: Case-sensitive search

Examples:

# Search for errors or exceptions
ezpl logs search --pattern "error|exception"

# Case-sensitive search in ERROR level
ezpl logs search --pattern "Database" --level ERROR --case-sensitive

ezpl logs stats

Display statistics about log files.

ezpl logs stats [OPTIONS]

Options:

  • --file, -f PATH: Path to log file (default: from config)
  • --format, -F FORMAT: Output format: table (default) or json

Examples:

# Display stats in table format
ezpl logs stats

# Export stats as JSON
ezpl logs stats --format json > stats.json

Output includes:

  • Total lines
  • Log level distribution
  • File size
  • Date range
  • Error rate

ezpl logs tail

Display the last lines of a log file.

ezpl logs tail [OPTIONS]

Options:

  • --file, -f PATH: Path to log file (default: from config)
  • --lines, -n N: Number of lines to display (default: 20)
  • --follow, -F: Follow log file continuously

Examples:

# Tail last 20 lines
ezpl logs tail

# Follow log file
ezpl logs tail --lines 50 --follow

ezpl logs list

List available log files.

ezpl logs list [OPTIONS]

Options:

  • --dir, -d PATH: Directory to search (default: from config)

Examples:

# List log files in default directory
ezpl logs list

# List log files in specific directory
ezpl logs list --dir /var/log/myapp

ezpl logs clean

Clean old or large log files.

ezpl logs clean [OPTIONS]

Options:

  • --file, -f PATH: Specific file to clean
  • --days, -d N: Delete files older than N days
  • --size, -s SIZE: Delete files larger than SIZE (e.g., '100MB')
  • --confirm, -y: Skip confirmation prompt

Examples:

# Clean files older than 30 days
ezpl logs clean --days 30

# Clean files larger than 500MB (no confirmation)
ezpl logs clean --size 500MB --confirm

ezpl logs export

Export log file to different formats.

ezpl logs export [OPTIONS]

Options:

  • --file, -f PATH: Path to log file (default: from config)
  • --format, -F FORMAT: Export format: json (default), csv, or txt
  • --output, -o PATH: Output file path (default: stdout)

Examples:

# Export to JSON
ezpl logs export --format json --output logs.json

# Export to CSV
ezpl logs export --format csv --output logs.csv

# Export to stdout
ezpl logs export --format json

Configuration Commands

ezpl config show

Display current configuration.

ezpl config show [OPTIONS]

Options:

  • --env, -e: Also show environment variables

Examples:

# Show current configuration
ezpl config show

# Show with environment variables
ezpl config show --env

ezpl config set

Set a configuration value.

ezpl config set KEY VALUE [OPTIONS]

Options:

  • KEY: Configuration key
  • VALUE: Configuration value
  • --env, -e: Also set as environment variable

Available Keys:

  • log_level: Global log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • log_file: Log file name
  • printer_level: Console output level
  • file_logger_level: File logging level
  • log_rotation: Rotation setting (e.g., "10 MB", "1 day")
  • log_retention: Retention period (e.g., "7 days")
  • log_compression: Compression format (e.g., "zip", "gz")
  • indent_step: Indentation step size
  • indent_symbol: Symbol for indentation
  • base_indent_symbol: Base indentation symbol

Examples:

# Set log level
ezpl config set log_level DEBUG

# Set with environment variable
ezpl config set log_level DEBUG --env

# Set rotation
ezpl config set log_rotation "10 MB"

ezpl config reset

Reset configuration to default values.

ezpl config reset [OPTIONS]

Options:

  • --confirm, -y: Skip confirmation prompt

Examples:

# Reset with confirmation
ezpl config reset

# Reset without confirmation
ezpl config reset --confirm

ezpl config export

Export configuration as environment variables script.

ezpl config export [OPTIONS]

Options:

  • --output, -o PATH: Output file path
  • --platform, -p PLATFORM: Platform (unix, windows)

Examples:

# Export for Unix
ezpl config export --output env.sh --platform unix

# Export for Windows
ezpl config export --output env.bat --platform windows

Generated script:

# Unix (env.sh)
export EZPL_LOG_LEVEL="INFO"
export EZPL_LOG_FILE="ezpl.log"
# ...

# Windows (env.bat)
set EZPL_LOG_LEVEL=INFO
set EZPL_LOG_FILE=ezpl.log

Utility Commands

ezpl version

Display version information.

ezpl version [OPTIONS]

Options:

  • --full, -f: Display full version information

Examples:

# Simple version
ezpl version
# Output: 1.5.1

# Full version info
ezpl version --full
# Output:
# Ezpl version 1.5.1
# Python 3.11.0
# Platform: linux

ezpl info

Display package information.

ezpl info

Shows detailed information including:

  • Package version
  • Installation location
  • Configuration paths
  • Python version
  • Core dependencies

Example output:

Ezpl Package Information
========================
Version: 1.5.1
Location: /usr/local/lib/python3.11/site-packages/ezpl
Config Dir: /home/user/.ezpl
Python: 3.11.0

Dependencies:
- loguru: 0.7.2
- rich: 13.7.0
- click: 8.1.7

Environment Variables

Ezpl supports the following environment variables:

Variable Description Default
EZPL_LOG_LEVEL Global log level INFO
EZPL_LOG_FILE Log file name ezpl.log
EZPL_LOG_DIR Log directory Current directory
EZPL_PRINTER_LEVEL Console level INFO
EZPL_FILE_LOGGER_LEVEL File level INFO
EZPL_LOG_ROTATION Rotation setting None
EZPL_LOG_RETENTION Retention period None
EZPL_LOG_COMPRESSION Compression format None
EZPL_INDENT_STEP Indentation step 3
EZPL_INDENT_SYMBOL Indent symbol >
EZPL_BASE_INDENT_SYMBOL Base indent symbol ~

Setting Environment Variables

Unix/Linux/macOS:

export EZPL_LOG_LEVEL=DEBUG
export EZPL_LOG_FILE=app.log
export EZPL_LOG_ROTATION="10 MB"

Windows:

set EZPL_LOG_LEVEL=DEBUG
set EZPL_LOG_FILE=app.log
set EZPL_LOG_ROTATION=10 MB

Using CLI:

ezpl config set log_level DEBUG --env

Best Practices

Configuration Management

  1. Use environment variables for environment-specific settings:
# Development
export EZPL_LOG_LEVEL=DEBUG

# Production
export EZPL_LOG_LEVEL=ERROR
  1. Check configuration before setting:
ezpl config show
ezpl config set log_level DEBUG
  1. Export configuration for team sharing:
ezpl config export --output team-env.sh

Log Management

  1. Use tail --follow for real-time monitoring:
ezpl logs tail --follow
  1. Export logs before cleaning:
ezpl logs export --format json --output backup.json
ezpl logs clean --days 30 --confirm
  1. Use search with level filtering:
ezpl logs search --pattern "error" --level ERROR
  1. Check statistics regularly:
ezpl logs stats

Automation

Example: Daily log backup script (Unix):

#!/bin/bash
DATE=$(date +%Y%m%d)
ezpl logs export --format json --output "backup-$DATE.json"
ezpl logs clean --days 7 --confirm
ezpl logs stats --format json > "stats-$DATE.json"

Example: Log monitoring script:

#!/bin/bash
while true; do
    ezpl logs search --pattern "error|exception" --level ERROR
    sleep 60
done

Configuration File

Configuration is stored in ~/.ezpl/config.json:

{
  "log_level": "INFO",
  "log_file": "ezpl.log",
  "printer_level": "INFO",
  "file_logger_level": "DEBUG",
  "log_rotation": "10 MB",
  "log_retention": "7 days",
  "log_compression": "zip",
  "indent_step": 3,
  "indent_symbol": ">",
  "base_indent_symbol": "~"
}

See Also

Need Help?