Source Code Cross Referenced for Log4jLogger.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » logging » 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 JDBC Connection Pool » octopus » org.webdocwf.util.loader.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:            Copyright (C) 2002-2003  Together
003:            This library is free software; you can redistribute it and/or
004:            modify it under the terms of the GNU Lesser General Public
005:            License as published by the Free Software Foundation; either
006:            version 2.1 of the License, or (at your option) any later version.
007:            This library is distributed in the hope that it will be useful,
008:            but WITHOUT ANY WARRANTY; without even the implied warranty of
009:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
010:            Lesser General Public License for more details.
011:            You should have received a copy of the GNU Lesser General Public
012:            License along with this library; if not, write to the Free Software
013:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111--1307  USA
014:         */package org.webdocwf.util.loader.logging;
015:
016:        import java.util.*;
017:        import java.io.*;
018:        import org.webdocwf.util.loader.BufferOctopusClass;
019:
020:        import java.util.Hashtable;
021:        import java.io.*;
022:        import org.apache.log4j.BasicConfigurator;
023:        import org.apache.log4j.ConsoleAppender;
024:        import org.apache.log4j.Level;
025:        import org.apache.log4j.Logger;
026:        import org.apache.log4j.PatternLayout;
027:        import org.apache.log4j.RollingFileAppender;
028:        import org.apache.log4j.spi.LoggerRepository;
029:        import org.apache.log4j.xml.DOMConfigurator;
030:
031:        public class Log4jLogger extends
032:                org.webdocwf.util.loader.logging.Logger {
033:
034:            /**
035:             * Log file name.
036:             */
037:            File activeLogFile;
038:
039:            /**
040:             * Log file writter.
041:             */
042:            PrintWriter logFileStream;
043:
044:            private boolean[] enabledLogLevels = new boolean[3];
045:            private Hashtable messages = new Hashtable();
046:            private String logMode;
047:            private org.apache.log4j.Logger logger;
048:
049:            /**
050:             * Construct a new logger.  Configuration is not done now, to allow
051:             * the logger to be created very early.
052:             */
053:            public Log4jLogger() {
054:                centralLogger = this ;
055:            }
056:
057:            /**
058:             * Configure Logger with given config file, interpreting of config file is
059:             * logger implementation specific.
060:             *
061:             * @param log4jConfFile is Path to configuration file.
062:             * @throws Exception
063:             */
064:            public void configure(String log4jConfFile) throws Exception {
065:
066:                try {
067:                    DOMConfigurator.configure(log4jConfFile);
068:                    this .logger = Logger.getLogger("OctopusLogger");
069:                } catch (javax.xml.parsers.FactoryConfigurationError fce) {
070:                    throw new Exception(
071:                            "Cannot configure Log4jLogger! FactoryConfigurationError occured!");
072:
073:                }
074:            }
075:
076:            public int getLevel(String level) {
077:                if (level
078:                        .equalsIgnoreCase(org.webdocwf.util.loader.logging.Logger.strLOGMODE_NONE))
079:                    return 0;
080:                else if (level
081:                        .equalsIgnoreCase(org.webdocwf.util.loader.logging.Logger.strLOGMODE_NORMAL))
082:                    return 1;
083:                else
084:                    return 2;
085:            }
086:
087:            public boolean isEnabled(int level) {
088:                return true;
089:            }
090:
091:            public boolean isEnabled(String level) {
092:                //    return isEnabled(this.getLevel(level));
093:                return true;
094:            }
095:
096:            public void write(int level, String msg) {
097:                Level lev;
098:                if (this .logger == null) {
099:                    this .logger = Logger.getLogger("OctopusLogger");
100:                }
101:                if (level == 1)
102:                    lev = Level.INFO;
103:                else if (level == 2)
104:                    lev = Level.DEBUG;
105:                else
106:                    lev = Level.INFO;
107:
108:                logger.log(lev, msg);
109:            }
110:
111:            public synchronized void write(String level, String msg) {
112:                write(getLevel(level), msg);
113:            }
114:
115:            public synchronized void write(int level, String msg,
116:                    Throwable throwable) {
117:                Date date = new Date();
118:                StringWriter stackBuf = new StringWriter();
119:                throwable.printStackTrace(new PrintWriter(stackBuf));
120:                stackBuf.flush();
121:
122:                String errMsg = msg + ":" + " " + throwable.getMessage() + '\n'
123:                        + stackBuf;
124:                this .write(level, errMsg);
125:
126:            }
127:
128:            public synchronized void write(String level, String msg,
129:                    Throwable throwable) {
130:                write(getLevel(level), msg, throwable);
131:            }
132:
133:            public void setEnabledLogLevels(String logMode) {
134:            }
135:
136:            public boolean[] getEnabledLogLevels() {
137:                return enabledLogLevels;
138:            }
139:
140:            public String getMessage(String key) {
141:                if (key != null) {
142:                    return (String) this .messages.get(key);
143:                } else
144:                    return null;
145:            }
146:
147:            public boolean setMessage(String key, String value) {
148:                if (value != null && key != null) {
149:                    this .messages.put(key, value);
150:                    return true;
151:                } else
152:                    return false;
153:            }
154:
155:            public boolean writeEcho(String strLogTxt) {
156:                if (!this .logMode
157:                        .equalsIgnoreCase(org.webdocwf.util.loader.logging.Logger.strLOGMODE_NONE)) {
158:                    this 
159:                            .write(
160:                                    org.webdocwf.util.loader.logging.Logger.strLOGMODE_NORMAL,
161:                                    strLogTxt);
162:                    BufferOctopusClass.getInstance().writeToBuffer(strLogTxt);
163:                    return true;
164:                } else
165:                    return false;
166:            }
167:
168:            public void close() {
169:                //
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.