Source Code Cross Referenced for Logging.java in  » Mail-Clients » columba-1.4 » org » columba » core » logging » 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 » Mail Clients » columba 1.4 » org.columba.core.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014:        //
015:        //All Rights Reserved.
016:        package org.columba.core.logging;
017:
018:        import java.io.File;
019:        import java.io.IOException;
020:        import java.util.logging.ConsoleHandler;
021:        import java.util.logging.FileHandler;
022:        import java.util.logging.Handler;
023:        import java.util.logging.Level;
024:        import java.util.logging.Logger;
025:        import java.util.logging.SimpleFormatter;
026:
027:        import org.columba.ristretto.log.RistrettoLogger;
028:
029:        /**
030:         * Depending on the debug flag (--debug command line option reflected in
031:         * MainInterface.DEBUG) the logger will either show all debug messages or just
032:         * severe errors. Logging information is passed to a log file and to the
033:         * console.
034:         * <p>
035:         * Note, that Logging must not be called before MainInterface.DEBUG, was set.
036:         * Otherwise, the logger won't show the correct debug level.
037:         * <p>
038:         * If the user has defined their own logging config file, then this will take
039:         * precedence over Columba defined logging handlers, ie. Columba will not create
040:         * its own default logging handlers. All has already been defined in the system
041:         * property <b>java.util.logging.config.file</b>.
042:         * <p>
043:         * 
044:         * @see org.columba.core.main.Main
045:         * @see java.util.logging.Logger
046:         * @author redsolo
047:         */
048:        public final class Logging {
049:
050:            private static final Logger LOG = Logger.getLogger("org.columba");
051:
052:            private static ConsoleHandler consoleHandler;
053:
054:            /** If true, enables debugging output from org.columba.core.logging */
055:            public static boolean DEBUG = false;
056:
057:            /**
058:             * Don't instanciate this class.
059:             */
060:            private Logging() {
061:            }
062:
063:            /**
064:             * Returns true if the user has defined a logging config file. The user can
065:             * define a config file using the system property
066:             * <code>java.util.logging.config.file</code>.
067:             * 
068:             * @return true if the user has defined a logging config file; false
069:             *         otherwise.
070:             */
071:            private static boolean userHasDefinedLogging() {
072:                return (System.getProperty("java.util.logging.config.file") != null);
073:            }
074:
075:            /**
076:             * Creates the console handler. The console handler outputs only the
077:             * severest logging message unless the MainInterface.DEBUG flag is set.
078:             */
079:            public static void createDefaultHandler() {
080:
081:                if (!userHasDefinedLogging()) {
082:
083:                    // Since Columba is doing its own logging handlers, we should not
084:                    // use handlers in the parent logger.
085:                    LOG.setUseParentHandlers(false);
086:
087:                    // init console handler
088:                    consoleHandler = new ConsoleHandler();
089:
090:                    consoleHandler.setFormatter(new OneLineFormatter());
091:                    consoleHandler.setLevel(Level.SEVERE);
092:
093:                    LOG.addHandler(consoleHandler);
094:                }
095:            }
096:
097:            public static void setDebugging(boolean debug) {
098:                if (debug) {
099:                    consoleHandler.setFormatter(new DebugFormatter());
100:                    consoleHandler.setLevel(Level.ALL);
101:
102:                    LOG.setLevel(Level.ALL);
103:                    // System.setProperty("javax.net.debug",
104:                    // "ssl,handshake,data,trustmanager"); // init java.net.ssl
105:                    // debugging
106:
107:                    // TODO Ristretto should handle the logging of streams in another
108:                    // way.
109:                    RistrettoLogger.setLogStream(System.out);
110:                } else {
111:                    consoleHandler.setFormatter(new OneLineFormatter());
112:                    consoleHandler.setLevel(Level.SEVERE);
113:
114:                    LOG.setLevel(Level.SEVERE);
115:                }
116:            }
117:
118:            /**
119:             * Default logger configuration used by Columba.
120:             * <p>
121:             * If the user has not defined their own config file for the logging
122:             * framework, then this will create a log file named
123:             * <code>columba.log</code>, in the default config directory.
124:             */
125:            public static void createDefaultFileHandler(File configDirectory) {
126:
127:                if (!userHasDefinedLogging()) {
128:                    String logConfigFile = System
129:                            .getProperty("java.util.logging.config.file");
130:                    if (logConfigFile == null) {
131:
132:                        // create logging file in "<users config-folder>/log"
133:                        File file = new File(configDirectory, "log");
134:                        if (!file.exists())
135:                            file.mkdir();
136:
137:                        File loggingFile = new File(file, "columba.log");
138:
139:                        // Setup file logging
140:                        try {
141:                            Handler handler = new FileHandler(loggingFile
142:                                    .getPath(), false);
143:                            handler.setFormatter(new SimpleFormatter()); // don't use
144:                            // standard
145:                            // XML
146:                            // formatting
147:
148:                            if (Logging.DEBUG) {
149:                                handler.setLevel(Level.ALL);
150:                            } else {
151:                                handler.setLevel(Level.WARNING);
152:                            }
153:
154:                            LOG.addHandler(handler);
155:                        } catch (IOException ioe) {
156:                            LOG
157:                                    .severe("Could not start the file logging due to: "
158:                                            + ioe);
159:                        }
160:                    }
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.