如题。各位哥哥姐姐帮帮忙。

解决方案 »

  1.   

    # 文件输出方式 
    # org.apache.log4j.ConsoleAppender(控制台)
    # org.apache.log4j.FileAppender(文件)
    # org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)
    # org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生新文件)
    # org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
    ## 文件输出格式
    # org.apache.log4j.HTMLLayout(以HTML表格形式布局),
    # org.apache.log4j.PatternLayout(可以灵活地指定布局模式),
    # org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串),
    # org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)
    #  打印输出
    #  %p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL
    # %r 输出自应用启动到输出该log信息耗费的毫秒数
    # %c 输出所属的类目,通常就是所在类的全名
    # %t 输出产生该日志事件的线程名
    # %n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n”
    # %d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,
    #  比如:%d{yyy MMM dd HH:mm:ss,SSS},输出类似: 2002年10月18日 22:10:28,921
    # %l 输出日志事件的发生位置,包括类目名、发生的线程,以及在代码中的行数  
    #set level
    log4j.rootLogger=DEBUG,stdout,R#set stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%5p[%t](%F:%L)-%m%n#set R
    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File = test.log4j
    log4j.appender.R.MaxFileSize = 300KB
    #keep one backup file 
    log4j.appender.R.MaxBackupIndex = 1
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern = $p%t%c - %m%n是这个么?我用过。
      

  2.   

    谢谢 package org.grlea.log;// $Id: SimpleLogger.java,v 1.12 2006/07/13 12:40:06 grlea Exp $
    // Copyright (c) 2004-2006 Graham Lea. All rights reserved.// Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    //
    //     http://www.apache.org/licenses/LICENSE-2.0
    //
    // Unless required by applicable law or agreed to in writing, software
    // distributed under the License is distributed on an "AS IS" BASIS,
    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    // See the License for the specific language governing permissions and
    // limitations under the License.import java.text.MessageFormat;
    import java.util.Date;/**
     * <p>Used to create log messages for a single class or instance of a class.</p>
     *
     * <p><code>SimpleLogger</code> is where it all happens, from a client's perspective.<br>
     * The easiest way to use Simple Log is to create one <code>SimpleLogger</code> for each class and
     * then log to it!</p>
     *
     * <p>1. Create a logger like this:<pre>
     *    private static final SimpleLogger log = new SimpleLogger(HelloWorld.class);
     * </pre></p>
     *
     * <p>2. And then use it like this:<pre>
     *       log.entry("main()");
     *       log.debugObject("argv", argv);
     *       if (argv.length == 0)
     *       {
     *          log.info("No arguments. Using defaults.");
     *          ...
     *       }
     *       ...
     *       log.exit("main()");
     * </pre></p>
     *
     * <p>
     * <code>SimpleLogger</code> provides for four types of log messages:
     * <ul>
     *    <li>
     *       "db" = Debug (see {@link #db SimpleLogger.db()})<br>
     *       Lets you log a simple log message, e.g. "Got to the point where you thought it wasn't
     *       getting to."
     *    </li><br><br>
     *    <li>
     *       "dbo" = Debug Object
     *       (see {@link #dbo(DebugLevel,String,Object) SimpleLogger.dbo()})
     *       <br>
     *       Debugs the name and value of an object. Specially handled variants exist for all primitives,
     *       Object[], byte[] and char[].
     *    </li><br><br>
     *    <li>
     *       "dbe" = Debug Exception (see {@link #dbe SimpleLogger.dbe()})<br>
     *       Special handling of exceptions that will print a stack trace (can be turned off).
     *    </li><br><br>
     *    <li>
     *       Tracing (see {@link #entry SimpleLogger.entry()} and {@link #exit SimpleLogger.exit()})<br>
     *       Logs entry to and exit from a method. Can be turned on/off independent of debug level.<br>
     *    </li>
     * </ul>
     *
     * as well as convenience methods, named after the various levels, as shortcuts to the above methods.
     * </p>
     *
     * <p>
     * Instance-based <code>SimpleLogger</code>s can be used to determine, from the log output,
     * exactly which object a log statement is coming from. This is useful when many objects of the same
     * class are all performing logging and it is crucial to analysis to know which object logged any
     * given message.<br><br>
     *
     * Here is an example of how an instance-based logger would be used:<pre>
     * public class
     * Test
     * {
     *    private final SimpleLogger log;
     *
     *    private final String id;
     *
     *    public
     *    Test(String id)
     *    {
     *       log = new SimpleLogger(Test.class, id);
     *       this.id = id;
     *    }
     * }</pre>
     * Note the following important features of this pattern and instance-based logs in general:
     * <ul>
     * <li>The <code>log</code> field is <i>not</i> static. There is one per instance.</li>
     * <li><code>&lt;ClassName&gt;.class</code> is used rather than <code>getClass()</code>. Otherwise,
     * if this class were subclassed, logging statements would appear with the subclass's name as the
     * source.</li>
     * <li>There are separate log formats for instance-based logs in the properties file.</li>
     * </ul>
     * </p>
     *
     * @version $Revision: 1.12 $
     * @author $Author: grlea $
     */
    这是日志工具中的一段注释 好像根log4j的不一样。这样的该如何做呢
      

  3.   

    这个能看的明白点。
    Used to create log messages for a single class or instance of a class.SimpleLogger is where it all happens, from a client's perspective.
    The easiest way to use Simple Log is to create one SimpleLogger for each class and then log to it!1. Create a logger like this:    private static final SimpleLogger log = new SimpleLogger(HelloWorld.class);
     2. And then use it like this:       log.entry("main()");
           log.debugObject("argv", argv);
           if (argv.length == 0)
           {
              log.info("No arguments. Using defaults.");
              ...
           }
           ...
           log.exit("main()");
     SimpleLogger provides for four types of log messages: "db" = Debug (see SimpleLogger.db())
    Lets you log a simple log message, e.g. "Got to the point where you thought it wasn't getting to." 
    "dbo" = Debug Object (see SimpleLogger.dbo()) 
    Debugs the name and value of an object. Specially handled variants exist for all primitives, Object[], byte[] and char[]. 
    "dbe" = Debug Exception (see SimpleLogger.dbe())
    Special handling of exceptions that will print a stack trace (can be turned off). 
    Tracing (see SimpleLogger.entry() and SimpleLogger.exit())
    Logs entry to and exit from a method. Can be turned on/off independent of debug level.as well as convenience methods, named after the various levels, as shortcuts to the above methods. Instance-based SimpleLoggers can be used to determine, from the log output, exactly which object a log statement is coming from. This is useful when many objects of the same class are all performing logging and it is crucial to analysis to know which object logged any given message.Here is an example of how an instance-based logger would be used: public class
     Test
     {
        private final SimpleLogger log;    private final String id;    public
        Test(String id)
        {
           log = new SimpleLogger(Test.class, id);
           this.id = id;
        }
     }
    Note the following important features of this pattern and instance-based logs in general: 
    The log field is not static. There is one per instance. 
    <ClassName>.class is used rather than getClass(). Otherwise, if this class were subclassed, logging statements would appear with the subclass's name as the source. 
    There are separate log formats for instance-based logs in the properties file. Author:
    $Author: grlea $
    @version
    $Revision: 1.12 $