Source Code Cross Referenced for FileLogger.java in  » Web-Mail » jwebmail-0.7 » net » wastl » webmail » logger » 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 » Web Mail » jwebmail 0.7 » net.wastl.webmail.logger 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* CVS ID: $Id: FileLogger.java,v 1.1.1.1 2002/10/02 18:42:48 wastl Exp $ */
002:        package net.wastl.webmail.logger;
003:
004:        import java.io.*;
005:        import java.util.*;
006:        import java.text.*;
007:        import net.wastl.webmail.server.*;
008:        import net.wastl.webmail.misc.*;
009:        import net.wastl.webmail.config.*;
010:
011:        /**
012:         * Logger.java
013:         *
014:         * Created: Sun Sep 19 18:58:28 1999
015:         *
016:         * Copyright (C) 1999-2000 Sebastian Schaffert
017:         * 
018:         * This program is free software; you can redistribute it and/or
019:         * modify it under the terms of the GNU General Public License
020:         * as published by the Free Software Foundation; either version 2
021:         * of the License, or (at your option) any later version.
022:         * 
023:         * This program is distributed in the hope that it will be useful,
024:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
025:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
026:         * GNU General Public License for more details.
027:         * 
028:         * You should have received a copy of the GNU General Public License
029:         * along with this program; if not, write to the Free Software
030:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
031:         */
032:        /**
033:         * This is an asynchronous Logger thread that accepts log messages to a Queue and writes 
034:         * them to the logfile from time to time (all 5 seconds).
035:         *
036:         * @author Sebastian Schaffert
037:         * @version
038:         */
039:        public class FileLogger extends Thread implements 
040:                ConfigurationListener, Logger {
041:
042:            private DateFormat df = null;
043:
044:            protected PrintWriter logout;
045:            protected int loglevel;
046:
047:            protected Queue queue;
048:            protected Queue time_queue;
049:
050:            protected boolean do_shutdown = false;
051:
052:            protected WebMailServer parent;
053:            protected Storage store;
054:
055:            protected int interval;
056:
057:            public FileLogger(WebMailServer parent, Storage st) {
058:                super ("FileLogger Thread");
059:                this .parent = parent;
060:                this .store = st;
061:                parent.getConfigScheme().configRegisterIntegerKey(this ,
062:                        "LOGLEVEL", "5",
063:                        "How much debug output will be written in the logfile");
064:                parent.getConfigScheme().configRegisterStringKey(
065:                        this ,
066:                        "LOGFILE",
067:                        parent.getProperty("webmail.data.path")
068:                                + System.getProperty("file.separator")
069:                                + "webmail.log", "WebMail logfile");
070:                parent
071:                        .getConfigScheme()
072:                        .configRegisterIntegerKey(
073:                                this ,
074:                                "LOG INTERVAL",
075:                                "5",
076:                                "Interval used for flushing the log buffer"
077:                                        + " in seconds. Log messages of level CRIT or"
078:                                        + " ERR will be written immediately in any way.");
079:                initLog();
080:                queue = new Queue();
081:                time_queue = new Queue();
082:                this .start();
083:            }
084:
085:            protected void initLog() {
086:                System.err.print("  * Logfile ... ");
087:                try {
088:                    loglevel = Integer.parseInt(store.getConfig("LOGLEVEL"));
089:                } catch (NumberFormatException e) {
090:                }
091:                try {
092:                    interval = Integer
093:                            .parseInt(store.getConfig("LOG INTERVAL"));
094:                } catch (NumberFormatException e) {
095:                }
096:                try {
097:                    String filename = store.getConfig("LOGFILE");
098:                    logout = new PrintWriter(new FileOutputStream(filename,
099:                            true));
100:                    System.err.println("initalization complete: " + filename
101:                            + ", Level " + loglevel);
102:                } catch (IOException ex) {
103:                    ex.printStackTrace();
104:                    logout = new PrintWriter(System.out);
105:                    System.err
106:                            .println("initalization complete: Sending to STDOUT, Level "
107:                                    + loglevel);
108:                }
109:            }
110:
111:            protected String formatDate(long date) {
112:                if (df == null) {
113:                    TimeZone tz = TimeZone.getDefault();
114:                    df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
115:                            DateFormat.DEFAULT, Locale.getDefault());
116:                    df.setTimeZone(tz);
117:                }
118:                String now = df.format(new Date(date));
119:                return now;
120:            }
121:
122:            protected void writeMessage(long time, String message) {
123:                logout.println("[" + formatDate(time) + "] - " + message);
124:            }
125:
126:            public void log(int level, String message) {
127:                if (level <= loglevel) {
128:                    String s = "LEVEL " + level;
129:                    switch (level) {
130:                    case Storage.LOG_DEBUG:
131:                        s = "DEBUG   ";
132:                        break;
133:                    case Storage.LOG_INFO:
134:                        s = "INFO    ";
135:                        break;
136:                    case Storage.LOG_WARN:
137:                        s = "WARNING ";
138:                        break;
139:                    case Storage.LOG_ERR:
140:                        s = "ERROR   ";
141:                        break;
142:                    case Storage.LOG_CRIT:
143:                        s = "CRITICAL";
144:                        break;
145:                    }
146:                    queue(System.currentTimeMillis(), s + " - " + message);
147:                    if (level <= Storage.LOG_ERR) {
148:                        flush();
149:                    }
150:                }
151:            }
152:
153:            public void log(int level, Exception ex) {
154:                if (level <= loglevel) {
155:                    String s = "LEVEL " + level;
156:                    switch (level) {
157:                    case Storage.LOG_DEBUG:
158:                        s = "DEBUG   ";
159:                        break;
160:                    case Storage.LOG_INFO:
161:                        s = "INFO    ";
162:                        break;
163:                    case Storage.LOG_WARN:
164:                        s = "WARNING ";
165:                        break;
166:                    case Storage.LOG_ERR:
167:                        s = "ERROR   ";
168:                        break;
169:                    case Storage.LOG_CRIT:
170:                        s = "CRITICAL";
171:                        break;
172:                    }
173:                    StringWriter message = new StringWriter();
174:                    ex.printStackTrace(new PrintWriter(message));
175:                    queue(System.currentTimeMillis(), s + " - "
176:                            + message.toString());
177:                    if (level <= Storage.LOG_ERR) {
178:                        flush();
179:                    }
180:                }
181:            }
182:
183:            protected void flush() {
184:                while (!queue.isEmpty()) {
185:                    Long l = (Long) time_queue.next();
186:                    String s = (String) queue.next();
187:                    writeMessage(l.longValue(), s);
188:                }
189:                logout.flush();
190:            }
191:
192:            public void queue(long time, String message) {
193:                queue.queue(message);
194:                time_queue.queue(new Long(time));
195:            }
196:
197:            public void notifyConfigurationChange(String key) {
198:                initLog();
199:            }
200:
201:            public void shutdown() {
202:                flush();
203:                do_shutdown = true;
204:            }
205:
206:            public void run() {
207:                while (!do_shutdown) {
208:                    flush();
209:                    try {
210:                        sleep(interval * 1000);
211:                    } catch (InterruptedException e) {
212:                    }
213:                }
214:            }
215:        } // FileLogger
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.