Source Code Cross Referenced for ApplLogger.java in  » Workflow-Engines » wfmopen-2.1.1 » de » danet » an » util » log4j » 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 » Workflow Engines » wfmopen 2.1.1 » de.danet.an.util.log4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the WfMOpen project.
003:         * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004:         * All rights reserved.
005:         *
006:         * This program is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU General Public License as published by
008:         * the Free Software Foundation; either version 2 of the License, or
009:         * (at your option) 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:         * $Id: ApplLogger.java,v 1.2 2006/09/29 12:32:13 drmlipp Exp $
021:         *
022:         * $Log: ApplLogger.java,v $
023:         * Revision 1.2  2006/09/29 12:32:13  drmlipp
024:         * Consistently using WfMOpen as projct name now.
025:         *
026:         * Revision 1.1.1.4  2004/08/18 15:17:35  drmlipp
027:         * Update to 1.2
028:         *
029:         * Revision 1.10  2004/06/22 11:52:04  lipp
030:         * Some fixes to match new commons-logging.
031:         *
032:         * Revision 1.9  2003/09/05 09:40:26  lipp
033:         * Fixed paths for IBM JVM.
034:         *
035:         * Revision 1.8  2003/06/27 08:51:46  lipp
036:         * Fixed copyright/license information.
037:         *
038:         * Revision 1.7  2002/11/28 22:52:08  lipp
039:         * Added search in /etc and result output.
040:         *
041:         * Revision 1.6  2002/10/11 14:59:38  lipp
042:         * Better initialization.
043:         *
044:         * Revision 1.5  2002/09/04 06:57:37  lipp
045:         * Now using JBoss-3.0
046:         *
047:         * Revision 1.4  2002/01/22 08:48:14  lipp
048:         * Javadoc fixes.
049:         *
050:         * Revision 1.3  2002/01/08 16:57:05  lipp
051:         * Removed debug message.
052:         *
053:         * Revision 1.2  2002/01/05 19:35:03  lipp
054:         * Final log solution.
055:         *
056:         * Revision 1.1  2002/01/04 13:01:24  lipp
057:         * Loading application specific log4j classes (1. try).
058:         *
059:         */
060:
061:        package de.danet.an.util.log4j;
062:
063:        import java.io.InputStream;
064:
065:        import java.net.URL;
066:
067:        import org.apache.log4j.Hierarchy;
068:        import org.apache.log4j.Level;
069:        import org.apache.log4j.Logger;
070:        import org.apache.log4j.spi.RootCategory;
071:        import org.apache.log4j.xml.DOMConfigurator;
072:
073:        /**
074:         * This class provides an alternate access to the log4j logging
075:         * library. The necessity arises from the usage of log4j as logging
076:         * package in the JBoss application server. As log4j is already
077:         * included in JBoss' classpath and configured by JBoss, we cannot
078:         * have really independent application level logging.<P>
079:         *
080:         * The central problem is the static default hierarchy used by
081:         * <code>org.apache.log4j.Logger</code>. For a distinct application
082:         * level logging we need an alternate hierarchy. Of course, we want to
083:         * access this hierarchy as simple as
084:         * <code>Logger.getInstance(...)</code> and thus we need a new class
085:         * that provides the static acces to the alternate (application
086:         * level) hierarchy.<P>
087:         *
088:         * Note that no static methods of other log4j classes may be used in
089:         * the context of this application level logging, as they usually rely
090:         * on <code>Logger.getDefaultHierarchy()</code> and that is not the
091:         * application level hierarchy.<P>
092:         */
093:        public class ApplLogger {
094:
095:            /**
096:             * The hierarchy used in <code>ApplLogger</code>.
097:             */
098:            public static final RootCategory rc = new RootCategory(Level.DEBUG);
099:            public static final Hierarchy defaultHierarchy = new Hierarchy(rc);
100:
101:            private static URL cu = null;
102:            static {
103:                try {
104:                    // First try /etc
105:                    cu = Thread.currentThread().getContextClassLoader()
106:                            .getResource("/etc/log4j-appl.xml");
107:                    if (cu == null) {
108:                        // above doesn't work under unknown circumstances ...
109:                        cu = ApplLogger.class
110:                                .getResource("/etc/log4j-appl.xml");
111:                    }
112:                    if (cu == null) {
113:                        // above doesn't work under unknown circumstances ...
114:                        cu = ClassLoader
115:                                .getSystemResource("/etc/log4j-appl.xml");
116:                    }
117:
118:                    // Now try /
119:                    if (cu == null) {
120:                        cu = Thread.currentThread().getContextClassLoader()
121:                                .getResource("log4j-appl.xml");
122:                    }
123:                    if (cu == null) {
124:                        // above doesn't work under unknown circumstances ...
125:                        cu = ApplLogger.class.getResource("log4j-appl.xml");
126:                    }
127:                    if (cu == null) {
128:                        // above doesn't work under unknown circumstances ...
129:                        cu = ClassLoader.getSystemResource("log4j-appl.xml");
130:                    }
131:                    if (cu == null) {
132:                        System.err
133:                                .println("FATAL: No \"log4j-appl.xml\" in classpath!");
134:                    }
135:                    InputStream cf = cu.openStream();
136:                    new DOMConfigurator().doConfigure(cf, defaultHierarchy);
137:                } catch (Exception ex) {
138:                    System.err.println("FATAL: Problem initializing logging:"
139:                            + ex.getMessage());
140:                    ex.printStackTrace();
141:                }
142:            }
143:            private static final org.apache.log4j.Logger logger = de.danet.an.util.log4j.ApplLogger
144:                    .getLogger(ApplLogger.class);
145:            static {
146:                logger.info("Application logger hierarchy initialized from "
147:                        + cu);
148:            }
149:
150:            /**
151:             * Return the default Hierarchy instance.
152:             * @return the default hierarchy instance.
153:             */
154:            public static Hierarchy getDefaultHierarchy() {
155:                return defaultHierarchy;
156:            }
157:
158:            /**
159:             * Retrieve a category with named as the <code>name</code>
160:             * parameter. If the named category already exists, then the existing
161:             * instance will be reutrned. Otherwise, a new instance is created.
162:             *
163:             * By default, categories do not have a set priority but inherit it
164:             * from the hierarchy. This is one of the central features of log4j.
165:             *
166:             * @param name The name of the category to retrieve.  
167:             * @return the logger
168:             */
169:            public static Logger getLogger(String name) {
170:                return defaultHierarchy.getLogger(name);
171:            }
172:
173:            /**
174:             * Shorthand for <code>getInstance(clazz.getName())</code>.
175:             * 
176:             * @param clazz The name of <code>clazz</code> will be used as the
177:             * name of the category to retrieve.  See {@link
178:             * #getLogger(String)} for more detailed information.
179:             * @return the logger
180:             */
181:            public static Logger getLogger(Class clazz) {
182:                return getLogger(clazz.getName());
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.