KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > LogLayout


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.util;
15
16 import java.sql.Timestamp JavaDoc;
17 import java.awt.Toolkit JavaDoc;
18
19 import org.apache.log4j.*;
20 import org.apache.log4j.spi.*;
21
22
23 /**
24  * Log4J Formatter
25  *
26  * @author Jorg Janke
27  * @version $Id: LogLayout.java,v 1.2 2003/03/20 06:51:23 jjanke Exp $
28  */

29 public class LogLayout extends Layout
30 {
31     /**
32      * Constructor
33      */

34     public LogLayout()
35     {
36     } // LogLayout
37

38     /**
39      * Create layout format.
40      * @param event log event
41      * @return formatted string
42      */

43     public String JavaDoc format (LoggingEvent event)
44     {
45         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
46         Timestamp JavaDoc ts = new Timestamp JavaDoc(event.timeStamp);
47         String JavaDoc tstr = ts.toString() + "00";
48         //
49
int prio = event.getLevel().toInt(); // Priority
50
if (prio == Priority.FATAL_INT || prio == Priority.ERROR_INT)
51         {
52             // 12:12:12.123
53
sb.append("===========> ");
54             //
55
Toolkit.getDefaultToolkit().beep();
56             //
57
if (event.getMessage() != null)
58                 Log.writeDBLog(event.getLoggerName(), event.getMessage().toString());
59         }
60         else
61         {
62             sb.append(tstr.substring(11, 23));
63             int level = 1;
64         // if (prio == Priority.INFO_INT);
65
if (prio == Priority.DEBUG_INT)
66                 level = 2;
67             // + " [" + level + "]"
68
sb.append(" ".substring(0, level << 1));
69         }
70         String JavaDoc className = event.getLoggerName();
71         int pos = className.lastIndexOf('.');
72         if (pos != -1)
73             className = className.substring(pos+1);
74         sb.append(className)
75             .append(": ")
76             .append(event.getMessage());
77
78         // Throwable
79
ThrowableInformation ti = event.getThrowableInformation();
80         if (ti != null)
81         {
82         }
83
84         sb.append(Env.NL);
85         return sb.toString();
86     } // format
87

88     /**
89         If the layout handles the throwable object contained within
90         {@link LoggingEvent}, then the layout should return
91         <code>false</code>. Otherwise, if the layout ignores throwable
92         object, then the layout should return <code>true</code>.
93      * @return false
94      **/

95     public boolean ignoresThrowable()
96     {
97         return true;
98     }
99
100     /**
101        Does not do anything as options become effective
102     */

103     public void activateOptions()
104     {
105         // nothing to do.
106
}
107
108 } // LogLayout
109
Popular Tags