Source Code Cross Referenced for FileLogger.java in  » Development » javaguard » net » sf » javaguard » 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 » Development » javaguard » net.sf.javaguard.log 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JavaGuard -- an obfuscation package for Java classfiles.
003:         *
004:         * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This library 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 GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * The author may be contacted at theit@gmx.de.
021:         *
022:         *
023:         * $Id: FileLogger.java,v 1.2 2002/04/23 11:18:39 glurk Exp $
024:         */package net.sf.javaguard.log;
025:
026:        import java.io.PrintWriter;
027:        import java.util.Vector;
028:
029:        /** Implements a simple writer that serves as an output mechanism for
030:         * script file output messages.
031:         *
032:         * @author <a href="mailto:theit@gmx.de">Thorsten Heit</a>
033:         */
034:        public class FileLogger implements  Log {
035:            /** Holds the logging level. */
036:            private int logFileLevel;
037:
038:            /** Holds the current instance of the logger. */
039:            private static FileLogger theInstance = null;
040:            /** Holds the print writer that will be used for printing the log messages.
041:             * The default setting is to discard all logging messages.
042:             */
043:            private static PrintWriter logFileWriter = null;
044:            /** A vector containing warning messages about methods. */
045:            private Vector methodWarnings;
046:            /** A vector containing general warning messages. */
047:            private Vector warnings;
048:
049:            /** Returns the current instance of the logger.
050:             * @return the current instance of the file logger
051:             */
052:            public static FileLogger getInstance() {
053:                if (null == theInstance) {
054:                    theInstance = new FileLogger();
055:                }
056:                return theInstance;
057:            }
058:
059:            /** Defines the new print writer that will be used when writing log messages.
060:             * @param pw the print writer
061:             */
062:            public static void setWriter(PrintWriter pw) {
063:                logFileWriter = pw;
064:            }
065:
066:            /** Private constructor that initializes the logger. */
067:            private FileLogger() {
068:                warnings = new Vector();
069:                methodWarnings = new Vector();
070:                setLoggingLevel(NORMAL);
071:            }
072:
073:            /** Flushes the logger and closes the output stream.
074:             */
075:            protected void finalize() {
076:                close();
077:            }
078:
079:            /** Closes the output streams.
080:             */
081:            public void close() {
082:                if (null != logFileWriter) {
083:                    logFileWriter.flush();
084:                    logFileWriter.close();
085:                }
086:            }
087:
088:            /** Sets the logging level. Future log messages must have a logging level
089:             * equal or higher to the one specified in the parameter.
090:             * @param level the new logging level; one of the constants
091:             * <code>NORMAL</code>, <code>INFO</code>, <code>VERBOSE</code> or <code>DEBUG</code>
092:             * @see #getLoggingLevel
093:             */
094:            public void setLoggingLevel(int level) {
095:                logFileLevel = level;
096:            }
097:
098:            /** Returns the current logging level.
099:             * @return the current logging level
100:             */
101:            public int getLoggingLevel() {
102:                return logFileLevel;
103:            }
104:
105:            /** Increment the current logging level to be more verbose.
106:             */
107:            public void incrementLoggingLevel() {
108:                setLoggingLevel(getLoggingLevel() + 1);
109:            }
110:
111:            /** Prints an empty line to the logger using the <code>NORMAL</code> logging
112:             * level.
113:             * @see #log
114:             */
115:            public void println() {
116:                println("");
117:            }
118:
119:            /** Prints the given string to the logger using the <code>NORMAL</code>
120:             * logging level and terminates the current line.
121:             * @param msg the message to log
122:             */
123:            public void println(String msg) {
124:                log(msg);
125:            }
126:
127:            /** Prints the given string to the logger using the <code>NORMAL</code>
128:             * logging level and terminates the current line.
129:             * @param msg the message to log
130:             */
131:            public void log(String msg) {
132:                log(NORMAL, msg);
133:            }
134:
135:            /** Prints the given string to the logger using the <code>NORMAL</code>
136:             * logging level.
137:             * @param msg the message to log
138:             */
139:            public void print(String msg) {
140:                log(NORMAL, msg, false);
141:            }
142:
143:            /** Prints a logging message and terminates the line if the specified logging
144:             * level is lower or equal than the current logging level.
145:             * @param level the logging level
146:             * @param msg the log message
147:             */
148:            public void log(int level, String msg) {
149:                log(level, msg, true);
150:            }
151:
152:            /** Prints a logging message if the specified logging level is lower or equal
153:             * than the current logging level. Depending on the <code>lineFeed</code>
154:             * parameter the output line is terminated.
155:             * @param level the logging level
156:             * @param msg the log message
157:             * @param lineFeed true if the output line is terminated; false else
158:             */
159:            public void log(int level, String msg, boolean lineFeed) {
160:                if (getLoggingLevel() >= level) {
161:                    if (null != logFileWriter) {
162:                        if (lineFeed) {
163:                            logFileWriter.println(msg);
164:                        } else {
165:                            logFileWriter.print(msg);
166:                        }
167:                    }
168:                }
169:            }
170:
171:            /** Logs the stack trace of the given exception.
172:             * @param ex the exception whose stack trace should be logged
173:             */
174:            public void printStackTrace(Exception ex) {
175:                ex.printStackTrace(logFileWriter);
176:            }
177:
178:            /** Append a warning message to the current list of warnings.
179:             * @param msg the warning message
180:             * @see #printMethodWarnings
181:             */
182:            public void addMethodWarning(String msg) {
183:                methodWarnings.addElement(msg);
184:            }
185:
186:            /** Print the warning messages to the log file.
187:             * @see #addMethodWarning
188:             */
189:            public void printMethodWarnings() {
190:                for (int i = 0; i < methodWarnings.size(); i++) {
191:                    println((String) methodWarnings.elementAt(i));
192:                }
193:            }
194:
195:            /** Append a general warning message to the current list of warnings.
196:             * @param msg the warning message
197:             * @see #printWarnings
198:             */
199:            public void addWarning(String msg) {
200:                warnings.addElement(msg);
201:            }
202:
203:            /** Print the warning messages to the log file.
204:             * @see #addWarning
205:             */
206:            public void printWarnings() {
207:                for (int i = 0; i < warnings.size(); i++) {
208:                    println((String) warnings.elementAt(i));
209:                }
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.