Log Debug java

---

Debugで出力するLogは基本的に以下の情報を出力する。

  • コンストラクタ時のメッセージ
  • 関数の入通知と引数のダンプ
  • 関数の出通知と返値のダンプ
  • servletの場合には受け取ったPOSTデータの値

    以下必要な情報は随時追加

---

またdebugログを出力する場合は必ず現状のログレベルがdebugであることを確認し、出力するデータを作成すること。

---

example. jsp

  1. <%@ page language="java" contentType="text/html; charset=ASCII" %>
  2. <%@ page import="org.apache.log4j*" %>
  3. <%@ page import="org.ultramonkey.l7.model.*" %>
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html"; charset=ASCII">
  7. <title>sample</title>
  8. <body>
  9. <%
  10. Logger logger = Logger.getLogger( LogCategorySet.JSPCategory );
  11. if( logger.isDebugEnable() ){
  12. logger.debug( "sample.jsp start" );
  13. }
  14. SampleClass sampleClass = SampleClass.getInstance();
  15. if( null == sampleClass ){
  16. logger.error( "SampleClass.getInstance() is NULL!" );
  17. }
  18. %>
  19. hello world!
  20. <%
  21. if( logger.isDebugEnable() ){
  22. logger.debug( "sample.jsp exit" );
  23. }
  24. %>
  25. </body>
  26. </html>

example class

  1. package org.ultramonkey.l7;
  2. import org.apache.log4j.*;
  3. public class Sample{
  4. Logger logger = null;
  5. public Sample(){
  6. logger = Logger.getInstance( LogCategorySet.SampleCategory );
  7. if( logger.isDebugEnable() ){
  8. logger.debug( "class Sample created." );
  9. }
  10. }
  11. public String foo(Sample sample, String string) throws Exception {
  12. // debug log (in method)
  13. if( logger.isDebugEnable() ){
  14. StringBuffer buf = new StringBuffer();
  15. buf.append("Sample::foo(Sample sample, String string) throws Exception in ");
  16. buf.append("sample=" + sample + ", ");
  17. buf.append("string=" + string);
  18. logger.debug(buf.toString());
  19. }
  20. if( null != sample ){
  21. logger.error( "in sample value is null. check configure" );
  22. }
  23. // debug log (out method)
  24. if( logger.isDebugEnable() ){
  25. StringBuffer buf = new StringBuffer();
  26. buf.append("Sample::foo(Sample sample, String string) throws Exception out ");
  27. buf.append("return=" + sample.toString + string);
  28. logger.debug(buf.toString());
  29. }
  30. return sample.toString + string;
  31. }
  32. }