Source Code Cross Referenced for Hierarchy.java in  » Net » openfire » org » jivesoftware » util » 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 » Net » openfire » org.jivesoftware.util.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The Apache Software Foundation. All rights reserved.
003:         *
004:         * This software is published under the terms of the Apache Software License
005:         * version 1.1, a copy of which has been included with this distribution in
006:         * the LICENSE file.
007:         */
008:        package org.jivesoftware.util.log;
009:
010:        import org.jivesoftware.util.log.format.PatternFormatter;
011:        import org.jivesoftware.util.log.output.io.StreamTarget;
012:        import org.jivesoftware.util.log.util.DefaultErrorHandler;
013:
014:        /**
015:         * This class encapsulates a basic independent log hierarchy.
016:         * The hierarchy is essentially a safe wrapper around root logger.
017:         *
018:         * @author <a href="mailto:peter@apache.org">Peter Donald</a>
019:         */
020:        public class Hierarchy {
021:            ///Format of default formatter
022:            private static final String FORMAT = "%7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): %{message}\\n%{throwable}";
023:
024:            ///The instance of default hierarchy
025:            private static final Hierarchy c_hierarchy = new Hierarchy();
026:
027:            ///Error Handler associated with hierarchy
028:            private ErrorHandler m_errorHandler;
029:
030:            ///The root logger which contains all Loggers in this hierarchy
031:            private Logger m_rootLogger;
032:
033:            /**
034:             * Retrieve the default hierarchy.
035:             * <p/>
036:             * <p>In most cases the default LogHierarchy is the only
037:             * one used in an application. However when security is
038:             * a concern or multiple independent applications will
039:             * be running in same JVM it is advantageous to create
040:             * new Hierarchies rather than reuse default.</p>
041:             *
042:             * @return the default Hierarchy
043:             */
044:            public static Hierarchy getDefaultHierarchy() {
045:                return c_hierarchy;
046:            }
047:
048:            /**
049:             * Create a hierarchy object.
050:             * The default LogTarget writes to stdout.
051:             */
052:            public Hierarchy() {
053:                m_errorHandler = new DefaultErrorHandler();
054:                m_rootLogger = new Logger(new InnerErrorHandler(), "", null,
055:                        null);
056:
057:                //Setup default output target to print to console
058:                final PatternFormatter formatter = new PatternFormatter(FORMAT);
059:                final StreamTarget target = new StreamTarget(System.out,
060:                        formatter);
061:
062:                setDefaultLogTarget(target);
063:            }
064:
065:            /**
066:             * Set the default log target for hierarchy.
067:             * This is the target inherited by loggers if no other target is specified.
068:             *
069:             * @param target the default target
070:             */
071:            public void setDefaultLogTarget(final LogTarget target) {
072:                if (null == target) {
073:                    throw new IllegalArgumentException(
074:                            "Can not set DefaultLogTarget to null");
075:                }
076:
077:                final LogTarget[] targets = new LogTarget[] { target };
078:                getRootLogger().setLogTargets(targets);
079:            }
080:
081:            /**
082:             * Set the default log targets for this hierarchy.
083:             * These are the targets inherited by loggers if no other targets are specified
084:             *
085:             * @param targets the default targets
086:             */
087:            public void setDefaultLogTargets(final LogTarget[] targets) {
088:                if (null == targets || 0 == targets.length) {
089:                    throw new IllegalArgumentException(
090:                            "Can not set DefaultLogTargets to null");
091:                }
092:
093:                for (int i = 0; i < targets.length; i++) {
094:                    if (null == targets[i]) {
095:                        throw new IllegalArgumentException(
096:                                "Can not set DefaultLogTarget element to null");
097:                    }
098:                }
099:
100:                getRootLogger().setLogTargets(targets);
101:            }
102:
103:            /**
104:             * Set the default priority for hierarchy.
105:             * This is the priority inherited by loggers if no other priority is specified.
106:             *
107:             * @param priority the default priority
108:             */
109:            public void setDefaultPriority(final Priority priority) {
110:                if (null == priority) {
111:                    throw new IllegalArgumentException(
112:                            "Can not set default Hierarchy Priority to null");
113:                }
114:
115:                getRootLogger().setPriority(priority);
116:            }
117:
118:            /**
119:             * Set the ErrorHandler associated with hierarchy.
120:             *
121:             * @param errorHandler the ErrorHandler
122:             */
123:            public void setErrorHandler(final ErrorHandler errorHandler) {
124:                if (null == errorHandler) {
125:                    throw new IllegalArgumentException(
126:                            "Can not set default Hierarchy ErrorHandler to null");
127:                }
128:
129:                m_errorHandler = errorHandler;
130:            }
131:
132:            /**
133:             * Retrieve a logger for named category.
134:             *
135:             * @param category the context
136:             * @return the Logger
137:             */
138:            public Logger getLoggerFor(final String category) {
139:                return getRootLogger().getChildLogger(category);
140:            }
141:
142:            //    /**
143:            //     * Logs an error message to error handler.
144:            //     * Default Error Handler is stderr.
145:            //     *
146:            //     * @param message a message to log
147:            //     * @param throwable a Throwable to log
148:            //     * @deprecated Logging components should use ErrorHandler rather than Hierarchy.log()
149:            //     */
150:            //    public void log(final String message, final Throwable throwable) {
151:            //        m_errorHandler.error(message, throwable, null);
152:            //    }
153:            //
154:            //    /**
155:            //     * Logs an error message to error handler.
156:            //     * Default Error Handler is stderr.
157:            //     *
158:            //     * @param message a message to log
159:            //     * @deprecated Logging components should use ErrorHandler rather than Hierarchy.log()
160:            //     */
161:            //    public void log(final String message) {
162:            //        log(message, null);
163:            //    }
164:
165:            private class InnerErrorHandler implements  ErrorHandler {
166:                /**
167:                 * Log an unrecoverable error.
168:                 *
169:                 * @param message   the error message
170:                 * @param throwable the exception associated with error (may be null)
171:                 * @param event     the LogEvent that caused error, if any (may be null)
172:                 */
173:                public void error(final String message,
174:                        final Throwable throwable, final LogEvent event) {
175:                    m_errorHandler.error(message, throwable, event);
176:                }
177:            }
178:
179:            /**
180:             * Utility method to retrieve logger for hierarchy.
181:             * This method is intended for use by sub-classes
182:             * which can take responsibility for manipulating
183:             * Logger directly.
184:             *
185:             * @return the Logger
186:             */
187:            protected final Logger getRootLogger() {
188:                return m_rootLogger;
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.