Source Code Cross Referenced for Log.java in  » Database-Client » executequery » org » executequery » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » executequery » org.executequery.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Log.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.executequery.util;
023:
024:        import java.io.IOException;
025:        import java.io.Serializable;
026:        import org.apache.log4j.Appender;
027:        import org.apache.log4j.Level;
028:        import org.apache.log4j.Logger;
029:        import org.apache.log4j.PatternLayout;
030:        import org.apache.log4j.RollingFileAppender;
031:        import org.executequery.SystemUtilities;
032:        import org.underworldlabs.util.SystemProperties;
033:
034:        /* ----------------------------------------------------------
035:         * CVS NOTE: Changes to the CVS repository prior to the 
036:         *           release of version 3.0.0beta1 has meant a 
037:         *           resetting of CVS revision numbers.
038:         * ----------------------------------------------------------
039:         */
040:
041:        /**
042:         *  <p>Logger wrapper class.<br>
043:         *  Provides static methods to the Log4J logging methods.
044:         *  This is a convenience class only and can not be instantiated.
045:         *
046:         *  @author   Takis Diakoumis
047:         * @version  $Revision: 1.9 $
048:         * @date     $Date: 2006/09/24 16:24:01 $
049:         */
050:        public class Log implements  Serializable {
051:
052:            /** The Log4J Logger object */
053:            private static Logger logger;
054:
055:            /** the logger name */
056:            public static final String LOGGER_NAME = "system-logger";
057:
058:            /** the log pattern string */
059:            public static final String PATTERN = "[%d{HH:mm:ss}] %m%n";
060:
061:            /** the max number of log files rolled over */
062:            public static final int MAX_BACKUP_INDEX = 5;
063:
064:            /** <p><code>private<code> constructor to prevent instantiation. */
065:            private Log() {
066:            }
067:
068:            /**
069:             * Initialises the logger instance with the default level.
070:             */
071:            public static void init() {
072:                init("INFO");
073:            }
074:
075:            /**
076:             * Initialises the logger instance with the specified level.
077:             *
078:             * @param level - the log level
079:             */
080:            public static void init(String level) {
081:                // if we are already running - bail
082:                if (isLogEnabled()) {
083:                    return;
084:                }
085:
086:                logger = Logger.getLogger(LOGGER_NAME);
087:                try {
088:                    if (level != null) {
089:                        setLevel(level);
090:                    } else { // default to INFO
091:                        setLevel("INFO");
092:                    }
093:
094:                    // the log file path
095:                    String path = SystemUtilities.getSystemLogPath();
096:
097:                    // init the patter layout
098:                    PatternLayout patternLayout = new PatternLayout(PATTERN);
099:                    RollingFileAppender appender = new RollingFileAppender(
100:                            patternLayout, path, true);
101:                    appender.setMaxBackupIndex(MAX_BACKUP_INDEX);
102:                    appender.setMaxFileSize("1MB");
103:                    logger.addAppender(appender);
104:                } catch (IOException ioExc) {
105:                    ioExc.printStackTrace();
106:                }
107:            }
108:
109:            /**
110:             * Adds the specified appender to the logger.
111:             *
112:             * @param appender - the appender to be added
113:             */
114:            public static void addAppender(Appender appender) {
115:                if (logger == null) {
116:                    throw new RuntimeException("Logger not initialised.");
117:                }
118:                logger.addAppender(appender);
119:            }
120:
121:            /**
122:             * Returns whether the log level is set to DEBUG.
123:             */
124:            public static boolean isDebugEnabled() {
125:                if (logger != null) {
126:                    return logger.isDebugEnabled();
127:                }
128:                return false;
129:            }
130:
131:            /**
132:             * Sets the logger level to that specified.
133:             *
134:             * @param level - the logger level to be set.<br>
135:             *        Valid values are: ERROR, DEBUG, INFO, WARN, ALL, FATAL, TRACE
136:             */
137:            public static void setLevel(String level) {
138:                if (level == null) {
139:                    return;
140:                }
141:
142:                level = level.toUpperCase();
143:                if (level.equals("INFO")) {
144:                    logger.setLevel((Level) Level.INFO);
145:                } else if (level.equals("WARN")) {
146:                    logger.setLevel((Level) Level.WARN);
147:                } else if (level.equals("DEBUG")) {
148:                    logger.setLevel((Level) Level.DEBUG);
149:                } else if (level.equals("ERROR")) {
150:                    logger.setLevel((Level) Level.ERROR);
151:                } else if (level.equals("FATAL")) {
152:                    logger.setLevel((Level) Level.FATAL);
153:                } else if (level.equals("TRACE")) {
154:                    logger.setLevel((Level) Level.TRACE);
155:                } else if (level.equals("ALL")) {
156:                    logger.setLevel((Level) Level.ALL);
157:                }
158:
159:            }
160:
161:            /**
162:             * Logs a message at log level INFO.
163:             *
164:             * @param message  the log message.
165:             * @param throwable the throwable.
166:             */
167:            public static void info(Object message, Throwable throwable) {
168:                if (logger == null) {
169:                    return;
170:                }
171:                logger.info(message, throwable);
172:            }
173:
174:            /**
175:             * Logs a message at log level WARN.
176:             *
177:             * @param message  the log message.
178:             * @param throwable the throwable.
179:             */
180:            public static void warning(Object message, Throwable throwable) {
181:                if (logger == null) {
182:                    return;
183:                }
184:                logger.warn(message, throwable);
185:            }
186:
187:            /**
188:             * Logs a message at log level DEBUG.
189:             *
190:             * @param message  the log message.
191:             */
192:            public static void debug(Object message) {
193:                if (logger == null || !logger.isDebugEnabled()) {
194:                    return;
195:                }
196:                logger.debug(message);
197:            }
198:
199:            /**
200:             * Logs a message at log level DEBUG.
201:             *
202:             * @param message  the log message.
203:             * @param throwable the throwable.
204:             */
205:            public static void debug(Object message, Throwable throwable) {
206:                if (logger == null || !logger.isDebugEnabled()) {
207:                    return;
208:                }
209:                logger.debug(message, throwable);
210:            }
211:
212:            /**
213:             * Logs a message at log level ERROR.
214:             *
215:             * @param message  the log message.
216:             * @param throwable the throwable.
217:             */
218:            public static void error(Object message, Throwable throwable) {
219:                if (logger == null) {
220:                    System.out.println("ERROR: " + message);
221:                    throwable.printStackTrace();
222:                    return;
223:                }
224:                logger.error(message, throwable);
225:            }
226:
227:            /**
228:             * Logs a message at log level INFO.
229:             *
230:             * @param message  the log message.
231:             */
232:            public static void info(Object message) {
233:                if (logger == null) {
234:                    return;
235:                }
236:                logger.info(message);
237:            }
238:
239:            /**
240:             * Logs a message at log level WARN.
241:             *
242:             * @param message  the log message.
243:             */
244:            public static void warning(Object message) {
245:                if (logger == null) {
246:                    return;
247:                }
248:                logger.warn(message);
249:            }
250:
251:            /**
252:             * Logs a message at log level ERROR.
253:             *
254:             * @param message  the log message.
255:             */
256:            public static void error(Object message) {
257:                if (logger == null) {
258:                    System.err.println("ERROR: " + message);
259:                    return;
260:                }
261:                logger.error(message);
262:            }
263:
264:            /**
265:             * Returns whether a logger exists and
266:             * has been initialised.
267:             *
268:             * @return <code>true</code> if initialised |
269:             *         <code>false</code> otherwise
270:             */
271:            public static boolean isLogEnabled() {
272:                return logger != null;
273:            }
274:
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.