Source Code Cross Referenced for ScreenLogger.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: ScreenLogger.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:
028:        /** Represents a simple Logger that prints logging messages to the screen or
029:         * a given print writer.
030:         *
031:         * @author <a href="mailto:theit@gmx.de">Thorsten Heit</a>
032:         */
033:        public class ScreenLogger implements  Log {
034:            /** Holds the logging level. */
035:            private int logLevel;
036:
037:            /** Holds the current instance of the logger. */
038:            private static ScreenLogger theInstance = null;
039:            /** A string containing whitespace characters. Used when printing messages. */
040:            private static String whitespaces = "                    ";
041:
042:            /** Returns the current instance of the logger.
043:             * @return current instance of the screen logger
044:             */
045:            public static ScreenLogger getInstance() {
046:                if (null == theInstance) {
047:                    theInstance = new ScreenLogger();
048:                }
049:                return theInstance;
050:            }
051:
052:            /** Private constructor that initializes the logger. */
053:            private ScreenLogger() {
054:                setLoggingLevel(NORMAL);
055:            }
056:
057:            /** Sets the logging level. Future log messages must have a logging level
058:             * equal or higher to the one specified in the parameter.
059:             * @param level the new logging level; one of the constants
060:             * <code>NORMAL</code>, <code>INFO</code>, <code>VERBOSE</code> or <code>DEBUG</code>
061:             * @see #getLoggingLevel
062:             */
063:            public void setLoggingLevel(int level) {
064:                logLevel = level;
065:            }
066:
067:            /** Returns the current logging level.
068:             * @return the current logging level
069:             */
070:            public int getLoggingLevel() {
071:                return logLevel;
072:            }
073:
074:            /** Increment the current logging level to be more verbose.
075:             */
076:            public void incrementLoggingLevel() {
077:                setLoggingLevel(getLoggingLevel() + 1);
078:            }
079:
080:            /** Prints an empty line to the logger using the <code>NORMAL</code> logging
081:             * level.
082:             * @see #log
083:             */
084:            public void println() {
085:                println("");
086:            }
087:
088:            /** Prints the given string to the logger using the <code>NORMAL</code>
089:             * logging level and terminates the current line.
090:             * @param msg the message to log
091:             */
092:            public void println(String msg) {
093:                log(msg);
094:            }
095:
096:            /** Prints the given string to the logger using the <code>NORMAL</code>
097:             * logging level.
098:             * @param msg the message to log
099:             */
100:            public void print(String msg) {
101:                log(NORMAL, msg, false);
102:            }
103:
104:            /** Prints the given string to the logger using the <code>NORMAL</code>
105:             * logging level and terminates the current line.
106:             * @param msg the message to log
107:             */
108:            public void log(String msg) {
109:                log(NORMAL, msg);
110:            }
111:
112:            /** Prints a logging message and terminates the line if the specified logging
113:             * level is lower or equal than the current logging level.
114:             * @param level the logging level
115:             * @param msg the log message
116:             */
117:            public void log(int level, String msg) {
118:                log(level, msg, true);
119:            }
120:
121:            /** Prints a logging message and terminates the line if the specified logging
122:             * level is lower or equal than the current logging level.
123:             * @param level the logging level
124:             * @param msg the log message
125:             * @param lineFeed true if the output line is terminated; false else
126:             */
127:            public void log(int level, String msg, boolean lineFeed) {
128:                if (getLoggingLevel() >= level) {
129:                    if (level > 0) {
130:                        if (level > whitespaces.length()) {
131:                            level = whitespaces.length();
132:                        }
133:                        System.out.print(whitespaces.substring(0, level));
134:                    }
135:                    if (lineFeed) {
136:                        System.out.println(msg);
137:                    } else {
138:                        System.out.print(msg);
139:                    }
140:                }
141:            }
142:
143:            /** Logs the stack trace of the given exception.
144:             * @param ex the exception whose stack trace should be logged
145:             */
146:            public void printStackTrace(Exception ex) {
147:                /* only available in JDK 1.4:
148:                StackTraceElement[] ste = ex.getStackTrace();
149:                for (int i=0; i<ste.length; i++) {
150:                  println(ste[i].toString());
151:                }
152:                 */
153:                ex.printStackTrace();
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.