Source Code Cross Referenced for LoggerWrapperPrintWriter.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » util » 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 ORM » db ojb » org.apache.ojb.broker.util.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker.util.logging;
002:
003:        /* Copyright 2002-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import java.io.PrintWriter;
019:
020:        import org.apache.commons.lang.BooleanUtils;
021:
022:        /**
023:         * Extremely simple piggyback for OJB Logger interface to provide PrintWriter dito.
024:         *
025:         * @author <a href="mailto:mkalen@apache.org">Martin Kal&eacute;n</a>
026:         * @version CVS $Id: LoggerWrapperPrintWriter.java,v 1.1.2.3 2005/12/21 22:28:16 tomdz Exp $
027:         * @since OJB 1.0.4, 2005-apr-30
028:         */
029:        public class LoggerWrapperPrintWriter extends PrintWriter {
030:
031:            private static final String LINESEP = System
032:                    .getProperty("line.separator");
033:            private static final int DEFAULT_LEVEL = Logger.INFO;
034:
035:            private final Logger logger;
036:            private final int level;
037:            private final boolean filterEverything;
038:
039:            /**
040:             * Construct a new PrintWriter piggyback for the specified OJB logger.
041:             * @param logger the logger to which all PrintWriter events should be sent to
042:             * @param level the log level for PrintWriter events, can only be specified
043:             * as a single level since ther is no priority concept in PrintWriter API
044:             */
045:            public LoggerWrapperPrintWriter(Logger logger, int level) {
046:                super (System.out); // dummy, must initialize stream
047:                this .logger = logger;
048:                this .level = level;
049:                filterEverything = !logger.isEnabledFor(level);
050:            }
051:
052:            public LoggerWrapperPrintWriter(Logger logger) {
053:                this (logger, DEFAULT_LEVEL);
054:            }
055:
056:            private void log(String s) {
057:                switch (level) {
058:                case Logger.FATAL:
059:                    logger.fatal(s);
060:                    break;
061:
062:                case Logger.ERROR:
063:                    logger.error(s);
064:                    break;
065:
066:                case Logger.WARN:
067:                    logger.warn(s);
068:                    break;
069:
070:                case Logger.INFO:
071:                    logger.info(s);
072:                    break;
073:
074:                case Logger.DEBUG:
075:                    logger.debug(s);
076:                    break;
077:
078:                default:
079:                    throw new RuntimeException(
080:                            "Internal OJB fault. Logger API does not permit level "
081:                                    + level);
082:                }
083:            }
084:
085:            private void logLn(String s) {
086:                if (s != null) {
087:                    log(s);
088:                }
089:                log(LINESEP);
090:            }
091:
092:            public void println() {
093:                if (!filterEverything) {
094:                    logLn(null);
095:                }
096:            }
097:
098:            public void print(char c) {
099:                if (!filterEverything) {
100:                    log(new String(new char[] { c }));
101:                }
102:            }
103:
104:            public void println(char c) {
105:                if (!filterEverything) {
106:                    logLn(new String(new char[] { c }));
107:                }
108:            }
109:
110:            public void print(double v) {
111:                if (!filterEverything) {
112:                    log(Double.toString(v));
113:                }
114:            }
115:
116:            public void println(double v) {
117:                if (!filterEverything) {
118:                    logLn(Double.toString(v));
119:                }
120:            }
121:
122:            public void print(float v) {
123:                if (!filterEverything) {
124:                    log(Float.toString(v));
125:                }
126:            }
127:
128:            public void println(float v) {
129:                if (!filterEverything) {
130:                    logLn(Float.toString(v));
131:                }
132:            }
133:
134:            public void print(int i) {
135:                if (!filterEverything) {
136:                    log(Integer.toString(i));
137:                }
138:            }
139:
140:            public void println(int i) {
141:                if (!filterEverything) {
142:                    logLn(Integer.toString(i));
143:                }
144:            }
145:
146:            public void print(long l) {
147:                if (!filterEverything) {
148:                    log(Long.toString(l));
149:                }
150:            }
151:
152:            public void println(long l) {
153:                if (!filterEverything) {
154:                    logLn(Long.toString(l));
155:                }
156:            }
157:
158:            public void print(boolean b) {
159:                if (!filterEverything) {
160:                    log(BooleanUtils.toStringTrueFalse(b));
161:                }
162:            }
163:
164:            public void println(boolean b) {
165:                if (!filterEverything) {
166:                    logLn(BooleanUtils.toStringTrueFalse(b));
167:                }
168:            }
169:
170:            public void print(char[] chars) {
171:                if (!filterEverything) {
172:                    log(new String(chars));
173:                }
174:            }
175:
176:            public void println(char[] chars) {
177:                if (!filterEverything) {
178:                    logLn(new String(chars));
179:                }
180:            }
181:
182:            public void print(Object o) {
183:                if (!filterEverything && o != null) {
184:                    log(o.toString());
185:                }
186:            }
187:
188:            public void println(Object o) {
189:                if (!filterEverything && o != null) {
190:                    logLn(o.toString());
191:                }
192:            }
193:
194:            public void print(String s) {
195:                if (!filterEverything) {
196:                    log(s);
197:                }
198:            }
199:
200:            public void println(String s) {
201:                if (!filterEverything) {
202:                    logLn(s);
203:                }
204:            }
205:
206:            public void write(int i) {
207:                if (!filterEverything) {
208:                    print(i);
209:                }
210:            }
211:
212:            public void write(String s) {
213:                if (!filterEverything) {
214:                    print(s);
215:                }
216:            }
217:
218:            public void write(char[] chars) {
219:                if (!filterEverything) {
220:                    print(chars);
221:                }
222:            }
223:
224:            public void write(char[] chars, int i, int i1) {
225:                if (!filterEverything) {
226:                    log(new String(chars, i, i1));
227:                }
228:            }
229:
230:            public void write(String s, int i, int i1) {
231:                if (!filterEverything) {
232:                    log(s.substring(i, i1));
233:                }
234:            }
235:
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.