5.1. Troubleshooting, Debugging and Profiling
Troubleshooting
Logging
Logging is easy to control through the console, with commands grouped under log shell. To learn about the available logging commands type:
karaf@root> log<tab> log:display log:display-exception log:get log:set karaf@root>
Typical usage is:
- Use
log:set
to dynamically change the global log level - Execute the problematic operation
- Use
log:display
(orlog:display-exception
to display the log
Worst Case Scenario
If you end up with a Karaf in a really bad state (i.e. you can not boot it anymore) or you just want to revert to a clean state quickly, you can safely remove the data
directory just in the installation directory. This folder contains transient data and will be recreated if you remove it and relaunch Karaf.
You may also want to remove the files in the deploy
folder to avoid them being automatically installed when Karaf is started the first time.
Debugging
Usually, the easiest way to debug Karaf or any application deployed onto it is to use remote debugging.
Remote debugging can be easily activated by setting the KARAF_DEBUG
environment variable to TRUE
.
This can be done using the following command on Unix systems:
export KARAF_DEBUG=true
On Windows, use the following command
set KARAF_DEBUG=true
Then, you can launch Karaf using the usual way:
bin/karaf
or
bin\karaf.bat
Last, inside your IDE, connect to the remote application (the default port to connect to is 5005).
Profiling
YourKit
You need a few steps to be able to profile Karaf using YourKit.
The first one is to edit the etc/config.properties
configuration file and add the following property:
org.osgi.framework.bootdelegation=com.yourkit.*
Then, set the JAVA_OPTS
environment variable:
export JAVA_OPTS='-Xmx512M -agentlib:yjpagent'
or, on Windows
set JAVA_OPTS='-Xmx512M -agentlib:yjpagent'
Run Karaf from the console, and you should now be able to connect using YourKit standalone or from your favorite IDE.