Question

I am writing java code and would like to use dbgview (and log4j if possible). By searching the documentation of log4j it seems that unlike log4net, log4j does not support the OutputDebugStringAppender which redirect output to what dbgview listens to.

How can one create a log file that dbgview can parse? How can one send string to the debug stream from java? Is there any debugview alternative for java?

I am using eclipse, Windows 7 and latest log4j jar.

Was it helpful?

Solution

Java does not have a native functionality to send over debug prints to Windows debug output.

However you can easily do it by importing the Windows OutputDebugString function using JNA. It will break any multi-platform functionality (you will only be able to run on windows) but it will work.

You can do something like this :

import com.sun.jna.Library;
import com.sun.jna.Native;

public interface Kernel32 extends Library
{
    public void OutputDebugStringA(String Text);
}

When calling OutputDebugString you need to do this :

 Kernel32 lib = (Kernel32) Native.loadLibrary(“kernel32″, Kernel32.class);
 lib.OutputDebugStringA(message);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top