Skip to content

Repository files navigation

Log Injector for IntelliJ IDEA

Version IntelliJ Platform

An IntelliJ IDEA plugin that automatically inserts and removes logging statements in your Java and Kotlin code. Save time and improve debugging efficiency by adding comprehensive logging with just a few clicks.

Features

🚀 Core Functionality

  • Automatic Log Insertion: Insert logging statements into all methods of a class with a single action
  • Automatic Log Removal: Remove all inserted logs from a class quickly and cleanly
  • Multi-Language Support: Works with both Java and Kotlin files
  • Multiple Logging Frameworks:
    • System.out.println (default)
    • Android Log (Log.d from android.util.Log)
    • Timber (Android logging library)
    • Napier (Kotlin Multiplatform logging library)
    • Custom (user-defined templates with {tag} and {message} placeholders)
  • Automatic Import Management: Imports are added when inserting logs and removed automatically when all logs for a framework are removed

📊 Tracking Options

  • Method Execution Tracking: Automatically log method entry points
  • Assignment Tracking: Log variable assignments for detailed debugging
  • Custom Log Tags: Configure your own log tag/prefix for easy filtering

🎨 User Interface

  • Context Menu Actions: Right-click in the editor to insert or remove logs
  • Tool Window: Dedicated settings panel for configuring logging preferences
  • Real-time Configuration: Change settings without restarting the IDE

Installation

From JetBrains Marketplace (Coming Soon)

  1. Open IntelliJ IDEA
  2. Go to FileSettingsPlugins
  3. Search for "Log Injector"
  4. Click Install and restart the IDE

From Source

  1. Clone this repository:

    git clone https://github.com/Kiolk/Log-Injector.git
    cd Log-Injector
  2. Build the plugin:

    ./gradlew buildPlugin
  3. Install the plugin:

    • Go to FileSettingsPlugins
    • Click the gear icon ⚙️ and select Install Plugin from Disk...
    • Select the ZIP file from build/distributions/
    • Restart IntelliJ IDEA

Usage

Quick Start

  1. Open a Java or Kotlin file in your project
  2. Right-click anywhere in the editor
  3. Choose one of the following actions:
    • Insert Logs: Adds logging statements to methods in the current class
    • Remove Logs: Removes all previously inserted logs from the current class

Configuration

Access the plugin settings through the LoggingOptions tool window on the right side of the IDE:

  • Track Method Execution: Enable/disable method entry logging
  • Track Assignments: Enable/disable variable assignment logging
  • Log Tag: Set a custom prefix for your log statements (default: "Myfancy log")
  • Logging Framework: Choose between System.out.println, Android Log, Timber, Napier, or Custom

Examples

Before (Kotlin):

class UserManager {
    fun createUser(name: String, email: String): User {
        val user = User(name, email)
        saveToDatabase(user)
        return user
    }
}

After (with method tracking enabled):

class UserManager {
    fun createUser(name: String, email: String): User {
        println("Myfancy log: createUser()")
        val user = User(name, email)
        saveToDatabase(user)
        return user
    }
}

Development

Prerequisites

  • JDK 21 or higher
  • Gradle 8.x (wrapper included)
  • IntelliJ IDEA 2024.3 or higher

Setup Development Environment

  1. Clone the repository:

    git clone https://github.com/Kiolk/Log-Injector.git
    cd Log-Injector
  2. Open the project in IntelliJ IDEA:

    • FileOpen → Select the project directory
    • IntelliJ will automatically import the Gradle project
  3. Run the plugin in a development instance:

    ./gradlew runIde

Project Structure

LogInjector/
├── src/
│   ├── main/
│   │   ├── kotlin/
│   │   │   └── com/github/kiolk/loggingplugin/
│   │   │       ├── actions/          # Plugin actions (Insert/Remove)
│   │   │       ├── services/         # Core logic and strategies
│   │   │       ├── settings/         # Configuration management
│   │   │       └── toolwindow/       # UI components
│   │   └── resources/
│   │       └── META-INF/
│   │           └── plugin.xml        # Plugin configuration
│   └── test/
│       └── kotlin/                   # Unit tests
├── build.gradle.kts                  # Build configuration
└── README.md                         # This file

Key Components

  • InsertLogsAction: Handles the "Insert Logs" action
  • RemoveLogsAction: Handles the "Remove Logs" action
  • LogInserterService: Core service for inserting logs into PSI elements
  • LogStrategy: Strategy pattern implementation for different logging frameworks
  • LoggingSettings: Persistent configuration storage

Contributing

We welcome contributions! Here's how you can help:

Reporting Issues

  1. Check if the issue already exists in the Issues section
  2. If not, create a new issue with:
    • Clear description of the problem
    • Steps to reproduce
    • Expected vs actual behavior
    • IntelliJ IDEA version and plugin version
    • Sample code (if applicable)

Submitting Pull Requests

  1. Fork the repository and create your branch from main:

    git checkout -b feature/your-feature-name
  2. Make your changes:

    • Follow the existing code style (enforced by ktlint)
    • Add tests for new functionality
    • Update documentation if needed
  3. Run tests to ensure everything works:

    ./gradlew test
  4. Run code quality checks:

    ./gradlew ktlintCheck
  5. Commit your changes with a clear commit message:

    git commit -m "Add feature: description of your changes"
  6. Push to your fork and create a Pull Request:

    git push origin feature/your-feature-name
  7. In your pull request description:

    • Explain what changes you made and why
    • Reference any related issues
    • Include screenshots for UI changes

Code Style Guidelines

  • Follow Kotlin coding conventions
  • Use meaningful variable and function names
  • Add comments for complex logic
  • Keep functions small and focused
  • Write unit tests for new features
  • Ensure ktlint passes: ./gradlew ktlintFormat

Development Tips

  • Use ./gradlew runIde to test changes in a live IDE instance
  • Check plugin logs: HelpShow Log in Finder/Explorer
  • Use IntelliJ's PSI Viewer: ToolsView PSI Structure

Testing

Run all tests:

./gradlew test

Run specific test:

./gradlew test --tests "LogInserterServiceTest"

Building

Build the plugin distribution:

./gradlew buildPlugin

The plugin ZIP will be created in build/distributions/

Publishing

To publish to JetBrains Marketplace:

  1. Set up environment variables:

    export PUBLISH_TOKEN="your-marketplace-token"
    export CERTIFICATE_CHAIN="your-certificate"
    export PRIVATE_KEY="your-private-key"
    export PRIVATE_KEY_PASSWORD="your-password"
  2. Publish:

    ./gradlew publishPlugin

Compatibility

  • IntelliJ IDEA: 2024.3 - 2025.3.*
  • Languages: Java, Kotlin
  • JDK: 21+

License

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

Author

Yauheni Slizh

Acknowledgments

  • Built with IntelliJ Platform SDK
  • Inspired by the need for faster debugging workflows
  • Thanks to all contributors!

Changelog

Version 1.1.0 (Current)

  • Android Log support (android.util.Log)
  • Custom logging framework support with user-defined templates
  • Custom template UI in the tool window

Version 1.0.1

  • Napier logging framework support
  • Scope function block removal fix

Version 1.0.0

  • Initial release
  • Support for Java and Kotlin
  • Method execution tracking
  • Assignment tracking
  • System.out.println and Timber frameworks
  • Configurable log tags
  • Tool window for settings

Roadmap

Future features under consideration:

  • Napier logging framework support
  • Android Log support
  • Custom log templates
  • More logging framework support (Log4j, SLF4J, etc.)
  • Smart log placement (avoid duplicates)
  • Log level configuration
  • Bulk operations across multiple files
  • Integration with debugging tools

Support


Made with ❤️ for developers who love clean code and efficient debugging

About

IntelliJ IDEA plugin that automatically inserts and removes logging statements in Java and Kotlin code with support for multiple logging frameworks.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages