-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
curvefs/sdk: log call stack to stdout for hadoop filesystem on debug …
…mode. Signed-off-by: Wine93 <[email protected]>
- Loading branch information
Showing
5 changed files
with
137 additions
and
47 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
curvefs/sdk/java/src/main/java/io/opencurve/curve/fs/common/StackLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.opencurve.curve.fs.common; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class StackLogger { | ||
private String classname; | ||
private int level; | ||
|
||
private static final String CURVEFS_DEBUG_ENV_VAR = "CURVEFS_DEBUG"; | ||
|
||
public StackLogger(String classname, int level) { | ||
this.classname = classname; | ||
this.level = level; | ||
} | ||
|
||
private String now() { | ||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | ||
return formatter.format(new Date()); | ||
} | ||
|
||
public void log(String fn, Object... args) { | ||
String value = System.getenv(CURVEFS_DEBUG_ENV_VAR); | ||
if (!Boolean.valueOf(value)) { | ||
return; | ||
} | ||
|
||
String[] params = new String[args.length]; | ||
for (int i = 0; i < args.length; i++) { | ||
params[i] = args[i].toString(); | ||
} | ||
|
||
String indent = " ".repeat(this.level * 4); | ||
String param = String.join(",", params); | ||
String message = String.format("+ [%s] %s%s.%s(%s)", now(), indent, this.classname, fn, param); | ||
System.out.println(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.