Source Code Cross Referenced for CommandLineLogger.java in  » Graphic-Library » fop » org » apache » fop » 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 » Graphic Library » fop » org.apache.fop.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:        /* contributor license agreements.  See the NOTICE file distributed with
003:        /* this work for additional information regarding copyright ownership.
004:        /* The ASF licenses this file to You under the Apache License, Version 2.0
005:        /* (the "License"); you may not use this file except in compliance with
006:        /* the License.  You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        /* $Id: CommandLineLogger.java 563951 2007-08-08 17:37:33Z vhennebert $ */
018:
019:        package org.apache.fop.util;
020:
021:        import org.apache.commons.logging.Log;
022:        import org.apache.commons.logging.LogFactory;
023:
024:        /**
025:         * This is a commons-logging logger for command line use.
026:         */
027:        public class CommandLineLogger implements  Log {
028:            /** "Trace" level logging. */
029:            public static final int LOG_LEVEL_TRACE = 1;
030:            /** "Debug" level logging. */
031:            public static final int LOG_LEVEL_DEBUG = 2;
032:            /** "Info" level logging. */
033:            public static final int LOG_LEVEL_INFO = 3;
034:            /** "Warn" level logging. */
035:            public static final int LOG_LEVEL_WARN = 4;
036:            /** "Error" level logging. */
037:            public static final int LOG_LEVEL_ERROR = 5;
038:            /** "Fatal" level logging. */
039:            public static final int LOG_LEVEL_FATAL = 6;
040:
041:            private int logLevel;
042:            private String logName;
043:
044:            /**
045:             * Construct the logger with a default log level taken from the LogFactory 
046:             * attribute "level". 
047:             * @param logName the logger name.
048:             */
049:            public CommandLineLogger(String logName) {
050:                this .logName = logName;
051:                setLogLevel((String) LogFactory.getFactory().getAttribute(
052:                        "level"));
053:            }
054:
055:            /**
056:             * Set a log level for the logger.
057:             * @param level the log level
058:             */
059:            public void setLogLevel(String level) {
060:                if ("fatal".equals(level)) {
061:                    logLevel = LOG_LEVEL_FATAL;
062:                } else if ("error".equals(level)) {
063:                    logLevel = LOG_LEVEL_ERROR;
064:                } else if ("warn".equals(level)) {
065:                    logLevel = LOG_LEVEL_WARN;
066:                } else if ("info".equals(level)) {
067:                    logLevel = LOG_LEVEL_INFO;
068:                } else if ("debug".equals(level)) {
069:                    logLevel = LOG_LEVEL_DEBUG;
070:                } else if ("trace".equals(level)) {
071:                    logLevel = LOG_LEVEL_TRACE;
072:                } else {
073:                    logLevel = LOG_LEVEL_INFO;
074:                }
075:            }
076:
077:            /**
078:             * {@inheritDoc}
079:             */
080:            public final boolean isTraceEnabled() {
081:                return logLevel <= LOG_LEVEL_TRACE;
082:            }
083:
084:            /**
085:             * {@inheritDoc}
086:             */
087:            public final boolean isDebugEnabled() {
088:                return logLevel <= LOG_LEVEL_DEBUG;
089:            }
090:
091:            /**
092:             * {@inheritDoc}
093:             */
094:            public final boolean isInfoEnabled() {
095:                return logLevel <= LOG_LEVEL_INFO;
096:            }
097:
098:            /**
099:             * {@inheritDoc}
100:             */
101:            public final boolean isWarnEnabled() {
102:                return logLevel <= LOG_LEVEL_WARN;
103:            }
104:
105:            /**
106:             * {@inheritDoc}
107:             */
108:            public final boolean isErrorEnabled() {
109:                return logLevel <= LOG_LEVEL_ERROR;
110:            }
111:
112:            /**
113:             * {@inheritDoc}
114:             */
115:            public final boolean isFatalEnabled() {
116:                return logLevel <= LOG_LEVEL_FATAL;
117:            }
118:
119:            /**
120:             * {@inheritDoc}
121:             */
122:            public final void trace(Object message) {
123:                if (isTraceEnabled()) {
124:                    log(LOG_LEVEL_TRACE, message, null);
125:                }
126:            }
127:
128:            /**
129:             * {@inheritDoc}
130:             */
131:            public final void trace(Object message, Throwable t) {
132:                if (isTraceEnabled()) {
133:                    log(LOG_LEVEL_TRACE, message, t);
134:                }
135:            }
136:
137:            /**
138:             * {@inheritDoc}
139:             */
140:            public final void debug(Object message) {
141:                if (isDebugEnabled()) {
142:                    log(LOG_LEVEL_DEBUG, message, null);
143:                }
144:            }
145:
146:            /**
147:             * {@inheritDoc}
148:             */
149:            public final void debug(Object message, Throwable t) {
150:                if (isDebugEnabled()) {
151:                    log(LOG_LEVEL_DEBUG, message, t);
152:                }
153:            }
154:
155:            /**
156:             * {@inheritDoc}
157:             */
158:            public final void info(Object message) {
159:                if (isInfoEnabled()) {
160:                    log(LOG_LEVEL_INFO, message, null);
161:                }
162:            }
163:
164:            /**
165:             * {@inheritDoc}
166:             */
167:            public final void info(Object message, Throwable t) {
168:                if (isInfoEnabled()) {
169:                    log(LOG_LEVEL_INFO, message, t);
170:                }
171:            }
172:
173:            /**
174:             * {@inheritDoc}
175:             */
176:            public final void warn(Object message) {
177:                if (isWarnEnabled()) {
178:                    log(LOG_LEVEL_WARN, message, null);
179:                }
180:            }
181:
182:            /**
183:             * {@inheritDoc}
184:             */
185:            public final void warn(Object message, Throwable t) {
186:                if (isWarnEnabled()) {
187:                    log(LOG_LEVEL_WARN, message, t);
188:                }
189:            }
190:
191:            /**
192:             * {@inheritDoc}
193:             */
194:            public final void error(Object message) {
195:                if (isErrorEnabled()) {
196:                    log(LOG_LEVEL_ERROR, message, null);
197:                }
198:            }
199:
200:            /**
201:             * {@inheritDoc}
202:             */
203:            public final void error(Object message, Throwable t) {
204:                if (isErrorEnabled()) {
205:                    log(LOG_LEVEL_ERROR, message, t);
206:                }
207:            }
208:
209:            /**
210:             * {@inheritDoc}
211:             */
212:            public final void fatal(Object message) {
213:                if (isFatalEnabled()) {
214:                    log(LOG_LEVEL_FATAL, message, null);
215:                }
216:            }
217:
218:            /**
219:             * {@inheritDoc}
220:             */
221:            public final void fatal(Object message, Throwable t) {
222:                if (isFatalEnabled()) {
223:                    log(LOG_LEVEL_FATAL, message, t);
224:                }
225:            }
226:
227:            /**
228:             * Do the actual logging.
229:             * This method assembles the message and prints it to
230:             * and then calls <code>write()</code> to cause it to be written.</p>
231:             *
232:             * @param type One of the LOG_LEVEL_XXX constants defining the log level
233:             * @param message The message itself (typically a String)
234:             * @param t The exception whose stack trace should be logged
235:             */
236:            protected void log(int type, Object message, Throwable t) {
237:                StringBuffer buf = new StringBuffer();
238:                // Append the message
239:                buf.append(String.valueOf(message));
240:                if (t != null) {
241:                    buf.append("\n");
242:                    // Append a stack trace or just the stack trace message.
243:                    if (!isDebugEnabled()) {
244:                        buf.append(t.toString());
245:                        buf.append("\n");
246:                    } else {
247:                        java.io.StringWriter sw = new java.io.StringWriter(1024);
248:                        java.io.PrintWriter pw = new java.io.PrintWriter(sw);
249:                        t.printStackTrace(pw);
250:                        pw.close();
251:                        buf.append(sw.toString());
252:                    }
253:                }
254:
255:                // Print to the appropriate destination
256:                if (type >= LOG_LEVEL_WARN) {
257:                    System.err.println(buf);
258:                } else {
259:                    System.out.println(buf);
260:                }
261:
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.