Skip to content

A powerful Python utility for automatically removing logging statements and console outputs from your codebase. This tool supports Python logging statements and JavaScript/TypeScript console outputs, with intelligent handling of both single-line and multi-line statements.

License

Notifications You must be signed in to change notification settings

Cypher-O/log_cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Cleaner Pro

A powerful Python utility that provides comprehensive log management capabilities. This dual-purpose tool helps you maintain clean production code by automatically removing logging statements and console outputs from your codebase, while also efficiently managing your log files through automated cleaning and scheduling. It intelligently handles Python logging statements and JavaScript/TypeScript console outputs, supporting both single-line and multi-line statements, alongside sophisticated log file management features for automated retention and cleanup.

Features

Code Cleanup

  • Multi-Language Support

    • Python (.py)
    • JavaScript (.js)
    • TypeScript (.ts)
    • React files (.jsx, .tsx)
  • Smart Code Detection

    • Identifies and removes Python logging statements (logger.*, logging.*)
    • Catches all console methods in JavaScript/TypeScript
    • Handles multi-line logging statements
    • Preserves code formatting

Log File Management

  • Intelligent Log Detection

    • Automatically identifies log files by extension and content
    • Supports multiple log file formats and patterns
    • Handles various timestamp formats
    • Works with rotated log files (e.g., .log.1, .log.2)
  • Automated Cleaning

    • Remove log entries older than specified date
    • Scheduled cleaning through cron jobs
    • Configurable retention periods
    • Preserves file structure and empty lines
  • Safety Features

    • Automatic backup creation
    • Detailed logging of all changes
    • Preview of affected files before cleanup
    • Undo capability through backups
  • User Interface

    • Interactive command-line interface
    • Clear progress indicators
    • Colored output for better visibility
    • Comprehensive summary reports

Installation

Using pip (Recommended)

You can install the package directly from GitHub:

# Install latest version
pip install git+https://github.com/cypher-o/log_cleaner.git

# Or specify a version
pip install git+https://github.com/cypher-o/log_cleaner.git@v1.0.0

From source

  1. Clone this repository:

    git clone https://github.com/cypher-o/log_cleaner.git
    cd log_cleaner
  2. Install in development mode:

    pip install -e .

Usage

Basic Command Line Usage

# Start the interactive tool
log-cleaner

# Or using Python's -m flag
python -m log_cleaner

Code Cleanup Examples

Clean logging statements from a specific directory:

python log_cleaner.py --clean-code ./my_project

Clean specific files:

python log_cleaner.py --clean-code ./src/main.py ./src/utils.js

Log File Management Examples

Clean old log entries:

# Clean logs older than 30 days
python log_cleaner.py --clean-logs ./logs --days 30

# Clean logs before specific date
python log_cleaner.py --clean-logs ./logs --before 2024-01-01

Set up automated cleaning:

# Schedule daily cleanup at 2:30 AM
python log_cleaner.py --schedule ./logs --hour 2 --minute 30

# Remove scheduled cleanup
python log_cleaner.py --remove-schedule

Supported Log Formats

The tool supports various log formats including:

  • ISO format timestamps:
2024-02-15 10:30:45 INFO Started application
  • Unix timestamps:
1644915045 Started backup process
  • Custom formats:
[Feb 15 10:30:45 2024] Server started

Supported Code Patterns

Python

# Import statements
import logging
from logging import getLogger

# Logger initialization
logger = logging.getLogger(__name__)
_logger = logging.getLogger()

# Logging statements
logger.info("Message")
logger.error(f"Error: {error}")
_logger.warning(
    f"Warning message with "
    "multiple lines"
)

JavaScript/TypeScript

// Console statements
console.log("Message");
console.error("Error");
console.warn(
    "Multi-line " +
    "warning message"
);

Backup and Recovery

  • Backups are stored in a backup directory with timestamps
  • Each backup includes:
    • Original files with directory structure preserved
    • Detailed log file of all changes
    • Timestamp-based organization for easy recovery

Examples

Basic Usage

Clean a specific directory:

python log_cleaner.py
# Select "Select a directory"
# Enter: ./my_project

Clean Specific Files

python log_cleaner.py
# Select "Select specific files"
# Enter files one by one:
# ./src/main.py
# ./src/utils.js

Best Practices

  1. Always run on version-controlled code
  2. Review changes before confirming
  3. Enable backups for important files
  4. Test after cleaning
  5. Schedule automated cleaning during low-traffic periods
  6. Monitor disk space usage
  7. Set appropriate retention periods

Limitations

  • Complex string concatenations may require manual review
  • Cannot detect logging statements in string literals or comments
  • May require adjustment of patterns for custom log formats
  • Scheduled cleaning requires cron daemon to be running

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Inspired by the need for clean production code
  • Built with best practices from Python and JavaScript communities

Support

For issues, questions, or contributions, please:

  1. Open an issue in the GitHub repository
  2. Include sample code or log files that demonstrate the problem
  3. Provide the error message if applicable
  4. Describe the expected behavior

Changelog

v1.1.0 (2025-02-15)

  • Added log file management capabilities
  • Automated cleaning with cron integration
  • Support for multiple log formats
  • Improved log file detection

v1.0.0 (2025-02-09)

  • Initial release
  • Multi-language code cleanup
  • Backup functionality
  • Interactive CLI

Made with Python by Olumide Awodeji

About

A powerful Python utility for automatically removing logging statements and console outputs from your codebase. This tool supports Python logging statements and JavaScript/TypeScript console outputs, with intelligent handling of both single-line and multi-line statements.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages