[英]how to code with debug options in java
我正在嘗試學習有關如何運行代碼的技巧,當打開調試標志時,該代碼將打印很多內容。
這是如何在Java中完成的。
我能想到的一種非常幼稚的方法是在我編寫的所有方法中都具有調試標志
並寫一些像
if (this.debug == true){
System.out.println("blah blah");
}
但是,應該有一種更優雅的方法,而不是在代碼中包含所有這些ifs?
另外,有沒有一種方法可以在代碼中獲取某些執行的行號:
例如,如果有例外
try:
/ *行號22 * /
catch Exception e{
//print that exception occured in above line number??
}
可能是非常la腳的問題。 謝謝
log4j API的簡單示例
private Logger _debugLogger = Logger.getLogger(yourClassName.class);
//For info mode
_debugLogger.info("Some Messages");
//or for debug mode
_debugLogger.debug(MessageFormat.format("Some message {0},{1},{2}",variable0, variable1,variable2));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.