• Showing Page History #12415

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 void Sample(){
  6. logger = Logger.getInstance();
  7. if( logger.isDebugEnable() ){
  8. logger.debug( "class Sample created." );
  9. }
  10. }
  11. public foo( Sample sample ) throws Exception {
  12. if( logger.isDebugEnable() ){
  13. StringBuffer buf = new StringBuffer();
  14. buf.append( "Sample::foo( Sample sample ) throws Exception in sample = " );
  15. if( null != sample ){
  16. buf.append( sample );
  17. }
  18. else{
  19. buf.append( " is NULL" );
  20. }
  21. logger.debug( buf.toString() );
  22. }
  23. if( null != sample ){
  24. logger.error( "in sample value is null. check configure" );
  25. }
  26. }
  27. }