File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
src/main/java/org/apache/hadoop/fs/glusterfs Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -63,12 +63,23 @@ public class GlusterDebugFileSystem extends GlusterFileSystem{
63
63
64
64
private static File logFile =null ;
65
65
private static final String LOG_PREFIX ="/tmp/glusterfs" ;
66
-
66
+ private static boolean showStackTrace = true ;
67
+
68
+ public static synchronized String getStackTrace (int stripTopElements ){
69
+ StackTraceElement [] trace = Thread .currentThread ().getStackTrace ();
70
+ String traceString = "" ;
71
+ // remove the specified top elements of the stack trace (to avoid debug methods in the trace). the +1 is for this methods call.
72
+ for (int i =stripTopElements +1 ;i <trace .length ;i ++){
73
+ traceString += "\t [" + trace [i ].getFileName () + "] " + trace [i ].getClassName () + "." + trace [i ].getMethodName () + "() line:" + trace [i ].getLineNumber () + "\n " ;
74
+ }
75
+
76
+ return traceString ;
77
+ }
78
+
67
79
public static synchronized void logMachine (String text ){
68
80
69
81
DateFormat dateFormat =new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss" );
70
82
Date date =new Date ();
71
-
72
83
if (logFile ==null ){
73
84
for (int i =0 ;i <1000000 ;i ++){
74
85
logFile =new File (LOG_PREFIX +"-" +i +".log" );
@@ -84,7 +95,9 @@ public static synchronized void logMachine(String text){
84
95
85
96
try {
86
97
PrintWriter out =new PrintWriter (new BufferedWriter (new FileWriter (logFile , true )));
87
- out .write (dateFormat .format (date )+" : " +text +"\n " );
98
+ out .write ("(" + dateFormat .format (date )+") : " +text +"\n " );
99
+ String stackTrace = GlusterDebugFileSystem .getStackTrace (3 );
100
+ if (showStackTrace ) out .write (stackTrace );
88
101
out .close ();
89
102
}catch (FileNotFoundException e ){
90
103
e .printStackTrace ();
You can’t perform that action at this time.
0 commit comments