Skip to main content

A tool to clean logging statements from code

Project description

Log & Console Cleanup Tool

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.

Features

  • Multi-Language Support

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

    • Identifies and removes Python logging statements (logger.*, logging.*)
    • Catches all console methods in JavaScript/TypeScript
    • Handles multi-line logging statements
    • Preserves code formatting
  • 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
  1. Install in development mode:
pip install -e .

Usage

After installation, you can run the tool from anywhere using:

# Using the command-line tool
logcleaner

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

Supported Patterns

Python

  • Import statements:

    import logging
    from logging import getLogger
    
  • Logger initialization:

    logger = logging.getLogger(__name__)
    _logger = logging.getLogger()
    
  • Logging statements (including multi-line):

    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 the tool on version-controlled code
  2. Review the summary before confirming changes
  3. Enable backup option for important codebases
  4. Test the cleaned code before committing changes

Limitations

  • Does not handle extremely complex string concatenations
  • Cannot detect logging statements in string literals or comments
  • May require manual review for edge cases

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 that demonstrates the problem
  3. Provide the error message if applicable
  4. Describe the expected behavior

Changelog

v1.0.0 (2025-02-09)

  • Initial release
  • Multi-language support
  • Backup functionality
  • Interactive CLI

Made with python by Olumide Awodeji

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

log_cleaner-1.0.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

log_cleaner-1.0.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file log_cleaner-1.0.0.tar.gz.

File metadata

  • Download URL: log_cleaner-1.0.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for log_cleaner-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c4855e12a54fe5da2bcdbc588b98a4835253db87c9d3325eada3ddb988ff27f9
MD5 01b8f2e4712e6344eb87f3c7cb3282e8
BLAKE2b-256 b93c1cb1d56ab40af7dd93227af49afb6d720d1bea2d448421cfbd4ba2fd35dc

See more details on using hashes here.

File details

Details for the file log_cleaner-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: log_cleaner-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for log_cleaner-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76a9b45bd25cac3f4c3b77ac34aca560bc4a46fef51d2f99036f26e83cd634d1
MD5 d3309c5ca98eaf7e67ed4b968e0b83b4
BLAKE2b-256 4f4772e946dc89259ce504b6c681580420e75a4c7e9e0a2022e98dbdf0f792c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page