Java agent for dynamic logging
jlogpoint is a lightweight Java agent that you can attach to a running JVM to dynamically inject "log points" into specific methods without requiring application restart. It uses Byte Buddy for safe bytecode manipulation and retransformation.
- 🔍 Introspect loaded classes and methods - Browse all classes loaded in the JVM
- 🎯 Dynamic log point injection - Add logging to any method on-the-fly
- 🔄 Safe retransformation - Uses Byte Buddy for reliable bytecode manipulation
- 🚀 No restart required - Attach to running JVMs
- 📊 Method entry/exit logging - Track method calls, arguments, and return values
- Compiler: JDK 25
- Target Compatibility: Java 17+
- Build System: Maven
- Testing: JUnit 5 (Jupiter)
mvn clean packageThis will create a shaded JAR with all dependencies at:
target/jlogpoint-1.0.0-SNAPSHOT.jar
java -javaagent:target/jlogpoint-1.0.0-SNAPSHOT.jar -jar your-application.jareu.ndsk.jlogpoint.infra.LogPointManager;
// Get the agent's log point manager
LogPointManager manager = eu.ndsk.jlogpoint.infra.JLogPointAgent.getLogPointManager();
// Add a log point to a specific method
manager.
addLogPoint(
"com.example.MyClass", // Class name
"myMethod", // Method name
"Custom log message" // Log message
);
// List all active log points
Map<String, LogPoint> activeLogPoints = manager.getActiveLogPoints();
// Remove a log point
manager.
removeLogPoint("com.example.MyClass","myMethod");import eu.ndsk.jlogpoint.infra.ClassIntrospector;
ClassIntrospector introspector = new ClassIntrospector(
JLogPointAgent.getInstrumentation()
);
// Find classes by pattern
List<ClassInfo> classes = introspector.findClasses("com.example");
// Get methods for a specific class
List<MethodInfo> methods = introspector.getMethodsForClass("com.example.MyClass");jlogpoint/
├── src/main/java/de/ndsk/jlogpoint/
│ ├── JLogPointAgent.java # Agent entry point
│ ├── LogPointManager.java # Manages log points and instrumentation
│ ├── LogPointAdvice.java # Byte Buddy advice for logging
│ └── ClassIntrospector.java # Class/method introspection utilities
├── src/test/java/de/ndsk/jlogpoint/
│ ├── LogPointManagerTest.java # Unit tests
│ └── ClassIntrospectorTest.java # Unit tests
└── pom.xml # Maven configuration
- Agent Initialization: When attached, the agent registers with the JVM's Instrumentation API
- Log Point Registration: When you call
addLogPoint(), the manager:- Locates the target class in loaded classes
- Creates a Byte Buddy transformation
- Applies
LogPointAdviceto inject logging code - Retransforms the class on-the-fly
- Method Execution: When the instrumented method runs:
- Entry advice logs method name and arguments
- Exit advice logs return values or exceptions
Run tests with:
mvn test- Byte Buddy 1.14.18 - Bytecode manipulation
- JUnit 5.10.2 - Testing framework
See LICENSE file for details.
When a log point is active, you'll see output like:
[LOGPOINT ENTER] com.example.MyClass#myMethod | Args: [arg1, arg2]
[LOGPOINT EXIT] com.example.MyClass#myMethod | Return: result value
manager.addLogPoint(
"com.example.Service",
"processData",
"Processing data with arguments: ${args}"
);Iterate through methods and add log points:
ClassIntrospector introspector = new ClassIntrospector(
JLogPointAgent.getInstrumentation()
);
List<MethodInfo> methods = introspector.getMethodsForClass("com.example.MyClass");
for (MethodInfo method : methods) {
manager.addLogPoint("com.example.MyClass", method.getName(), "Monitoring: " + method.getName());
}- Cannot instrument native methods
- Some system classes may be restricted
- Retransformation has a small performance overhead
- Log points persist until explicitly removed or JVM restart
Contributions are welcome! Please ensure tests pass before submitting PRs.