Nonsense not much to say that directly on the code
Copy Code code as follows:
Import Java.text.SimpleDateFormat;
Import Java.util.Date;
/**
* Java implementation similar to C + + in the __file__, __func__, __line__, etc., mainly for the functions of the log.
*
* @version 1.0
*
*/
Public abstract class Commonfunction {
/**
* Log when the current program file name, line number, method name output format is: [FileName | linenumber | MethodName]
*
* @return
*/
public static String Getfilelinemethod () {
Stacktraceelement traceelement = (new Exception ()). Getstacktrace ()) [1];
StringBuffer tostringbuffer = new StringBuffer ("["). Append (
Traceelement.getfilename ()). Append ("|"). Append
Traceelement.getlinenumber ()). Append ("|"). Append
Traceelement.getmethodname ()). Append ("]");
return tostringbuffer.tostring ();
}
Current file name
public static String _file_ () {
Stacktraceelement traceelement = (new Exception ()). Getstacktrace ()) [1];
return Traceelement.getfilename ();
}
Current method Name
public static String _func_ () {
Stacktraceelement traceelement = (new Exception ()). Getstacktrace ()) [1];
return Traceelement.getmethodname ();
}
Current line number
public static int _line_ () {
Stacktraceelement traceelement = (new Exception ()). Getstacktrace ()) [1];
return Traceelement.getlinenumber ();
}
Current time
public static String _time_ () {
Date now = new Date ();
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss". SSS ");
Return Sdf.format (now);
}
}