Source Code Cross Referenced for LogHandler.java in  » Code-Analyzer » javapathfinder » gov » nasa » jpf » 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 » Code Analyzer » javapathfinder » gov.nasa.jpf.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //
002:        //Copyright (C) 2005 United States Government as represented by the
003:        //Administrator of the National Aeronautics and Space Administration
004:        //(NASA).  All Rights Reserved.
005:        //
006:        //This software is distributed under the NASA Open Source Agreement
007:        //(NOSA), version 1.3.  The NOSA has been approved by the Open Source
008:        //Initiative.  See the file NOSA-1.3-JPF at the top of the distribution
009:        //directory tree for the complete NOSA document.
010:        //
011:        //THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012:        //KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013:        //LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014:        //SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015:        //A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016:        //THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017:        //DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018:        //
019:        package gov.nasa.jpf.util;
020:
021:        import gov.nasa.jpf.Config;
022:
023:        import java.io.File;
024:        import java.io.IOException;
025:        import java.io.PrintWriter;
026:        import java.io.OutputStream;
027:        import java.io.FileOutputStream;
028:        import java.net.ConnectException;
029:        import java.net.Socket;
030:        import java.net.UnknownHostException;
031:        import java.util.logging.Handler;
032:        import java.util.logging.LogRecord;
033:        import java.util.logging.Logger;
034:
035:        /**
036:         * log handler class that deals with output selection and formatting. This is the
037:         * only handler we use for our own logging
038:         */
039:        public class LogHandler extends Handler {
040:
041:            public static final String LOG_HOST = "localhost";
042:            public static final int LOG_PORT = 20000;
043:
044:            File file;
045:            Socket socket;
046:            OutputStream ostream;
047:
048:            PrintWriter out;
049:
050:            public LogHandler(Config conf) {
051:                String output = conf.getString("log.output", "out");
052:
053:                if (output.matches("[a-zA-Z0-9.]*:[0-9]*")) { // we assume that's a hostname:port spec
054:                    int idx = output.indexOf(':');
055:                    String host = output.substring(0, idx);
056:                    String port = output.substring(idx + 1, output.length());
057:                    ostream = connectSocket(host, port);
058:                } else if (output.equalsIgnoreCase("out")
059:                        || output.equals("System.out")) {
060:                    ostream = System.out;
061:                } else if (output.equalsIgnoreCase("err")
062:                        || output.equals("System.err")) {
063:                    ostream = System.err;
064:                } else {
065:                    ostream = openFile(output);
066:                }
067:
068:                if (ostream == null) {
069:                    ostream = System.out;
070:                }
071:
072:                out = new PrintWriter(ostream, true);
073:            }
074:
075:            OutputStream connectSocket(String host, String portSpec) {
076:                int port = -1;
077:
078:                if ((host == null) || (host.length() == 0)) {
079:                    host = LOG_HOST;
080:                }
081:
082:                if (portSpec != null) {
083:                    try {
084:                        port = Integer.parseInt(portSpec);
085:                    } catch (NumberFormatException x) {
086:                        // just catch it
087:                    }
088:                }
089:                if (port == -1) {
090:                    port = LOG_PORT;
091:                }
092:
093:                try {
094:                    socket = new Socket(host, port);
095:                    return socket.getOutputStream();
096:                } catch (UnknownHostException uhx) {
097:                    //System.err.println("unknown log host: " + host);
098:                } catch (ConnectException cex) {
099:                    //System.err.println("no log host detected);
100:                } catch (IOException iox) {
101:                    //System.err.println(iox);
102:                }
103:
104:                return null;
105:            }
106:
107:            OutputStream openFile(String fileName) {
108:                file = new File(fileName);
109:
110:                try {
111:                    if (file.exists()) {
112:                        file.delete();
113:                    }
114:                    file.createNewFile();
115:                    return new FileOutputStream(file);
116:                } catch (IOException iox) {
117:                    // just catch it
118:                }
119:
120:                return null;
121:            }
122:
123:            public void close() throws SecurityException {
124:                if ((ostream != System.err) && (ostream != System.out)) {
125:                    out.close();
126:                }
127:
128:                if (socket != null) {
129:                    try {
130:                        socket.close();
131:                    } catch (IOException iox) {
132:                        // not much we can do
133:                    }
134:                }
135:            }
136:
137:            public void flush() {
138:                out.flush();
139:            }
140:
141:            public void publish(LogRecord r) {
142:                out.println(r.getMessage());
143:            }
144:
145:            public void printStatus(Logger log) {
146:                if (socket != null) {
147:                    log.config("logging to socket: " + socket);
148:                } else if (file != null) {
149:                    log.config("logging to file: " + file.getAbsolutePath());
150:                } else if (ostream == System.err) {
151:                    log.config("logging to System.err");
152:                } else if (ostream == System.out) {
153:                    log.config("logging to System.out");
154:                } else {
155:                    log.warning("unknown log destination");
156:                }
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.