Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.0] - 2026-04-08

### Added
- Android Log support (`Log.d(tag, message)` from `android.util.Log`) as a built-in logging framework
- Custom logging framework support with user-defined templates using `{tag}` and `{message}` placeholders
- Custom template UI fields in the tool window (Kotlin template, Java template, optional import path)
- Java import fallback for unresolvable classes (needed for custom framework imports)

## [1.0.1] - 2026-02-19

### Fixed
Expand Down
9 changes: 6 additions & 3 deletions MARKETPLACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ Debugging complex applications often requires adding temporary logging statement

### 📦 Multiple Logging Frameworks
- **System.out.println**: Classic debugging output (default)
- **Android Log**: Native Android logging — `Log.d("Tag", "message")`
- **Timber**: Popular Android logging library — `Timber.tag("Tag").d("message")`
- **Napier**: Kotlin Multiplatform logging library — `Napier.d("message", tag = "Tag")`
- **Coming Soon**: Log4j, SLF4J, and custom frameworks
- **Custom**: Define your own templates with `{tag}` and `{message}` placeholders

### ⚙️ Flexible Configuration
- **Method Execution Tracking**: Log when methods are called
Expand Down Expand Up @@ -165,6 +166,7 @@ Access via **LoggingOptions** tool window:
| **Track Assignments** | Log variable assignments | ✅ Enabled |
| **Log Tag** | Custom prefix for logs | "Myfancy log" |
| **Logging Framework** | Choose output method | System.out.println |
| **Custom Templates** | Define your own log format (when Custom is selected) | `Log.d("{tag}", "{message}")` |

---

Expand All @@ -177,7 +179,7 @@ Access via **LoggingOptions** tool window:
- **Platforms**: Windows, macOS, Linux

### Smart Features
- **Import Management**: Automatically adds imports on insertion and removes them when no logs remain (Timber, Napier)
- **Import Management**: Automatically adds imports on insertion and removes them when no logs remain (Android Log, Timber, Napier, Custom)
- **Scope Detection**: Works on current class or entire file
- **Safe Removal**: Only removes logs inserted by this plugin, preserving logs from other tags
- **Scope Function Awareness**: When removing a log inside an `apply`/`let`/`run` block, only the log line is removed — the block is preserved
Expand Down Expand Up @@ -206,8 +208,10 @@ Access via **LoggingOptions** tool window:
- Use keyboard shortcuts for faster workflow

### Tip 4: Framework-Specific Benefits
- **Android Log**: Automatically adds/removes `import android.util.Log`, uses `Log.d("Tag", "message")` — native Android logging
- **Timber**: Automatically adds/removes `import timber.log.Timber`, uses `Timber.tag("Tag").d("message")`
- **Napier**: Automatically adds/removes `import io.github.aakira.napier.Napier`, uses `Napier.d("message", tag = "Tag")` — ideal for Kotlin Multiplatform projects
- **Custom**: Define your own log format with `{tag}` and `{message}` placeholders, with an optional import path
- **println**: Simple and works everywhere, no dependencies

---
Expand All @@ -229,7 +233,6 @@ Access via **LoggingOptions** tool window:
### Coming Soon
- ✨ Support for Log4j and SLF4J
- ✨ More Kotlin Multiplatform framework integrations
- ✨ Custom log templates
- ✨ Log level configuration (DEBUG, INFO, WARN, ERROR)
- ✨ Smart duplicate detection
- ✨ Bulk operations across multiple files
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Log Injector for IntelliJ IDEA

[![Version](https://img.shields.io/badge/version-1.0.1-blue.svg)](https://github.com/Kiolk/Log-Injector)
[![Version](https://img.shields.io/badge/version-1.1.0-blue.svg)](https://github.com/Kiolk/Log-Injector)
[![IntelliJ Platform](https://img.shields.io/badge/IntelliJ-2024.3-orange.svg)](https://www.jetbrains.com/idea/)

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.
Expand All @@ -13,8 +13,10 @@ An IntelliJ IDEA plugin that automatically inserts and removes logging statement
- **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
Expand Down Expand Up @@ -70,7 +72,7 @@ Access the plugin settings through the **LoggingOptions** tool window on the rig
- **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, Timber, or Napier
- **Logging Framework**: Choose between System.out.println, Android Log, Timber, Napier, or Custom

### Examples

Expand Down Expand Up @@ -279,7 +281,16 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Changelog

### Version 1.0.0 (Current)
### 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
Expand All @@ -292,8 +303,9 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

Future features under consideration:
- [x] Napier logging framework support
- [x] Android Log support
- [x] Custom log templates
- [ ] More logging framework support (Log4j, SLF4J, etc.)
- [ ] Custom log templates
- [ ] Smart log placement (avoid duplicates)
- [ ] Log level configuration
- [ ] Bulk operations across multiple files
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
}

version = "1.0.1"
version = "1.1.0"
group = "com.github.kiolk.loggingplugin"

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,12 @@ class LogInserterService(private val project: Project) {
) {
if (importPath == null) return
val className = importPath.substringAfterLast('.')
val pattern = Regex("\\b${Regex.escape(className)}\\b")
val hasRemainingUsage =
file.text
.lines()
.filter { !it.trimStart().startsWith("import ") }
.any { it.contains(className) }
.any { pattern.containsMatchIn(it) }
if (hasRemainingUsage) return
file.importList?.imports
?.find { it.importPath?.pathStr == importPath }
Expand All @@ -299,11 +300,12 @@ class LogInserterService(private val project: Project) {
) {
if (importPath == null) return
val className = importPath.substringAfterLast('.')
val pattern = Regex("\\b${Regex.escape(className)}\\b")
val hasRemainingUsage =
file.text
.lines()
.filter { !it.trimStart().startsWith("import ") }
.any { it.contains(className) }
.any { pattern.containsMatchIn(it) }
if (hasRemainingUsage) return
file.importList
?.findSingleClassImportStatement(importPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ class PrintlnStrategy : LogStrategy {
override fun getJavaImport(): String? = null
}

class AndroidLogStrategy : LogStrategy {
override fun createKotlinLog(
factory: KtPsiFactory,
tag: String,
message: String,
): String = "Log.d(\"$tag\", \"$message\")"

override fun createJavaLog(
factory: PsiElementFactory,
tag: String,
message: String,
): String = "Log.d(\"$tag\", \"$message\");"

override fun getRemovalPatterns(tag: String): List<String> = listOf("Log.d(\"$tag\"", tag)

override fun getKotlinImport(): String = "android.util.Log"

override fun getJavaImport(): String = "android.util.Log"
}

class TimberStrategy : LogStrategy {
override fun createKotlinLog(
factory: KtPsiFactory,
Expand Down Expand Up @@ -124,6 +144,7 @@ object LogStrategyFactory {
): LogStrategy {
return when (framework) {
LoggingSettings.LoggingFramework.PRINTLN -> PrintlnStrategy()
LoggingSettings.LoggingFramework.ANDROID_LOG -> AndroidLogStrategy()
LoggingSettings.LoggingFramework.TIMBER -> TimberStrategy()
LoggingSettings.LoggingFramework.NAPIER -> NapierStrategy()
LoggingSettings.LoggingFramework.CUSTOM ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.intellij.openapi.project.Project
class LoggingSettings : PersistentStateComponent<LoggingSettings.State> {
enum class LoggingFramework(val displayName: String) {
PRINTLN("System Println"),
ANDROID_LOG("Android Log"),
TIMBER("Timber"),
NAPIER("Napier"),
CUSTOM("Custom"),
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<li><strong>One-Click Log Insertion:</strong> Automatically add logging statements to all methods in a class</li>
<li><strong>Quick Removal:</strong> Remove all inserted logs just as easily</li>
<li><strong>Multi-Language Support:</strong> Works seamlessly with both Java and Kotlin files</li>
<li><strong>Multiple Frameworks:</strong> Choose between System.out.println, Timber, or Napier logging</li>
<li><strong>Multiple Frameworks:</strong> Choose between System.out.println, Android Log, Timber, Napier, or define your own Custom logging format</li>
<li><strong>Flexible Tracking:</strong> Track method execution and variable assignments</li>
<li><strong>Customizable:</strong> Set your own log tags for easy filtering</li>
</ul>
Expand All @@ -33,7 +33,7 @@
<li>Track method execution - Log when methods are called</li>
<li>Track assignments - Log variable assignments</li>
<li>Custom log tags - Set your preferred log prefix</li>
<li>Logging framework - Choose between println, Timber, and Napier</li>
<li>Logging framework - Choose between println, Android Log, Timber, Napier, or Custom</li>
<li>Automatic import management - Imports are added on insertion and removed when no longer needed</li>
</ul>

Expand Down
Loading
Loading