Source Code Cross Referenced for Log4jLogChannel.java in  » J2EE » Enhydra-Application-Framework » com » lutris » 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 » J2EE » Enhydra Application Framework » com.lutris.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         * 
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         * 
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         * 
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         * 
019:         * Contributor(s):
020:         * 
021:         * $Id: Log4jLogChannel.java,v 1.3 2007-10-19 10:05:39 sinisa Exp $
022:         */
023:        package com.lutris.logging;
024:
025:        import java.text.SimpleDateFormat;
026:
027:        import org.apache.log4j.Level;
028:        import org.apache.log4j.Logger;
029:
030:        /**
031:         * Standard implementation of a channel associated with a logging
032:         * facility.  All messages for the facility are written using a channel.
033:         * Care is take to avoid synchronization when possible for performance
034:         * reasons.
035:         *
036:         * @author Vladimir Puskas
037:         * @author Predrag Djoic
038:         * @author Sinisa Milosevic
039:         * @see com.lutris.logging.LogChannel
040:         * @see com.lutris.logging.Log4jLogger
041:         */
042:        public class Log4jLogChannel implements  LogChannel {
043:
044:            /**
045:             * Our symbolic name.
046:             */
047:            String separatorLine = "";
048:
049:            //    private String facility;
050:
051:            private static final int INT_ERROR = -1;
052:
053:            /**
054:             * Format for the date.
055:             */
056:            private static final SimpleDateFormat dateFormatter = new SimpleDateFormat(
057:                    "yyyy.MM.dd HH:mm:ss");
058:
059:            /**
060:             * Logger object with which we are associated.
061:             */
062:            private org.apache.log4j.Logger logger;
063:
064:            /**
065:             * Construct a new log channel.
066:             *
067:             * @param chanFacility The facility that the channel is associate with.
068:             * @param loggerObj The logging object that this channel will be associated
069:             *  with.
070:             */
071:            protected Log4jLogChannel(String chanFacility,
072:                    org.apache.log4j.Logger loggerObj, String separator) {
073:                //        facility = chanFacility;
074:                logger = loggerObj;
075:                separatorLine = separator;
076:
077:            }
078:
079:            public int getLevel(String level) {
080:                if (logger != null) {
081:                    if (logger.getLevel() != null) {
082:                        return logger.getLevel().toInt();
083:                    }
084:                }
085:                return INT_ERROR;
086:            }
087:
088:            /**
089:             * Determine if logging is enabled for the specified level.
090:             */
091:            public boolean isEnabled(int level) {
092:                return true;
093:                //         return logger.isEnabledFor(intToLevel(level));
094:            }
095:
096:            /**
097:             * Determine if logging is enabled for the specified level.
098:             */
099:            public boolean isEnabled(String level) {
100:                return true;
101:                //      return logger.isEnabledFor(stringToLevel(level));
102:            }
103:
104:            /**
105:             * Write a string to the log file.
106:             */
107:            public void write(int level, String msg) {
108:                Level lev;
109:
110:                if (logger == null) {
111:                    logger = Logger.getLogger(LogAdapter.class.getName());
112:                }
113:                lev = intToLevel(level);
114:                if (lev == null) {
115:                    lev = Level.INFO;
116:                }
117:
118:                logger.log(lev, msg + separatorLine);
119:            }
120:
121:            /**
122:             * Write a string and exception to the log file.
123:             */
124:            public void write(int level, String msg, Throwable throwable) {
125:                Level lev;
126:
127:                if (logger == null) {
128:                    logger = Logger.getLogger(LogAdapter.class.getName());
129:                }
130:                lev = intToLevel(level);
131:                if (lev == null) {
132:                    lev = Level.INFO;
133:                }
134:                logger.log(lev, msg + separatorLine, throwable);
135:            }
136:
137:            /**
138:             * Write a string to the log file.
139:             */
140:            public void write(String level, String msg) {
141:                Level lev;
142:
143:                if (logger == null) {
144:                    logger = Logger.getLogger(LogAdapter.class.getName());
145:                }
146:                lev = stringToLevel(level);
147:                if (lev == null) {
148:                    lev = Level.INFO;
149:                }
150:                logger.log(lev, msg + separatorLine);
151:            }
152:
153:            /**
154:             * Write a string and exception to the log file.
155:             */
156:            public void write(String level, String msg, Throwable throwable) {
157:                Level lev;
158:
159:                if (logger == null) {
160:                    logger = Logger.getLogger(LogAdapter.class.getName());
161:                }
162:                lev = stringToLevel(level);
163:                if (lev == null) {
164:                    lev = Level.INFO;
165:                }
166:                logger.log(lev, msg + separatorLine, throwable);
167:            }
168:
169:            private Level intToLevel(int level) {
170:                Level lev;
171:
172:                switch (level) {
173:                case com.lutris.logging.Logger.EMERGENCY:
174:                case com.lutris.logging.Logger.ALERT:
175:                    lev = Level.FATAL;
176:                    break;
177:
178:                case com.lutris.logging.Logger.CRITICAL:
179:                case com.lutris.logging.Logger.ERROR:
180:                    lev = Level.ERROR;
181:                    break;
182:
183:                case com.lutris.logging.Logger.WARNING:
184:                    lev = Level.WARN;
185:                    break;
186:
187:                case com.lutris.logging.Logger.NOTICE:
188:                case com.lutris.logging.Logger.INFO:
189:                    lev = Level.INFO;
190:                    break;
191:
192:                case com.lutris.logging.Logger.DEBUG:
193:                case com.lutris.logging.Logger.DEBUG1:
194:                case com.lutris.logging.Logger.DEBUG2:
195:                case com.lutris.logging.Logger.DEBUG3:
196:                case com.lutris.logging.Logger.DEBUG4:
197:                case com.lutris.logging.Logger.DEBUG5:
198:                case com.lutris.logging.Logger.DEBUG6:
199:                case com.lutris.logging.Logger.DEBUG7:
200:                case com.lutris.logging.Logger.DEBUG8:
201:                case com.lutris.logging.Logger.DEBUG9:
202:                case com.lutris.logging.Logger.DEBUGTMP:
203:                    lev = Level.DEBUG;
204:                    break;
205:
206:                default:
207:                    lev = Level.DEBUG;
208:                } // end switch (level)
209:                return lev;
210:            }
211:
212:            private Level stringToLevel(String level) {
213:                Level lev;
214:
215:                if (level.equalsIgnoreCase("EMERGENCY")
216:                        || level.equalsIgnoreCase("ALERT")) {
217:                    lev = Level.FATAL;
218:                } else if (level.equalsIgnoreCase("CRITICAL")
219:                        || level.equalsIgnoreCase("ERROR")) {
220:                    lev = Level.ERROR;
221:                } else if (level.equalsIgnoreCase("WARNING")) {
222:                    lev = Level.WARN;
223:                } else if (level.equalsIgnoreCase("NOTICE")
224:                        || level.equalsIgnoreCase("INFO")) {
225:                    lev = Level.INFO;
226:                } else if (level.equalsIgnoreCase("DEBUG")
227:                        || level.equalsIgnoreCase("DEBUG1")
228:                        || level.equalsIgnoreCase("DEBUG2")
229:                        || level.equalsIgnoreCase("DEBUG3")
230:                        || level.equalsIgnoreCase("DEBUG4")
231:                        || level.equalsIgnoreCase("DEBUG5")
232:                        || level.equalsIgnoreCase("DEBUG6")
233:                        || level.equalsIgnoreCase("DEBUG7")
234:                        || level.equalsIgnoreCase("DEBUG8")
235:                        || level.equalsIgnoreCase("DEBUG9")
236:                        || level.equalsIgnoreCase("DEBUGTMP")) {
237:                    lev = Level.DEBUG;
238:                } else {// default
239:                    lev = Level.DEBUG;
240:                }
241:                return lev;
242:            }
243:
244:            /**
245:             * <b>NOT SUPPORTED</b>
246:             *
247:             * @param level Symbolic level that is to be checked.
248:             * @return A log writer object.
249:             */
250:            public LogWriter getLogWriter(String level) {
251:                //	throw new UnsupportedOperationException("Log4jLogChannel doesn't support this operation.");
252:                return new Log4jLogWriter(this , level);
253:
254:            }
255:
256:            /**
257:             * <b>NOT SUPPORTED</b>
258:             *
259:             * @param level Numeric level that is to be checked.
260:             * @return A log writer object.
261:             */
262:            public LogWriter getLogWriter(int level) {
263:                //	throw new UnsupportedOperationException("Log4jLogChannel doesn't support this operation.");
264:                return new Log4jLogWriter(this, level);
265:            }
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.