Source Code Cross Referenced for SystemLogChute.java in  » Template-Engine » Velocity » org » apache » velocity » runtime » log » 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 » Template Engine » Velocity » org.apache.velocity.runtime.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.velocity.runtime.log;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.    
020:         */
021:
022:        import org.apache.velocity.runtime.RuntimeServices;
023:
024:        /**
025:         * Logger used when no other is configured.  By default, all messages
026:         * will be printed to the System.err output stream.
027:         *
028:         * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
029:         * @version $Id: SystemLogChute.java 463298 2006-10-12 16:10:32Z henning $
030:         */
031:        public class SystemLogChute implements  LogChute {
032:            public static final String RUNTIME_LOG_LEVEL_KEY = "runtime.log.logsystem.system.level";
033:            public static final String RUNTIME_LOG_SYSTEM_ERR_LEVEL_KEY = "runtime.log.logsystem.system.err.level";
034:
035:            private int enabled = TRACE_ID;
036:            private int errLevel = TRACE_ID;
037:
038:            public void init(RuntimeServices rs) throws Exception {
039:                // look for a level config property
040:                String level = (String) rs.getProperty(RUNTIME_LOG_LEVEL_KEY);
041:                if (level != null) {
042:                    // and set it accordingly
043:                    setEnabledLevel(toLevel(level));
044:                }
045:
046:                // look for an errLevel config property
047:                String errLevel = (String) rs
048:                        .getProperty(RUNTIME_LOG_SYSTEM_ERR_LEVEL_KEY);
049:                if (errLevel != null) {
050:                    setSystemErrLevel(toLevel(errLevel));
051:                }
052:            }
053:
054:            protected int toLevel(String level) {
055:                if (level.equalsIgnoreCase("debug")) {
056:                    return DEBUG_ID;
057:                } else if (level.equalsIgnoreCase("info")) {
058:                    return INFO_ID;
059:                } else if (level.equalsIgnoreCase("warn")) {
060:                    return WARN_ID;
061:                } else if (level.equalsIgnoreCase("error")) {
062:                    return ERROR_ID;
063:                } else {
064:                    return TRACE_ID;
065:                }
066:            }
067:
068:            protected String getPrefix(int level) {
069:                switch (level) {
070:                case WARN_ID:
071:                    return WARN_PREFIX;
072:                case INFO_ID:
073:                    return INFO_PREFIX;
074:                case DEBUG_ID:
075:                    return DEBUG_PREFIX;
076:                case TRACE_ID:
077:                    return TRACE_PREFIX;
078:                case ERROR_ID:
079:                    return ERROR_PREFIX;
080:                default:
081:                    return INFO_PREFIX;
082:                }
083:            }
084:
085:            /**
086:             * Logs messages to either std.out or std.err
087:             * depending on their severity.
088:             *
089:             * @param level severity level
090:             * @param message complete error message
091:             */
092:            public void log(int level, String message) {
093:                // pass it off
094:                log(level, message, null);
095:            }
096:
097:            /**
098:             * Logs messages to the system console so long as the specified level
099:             * is equal to or greater than the level this LogChute is enabled for.
100:             * If the level is equal to or greater than LogChute.ERROR_ID, 
101:             * messages will be printed to System.err. Otherwise, they will be 
102:             * printed to System.out. If a java.lang.Throwable accompanies the 
103:             * message, it's stack trace will be printed to the same stream
104:             * as the message.
105:             *
106:             * @param level severity level
107:             * @param message complete error message
108:             * @param t the java.lang.Throwable
109:             */
110:            public void log(int level, String message, Throwable t) {
111:                if (!isLevelEnabled(level)) {
112:                    return;
113:                }
114:
115:                String prefix = getPrefix(level);
116:                if (level >= this .errLevel) {
117:                    System.err.print(prefix);
118:                    System.err.println(message);
119:                    if (t != null) {
120:                        System.err.println(t.getMessage());
121:                        t.printStackTrace();
122:                    }
123:                } else {
124:                    System.out.print(prefix);
125:                    System.out.println(message);
126:                    if (t != null) {
127:                        System.out.println(t.getMessage());
128:                        t.printStackTrace(System.out);
129:                    }
130:                }
131:            }
132:
133:            /**
134:             * Set the minimum level at which messages will be printed.
135:             */
136:            public void setEnabledLevel(int level) {
137:                this .enabled = level;
138:            }
139:
140:            /**
141:             * Returns the current minimum level at which messages will be printed.
142:             */
143:            public int getEnabledLevel() {
144:                return this .enabled;
145:            }
146:
147:            /**
148:             * Set the minimum level at which messages will be printed to System.err
149:             * instead of System.out.
150:             */
151:            public void setSystemErrLevel(int level) {
152:                this .errLevel = level;
153:            }
154:
155:            /**
156:             * Returns the current minimum level at which messages will be printed
157:             * to System.err instead of System.out.
158:             */
159:            public int getSystemErrLevel() {
160:                return this .errLevel;
161:            }
162:
163:            /**
164:             * This will return true if the specified level
165:             * is equal to or higher than the level this
166:             * LogChute is enabled for.
167:             */
168:            public boolean isLevelEnabled(int level) {
169:                return (level >= this.enabled);
170:            }
171:
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.