All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.dmerkushov.loghelper.StackTraceUtils Maven / Gradle / Ivy

Go to download

A library to help use different logging frameworks, such as java.util.logging (JUL) and Apache Log4j, even together. See also https://github.com/dmerkushov/log-helper-examples

The newest version!
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.dmerkushov.loghelper;

/**
 *
 * @author Dmitriy Merkushov
 */
public class StackTraceUtils {

	/**
	 * Get the StackTraceElement of the method that called the caller of getCallerStackTraceElement ()
	 * @return may be null
	 */
	public static StackTraceElement getCallerStackTraceElement () {
		StackTraceElement callerStackTraceElement = null;

		StackTraceElement[] stackTraceElements = Thread.currentThread ().getStackTrace ();
		if (stackTraceElements != null) {
			if (stackTraceElements.length > 3) {
				callerStackTraceElement = stackTraceElements[3];
			}
		}

		return callerStackTraceElement;
	}
	
	/**
	 * Get the StackTraceElement of the caller of getMyStackTraceElement ()
	 * @return 
	 */
	public static StackTraceElement getMyStackTraceElement () {
		StackTraceElement myStackTraceElement = null;
		
		StackTraceElement[] stackTraceElements = Thread.currentThread ().getStackTrace ();
		if (stackTraceElements != null) {
			if (stackTraceElements.length > 2) {
				myStackTraceElement = stackTraceElements[2];
			}
		}

		return myStackTraceElement;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy