public class hiStack extends Object
| 修飾子とタイプ | メソッドと説明 |
|---|---|
static String |
className(Object obj_)
Objectのクラス名を得る.
|
static String |
currentFuncName()
カレント関数名を得る.
|
static long |
currentThreadId()
カレントスレッドidを得る.
|
static String[] |
funcNameNest()
関数ネストを得る(全段).
|
static String[] |
funcNameNest(int level_)
関数ネストを得る(段数指定).
|
static String[] |
funcNameNest(int start_,
int level_)
指定親レベルからび関数ネストを得る(段数指定).
|
static void |
get_trace_format_expanded(StringBuilder sb_) |
static void |
get_trace_format_expanded(StringBuilder sb_,
otsu.hiNote.hiStack.TraceFormat trace_format_)
トレース用フォーマット展開.
|
static String |
getStackTrace(Exception ex_)
ExceptionのstackTraceを文字列に得る.
|
static String |
indent(int level_)
階層を表す文字列を作成する.
|
static String |
indent(int level_,
String indent1_,
String indent2_)
階層を文字列(パターン指定)を作成する.
|
static String |
lineNumber(int level_)
ファイル名#行番号を得る.
|
static String |
lineNumber(int level_,
long option_)
ファイル名#行番号を得る.
|
static String |
parentFuncName(int level_)
親関数名を得る.
|
static String |
parentFuncName(int level_,
long option_)
親関数名を得る.
|
static void |
setThreadTraceFormat(String fmt_,
long option_,
int fold_)
スレッド毎の関数トレースのフォーマットを指定する.
|
static void |
setTraceFold(int fold_level_)
関数トレースの折りたたみ段数を指定する
|
static void |
setTraceFormat(String fmt_,
long option_,
int fold_level_)
関数トレースのフォーマットを指定する.
|
static String |
str(Throwable ex_)
短縮Exception文字列を得る(スタックトレースなどオプション付き).
|
static String |
str(Throwable ex_,
long option_,
int depth_)
短縮Exception文字列を得る(スタックトレースなどオプション付き).
|
public static void setTraceFormat(String fmt_, long option_, int fold_level_)
先頭引数でhiU.i(),hiU.o()などのトレースのネストの前に置く情報形式を指定します。
情報種は1文字で指定しスレッドID(T),年月日(d),月日(D),時刻(t),ミリ秒(m)
となっています。それ以外の文字はそのまま反映されます。
Tdtmを含む文字列を出したい場合はシングルクオートまたはダブルクオートで囲みます。
シングルクオートを出したい場合はダブルクオートで囲みます。
ダブルクオートを出したい場合はシングルクオートで囲みます。
デフォルトのフォーマットは"T "です。
2番目の引数はソース行数を表示するかどうかを指定します。
対象クラスが行番号情報を持つ場合"#行番号"が表示されます。
呼び出し元のソース行数が(from クラス名.メンバ名#行番号)で表示されます。
hiU.NO_LINE_NUMBERを指定すると当該関数のソース情報を表示しません。
hiU.OMIT_CALLERを指定すると呼び出し元のソース情報を表示しません。
3番目の引数はネストが深くなった場合の折りたたみ単位をしていします。10を指定すると、10段以上のネストが有る場合、10段ごとに1段に折りたたまれて表示します。
hiU.setTraceFormat("T ",hiU.NO_OPTION,10);//デフォルト
0001 | | | -->TraceSample.woo#231 i=4
hiU.setTraceFormat("d t m ",hiU.NO_LINE_NUMBER|hiU.OMIT_CALLER,10);
2009/11/03 10:10:18 921 | | | -->TraceSample.woo i=4
hiU.setTraceFormat("T6) t.m "),true,10;
000001) 10:16:33.984 | | | -->TraceSample.woo#375 i=4
fmt_ - フォーマットを表す文字列option_ - オプション(hiU.NO_LINE_NUMBER,hiU.OMIT_CALLERが有効) 0:デフォルトfold_level_ - 折りたたみレベル(このレベルを超える場合、このレベル単位でネスト表示が折りたたまれる)1を指定すると折りたたまれません。0を指定するとデフォルト(10)となります。public static void setTraceFold(int fold_level_)
fold_level_ - 折りたたみレベル(このレベルを超える場合、このレベル単位でネスト表示が折りたたまれる)1を指定すると折りたたまれません。0を指定するとデフォルト(10)となります。public static void setThreadTraceFormat(String fmt_, long option_, int fold_)
引数に関してはsetTraceFormat(String,long,int)を参照してください。
hiU.setTraceFormat("T ",hiU.NO_OPTION,10);//デフォルト
0001 | | | -->TraceSample.woo#231 i=4
hiU.setTraceFormat("d t m ",hiU.NO_LINE_NUMBER,10);
2009/11/03 10:10:18 921 | | | -->TraceSample.woo i=4
hiU.setTraceFormat("T) t.m ");
0001) 10:16:33.984 | | | -->TraceSample.woo i=4
fmt_ - フォーマットを表す文字列option_ - オプション(hiU.NO_LINE_NUMBERが有効) 0:デフォルトfold_ - 折りたたみレベル(このレベルを超える場合、このレベル単位でネスト表示が折りたたまれる)1を指定すると折りたたまれません。0を指定するとデフォルト(10)となります。public static String lineNumber(int level_, long option_)
level_ - 0:自分,1:親,2:親の親option_ - hiU.TRIM_SUFFIXを指定するとファイル名の.javaを削除hiU.currentFuncName(),
hiU.parentFuncName(),
hiU.currentThreadId()public static String lineNumber(int level_)
level_ - 0:自分,1:親,2:親の親hiU.currentFuncName(),
hiU.parentFuncName(),
hiU.currentThreadId()public static String[] funcNameNest(int level_)
カレント関数を含む関数の呼び出しネストを得ます。
関数名は"クラス名.関数名"の形です。引数型は表示されません。
配列先頭がカレント関数となります。
取得する呼び出し段数を指定できます。
level_ - 取得する最大段数hiU.funcNameNest(),
hiU.currentFuncName(),
hiU.parentFuncName(),
hiU.currentThreadId(),
Thread.currentThread(),
thread.getStackTrace(),
StackTraceElementpublic static String[] funcNameNest(int start_, int level_)
関数の呼び出しネストを得ます。
関数名は"クラス名.関数名"の形です。引数型は表示されません。
配列先頭がカレント関数からstart_分さかのぼった位置となります。
0は自分自身です。
取得する呼び出し段数を指定できます。
start_ - 開始位置level_ - 取得する最大段数hiU.funcNameNest(),
StackTraceElementpublic static String[] funcNameNest()
カレント関数を含む関数の呼び出しネストを得ます。
関数名は"クラス名.関数名"の形です。引数型は表示されません。
配列先頭がカレント関数となります。
取得する呼び出し段数を指定できます。
public static String currentFuncName()
hiU.currentFuncName(),
hiU.parentFuncName(),
hiU.currentThreadId()public static String parentFuncName(int level_)
level_ - 0:自分,1:親,2:親の親hiU.currentFuncName(),
hiU.parentFuncName(),
hiU.currentThreadId()public static String parentFuncName(int level_, long option_)
level_ - 0:自分,1:親,2:親の親option_ - hiU.WITH_LINE_NUMBERを指定すると、後ろにファイル名と行番号が付加hiU.currentFuncName(),
hiU.parentFuncName(),
hiU.currentThreadId()public static void get_trace_format_expanded(StringBuilder sb_)
public static void get_trace_format_expanded(StringBuilder sb_, otsu.hiNote.hiStack.TraceFormat trace_format_)
sb_ - ここに展開されるtrace_format_ - 定義されたフォーマットpublic static String indent(int level_)
level_ - ネストレベルpublic static String indent(int level_, String indent1_, String indent2_)
level_ - ネストレベルindent1_ - インデントに用いる文字列1indent2_ - インデントに用いる文字列2public static String className(Object obj_)
次のコードと同じです。
Object o; // oにクラスセット String name= o==null?"nuLL":o.getClass().getSimpleName();
obj_ - 対象Objectpublic static long currentThreadId()
次の操作と同等です。
Thread.currentThread().getId()
currentFuncName(),
parentFuncName(int)public static final String str(Throwable ex_, long option_, int depth_)
クラス名とメッセージからなる短縮表現を得ます。
hiU.WITH_STACKオプションを付けるとスタックトレースが表示されます。
ファイル名とクラス名が一致する場合はファイル名は省略されます。
depth_でスタックレベルの最大連続個数を指定できます。例えばLENGTH_2を指定した場合、
hiU.err.println(hiU.str(ex,hiU.WITH_STACK,2));
---
ArrayIndexOutOfBoundsException: 2
@ Test.foo1(#25) <-- (Test.java#25)だがクラス名と一致するので(#25)と表示
@ Test.foo2(#28)
... 3 ... <-- mainも含め7段、中3段を省略
@ Test.foo6(#40)
@ Test.main(#105)
ex_ - 例外option_ - オプションdepth_ - スタックレベルの最大連続個数public static final String str(Throwable ex_)
ex_ - 例外public static String getStackTrace(Exception ex_)
ExceptionのstackTraceをStringの形で得ます。
次の操作と同等です。
// Exception ex_
StringWriter _sw = new StringWriter();
PrintWriter _pw = new PrintWriter(_sw);
_ex.printStackTrace(_pw);
_pw.flush();
String _stackTrace= _sw.toString();
ex_ - スタックトレースを得たいException