Accueil > Java > Print a debug message with the class name and line position

Print a debug message with the class name and line position

28/01/2009

// Print a debug message with the class container name and the line position
public static void debug(String message) {
    try {
        throw new Throwable();
    } catch (Throwable th) {
        StackTraceElement elmt = th.getStackTrace()[1];
        System.out.println("[DEBUG] "+elmt.getClassName()+"."+elmt.getMethodName()+"("+elmt.getFileName()+":"+elmt.getLineNumber()+") # "+message);
    }
}

Java

Les commentaires sont fermés.