Source Code Cross Referenced for FileLog.java in  » Source-Control » jcvsweb » com » ice » util » 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 » Source Control » jcvsweb » com.ice.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         ** Copyright (c) 1997 by Timothy Gerard Endres
003:         ** 
004:         ** This program is free software.
005:         ** 
006:         ** You may redistribute it and/or modify it under the terms of the GNU
007:         ** General Public License as published by the Free Software Foundation.
008:         ** Version 2 of the license should be included with this distribution in
009:         ** the file LICENSE, as well as License.html. If the license is not
010:         ** included	with this distribution, you may find a copy at the FSF web
011:         ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
012:         ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
013:         **
014:         ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
015:         ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
016:         ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
017:         ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
018:         ** REDISTRIBUTION OF THIS SOFTWARE. 
019:         ** 
020:         */
021:
022:        package com.ice.util;
023:
024:        import java.io.*;
025:        import java.lang.*;
026:        import java.util.*;
027:
028:        public class FileLog extends Object {
029:            private static final String RCS_ID = "$Id: FileLog.java,v 1.3 1998/12/26 20:59:06 time Exp $";
030:            private static final String RCS_REV = "$Revision: 1.3 $";
031:            private static final String RCS_NAME = "$Name:  $";
032:
033:            private static final String DEFAULT_FILENAME = "log.txt";
034:
035:            private static FileLog defaultLogger = null;
036:
037:            private String filename;
038:            private FileWriter file;
039:            private PrintWriter stream;
040:            private boolean open;
041:            private boolean echo;
042:            private boolean autoFlush;
043:
044:            static public FileLog getDefaultLogger() {
045:                return FileLog.defaultLogger;
046:            }
047:
048:            static public FileLog setDefaultLogger(FileLog logger) {
049:                FileLog old = FileLog.defaultLogger;
050:                FileLog.defaultLogger = logger;
051:                return old;
052:            }
053:
054:            static public void checkDefaultLogger() {
055:                if (FileLog.defaultLogger == null) {
056:                    FileLog.defaultLogger = new FileLog(
057:                            FileLog.DEFAULT_FILENAME);
058:                }
059:            }
060:
061:            public FileLog(String filename) {
062:                this .open = false;
063:                this .echo = false;
064:                this .autoFlush = true;
065:                this .filename = filename;
066:                this .file = null;
067:                this .stream = null;
068:            }
069:
070:            public void setLogFilename(String filename) {
071:                this .filename = filename;
072:            }
073:
074:            public void setAutoFlush(boolean autoflush) {
075:                this .autoFlush = autoFlush;
076:            }
077:
078:            public void checkLogOpen() {
079:                if (!this .open) {
080:                    this .openLogFile();
081:                }
082:            }
083:
084:            public void openLogFile() {
085:                boolean isok = true;
086:
087:                try {
088:                    this .file = new FileWriter(this .filename);
089:                } catch (Exception ex) {
090:                    System.err.println("error opening log file '"
091:                            + this .filename + "' - " + ex.getMessage());
092:                    this .file = null;
093:                    isok = false;
094:                }
095:
096:                if (isok) {
097:                    this .stream = new PrintWriter(this .file);
098:                    this .open = true;
099:                }
100:
101:                this .echo = false;
102:            }
103:
104:            public void closeLog() {
105:                if (this .open) {
106:                    this .open = false;
107:                    if (this .stream != null) {
108:                        this .stream.flush();
109:                        this .stream.close();
110:                        this .stream = null;
111:                    }
112:                }
113:            }
114:
115:            public void setEcho(boolean setting) {
116:                this .echo = setting;
117:            }
118:
119:            public void traceMsg(Throwable thrown, String msg) {
120:                this .logMsg(msg);
121:                this .logMsg(thrown.getMessage());
122:
123:                if (!this .open)
124:                    thrown.printStackTrace(System.err);
125:                else
126:                    thrown.printStackTrace(this .stream);
127:
128:                if (this .autoFlush && this .open)
129:                    this .stream.flush();
130:            }
131:
132:            static public void defLogMsg(String msg) {
133:                FileLog.checkDefaultLogger();
134:                if (FileLog.defaultLogger != null)
135:                    FileLog.defaultLogger.logMsg(msg);
136:            }
137:
138:            public void logMsg(String msg) {
139:                this .checkLogOpen();
140:
141:                if (this .open) {
142:                    this .stream.println(msg);
143:                    if (this .autoFlush && this .open)
144:                        this .stream.flush();
145:                }
146:
147:                if (this .echo) {
148:                    System.out.println(msg);
149:                }
150:            }
151:
152:            static public void defLogMsgStdout(String msg) {
153:                FileLog.checkDefaultLogger();
154:                if (FileLog.defaultLogger != null)
155:                    FileLog.defaultLogger.logMsgStdout(msg);
156:            }
157:
158:            public void logMsgStdout(String msg) {
159:                this .checkLogOpen();
160:
161:                if (this .open) {
162:                    this .stream.println(msg);
163:                    if (this .autoFlush && this .open)
164:                        this .stream.flush();
165:                }
166:
167:                System.out.println(msg);
168:            }
169:
170:            static public void defLogMsgStderr(String msg) {
171:                FileLog.checkDefaultLogger();
172:                if (FileLog.defaultLogger != null)
173:                    FileLog.defaultLogger.logMsgStderr(msg);
174:            }
175:
176:            public void logMsgStderr(String msg) {
177:                this.checkLogOpen();
178:
179:                if (this.open) {
180:                    this.stream.println(msg);
181:                    if (this.autoFlush && this.open)
182:                        this.stream.flush();
183:                }
184:
185:                System.err.println(msg);
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.