Source Code Cross Referenced for LogWriter.java in  » Database-DBMS » Ozone-1.1 » org » infozone » tools » 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 » Database DBMS » Ozone 1.1 » org.infozone.tools.logger 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // You can redistribute this software and/or modify it under the terms of
002:        // the Infozone Software License version 2 published by the Infozone Group
003:        // (http://www.infozone-group.org).
004:        //
005:        // Copyright (C) @year@ by The Infozone Group. All rights reserved.
006:        //
007:        // $Id: LogWriter.java,v 1.1 2002/05/10 08:59:12 per_nyfelt Exp $
008:
009:        package org.infozone.tools.logger;
010:
011:        import java.io.*;
012:        import java.util.*;
013:
014:        /**
015:         @author <a href="http://www.softwarebuero.de/">SMB</a>
016:         @version $Revision: 1.1 $Date: 2002/05/10 08:59:12 $
017:         */
018:        public final class LogWriter {
019:
020:            public static final int INFO = 1;
021:            public static final int WARN = 2;
022:            public static final int ERROR = 4;
023:            public static final int DEBUG = 8;
024:            public static final int DEBUG2 = 16;
025:            public static final int DEBUG3 = 32;
026:
027:            protected static final String INFO_PREFIX = "[info] ";
028:            protected static final String WARN_PREFIX = "[warn] ";
029:            protected static final String ERROR_PREFIX = "[error]";
030:            protected static final String DEBUG_PREFIX = "[debug]";
031:
032:            public static final int LINE_WIDTH = 70;
033:
034:            protected Vector logTargets;
035:
036:            protected int allLevels;
037:
038:            public LogWriter() {
039:                logTargets = new Vector();
040:            }
041:
042:            /**
043:            This method allows to quickly find out if there is any log target that
044:            would receive entries of the specified level.
045:             */
046:            public boolean hasTarget(int level) {
047:                return (allLevels & level) > 0;
048:            }
049:
050:            public void addLogTarget(OutputStream _out, int _levels) {
051:                // set also lower debug levels when higher levels are requested
052:                _levels = ((_levels & DEBUG3) > 0) ? (_levels | DEBUG2)
053:                        : _levels;
054:                _levels = ((_levels & DEBUG2) > 0) ? (_levels | DEBUG)
055:                        : _levels;
056:
057:                addLogTarget(new PrintWriter(_out), _levels);
058:            }
059:
060:            public void addLogTarget(PrintWriter _writer, int _levels) {
061:                // set also lower debug levels when higher levels are requested
062:                _levels = ((_levels & DEBUG3) > 0) ? (_levels | DEBUG2)
063:                        : _levels;
064:                _levels = ((_levels & DEBUG2) > 0) ? (_levels | DEBUG)
065:                        : _levels;
066:
067:                logTargets.addElement(new LogTarget(_writer, _levels));
068:                allLevels = allLevels | _levels;
069:            }
070:
071:            public void newEntry(Object sender, String msg, int levels) {
072:                newEntry(sender, msg, null, levels);
073:            }
074:
075:            public void newEntry(Object sender, String msg, Throwable e,
076:                    int levels) {
077:                //check if at least one of the specified levels is supported by
078:                //any of the LogTargets
079:                if ((allLevels & levels) > 0) {
080:                    for (int i = 0; i < logTargets.size(); i++) {
081:                        LogTarget logTarget = (LogTarget) logTargets
082:                                .elementAt(i);
083:                        if ((logTarget.levels & levels & INFO) > 0)
084:                            printToWriter(logTarget.writer, sender, msg,
085:                                    INFO_PREFIX, e);
086:                        if ((logTarget.levels & levels & WARN) > 0)
087:                            printToWriter(logTarget.writer, sender, msg,
088:                                    WARN_PREFIX, e);
089:                        if ((logTarget.levels & levels & ERROR) > 0)
090:                            printToWriter(logTarget.writer, sender, msg,
091:                                    ERROR_PREFIX, e);
092:                        if ((logTarget.levels & levels & (DEBUG | DEBUG2 | DEBUG3)) > 0)
093:                            printToWriter(logTarget.writer, sender, msg,
094:                                    DEBUG_PREFIX, e);
095:                    }
096:                }
097:            }
098:
099:            protected void printToWriter(PrintWriter writer, Object sender,
100:                    String msg, String status, Throwable e) {
101:                StringBuffer sb = new StringBuffer(120);
102:                sb.append(status);
103:                sb.append('(');
104:                String threadNum = String.valueOf(Thread.currentThread()
105:                        .hashCode());
106:                sb.append(threadNum.substring(threadNum.length() - 3));
107:                sb.append(") ");
108:                sb.append(rawClassName(sender));
109:                sb.append(": ");
110:                sb.append(msg);
111:                writer.println(sb);
112:                writer.flush();
113:                if (e != null) {
114:                    // writer.print ("    exception: " + e.getMessage());
115:                    printFormatedException(writer, e, LINE_WIDTH, "    ");
116:                }
117:            }
118:
119:            public static String rawClassName(Object obj) {
120:                if (obj != null) {
121:                    String name = (obj instanceof  Class) ? ((Class) obj)
122:                            .getName() : obj.getClass().getName();
123:                    int index = name.lastIndexOf('.');
124:                    return name.substring(index + 1);
125:                } else
126:                    return "(null)";
127:            }
128:
129:            protected void printFormatedException(OutputStream out,
130:                    Throwable e, int lineWidth, String pre) {
131:                printFormatedException(new PrintWriter(out), e, lineWidth, pre);
132:            }
133:
134:            protected void printFormatedException(PrintWriter out, Throwable e,
135:                    int lineWidth, String pre) {
136:                StringWriter buff = new StringWriter();
137:                e.printStackTrace(new PrintWriter(buff));
138:                StringTokenizer st = new StringTokenizer(buff.toString(), "\n");
139:                while (st.hasMoreTokens()) {
140:                    String line = st.nextToken();
141:                    boolean firstSubLine = true;
142:                    // while (line.length() > lineWidth) {
143:                    do {
144:                        int subLineLength = Math.min(lineWidth, line.length());
145:                        String subLine = line.substring(0, subLineLength);
146:                        line = line.substring(subLineLength);
147:                        if (!firstSubLine)
148:                            out.print("        ");
149:                        out.print(pre);
150:                        out.println(subLine);
151:                        firstSubLine = false;
152:                    } while (line.length() > 0);
153:                }
154:                out.flush();
155:            }
156:
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.