Source Code Cross Referenced for MonologSink.java in  » J2EE » Enhydra-Application-Framework » org » enhydra » 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 » J2EE » Enhydra Application Framework » org.enhydra.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // ========================================================================
002:        // 
003:        // $Id: MonologSink.java,v 1.3 2007-10-19 10:05:39 sinisa Exp $
004:        // ========================================================================
005:
006:        package org.enhydra.logging;
007:
008:        import java.util.Enumeration;
009:        import java.util.Iterator;
010:        import java.util.Locale;
011:        import java.util.Properties;
012:        import java.util.ResourceBundle;
013:        import java.util.Set;
014:
015:        import javax.management.MBeanServer;
016:        import javax.management.MBeanServerFactory;
017:        import javax.management.ObjectName;
018:
019:        import org.mortbay.log.Frame;
020:        import org.mortbay.log.LogImpl;
021:        import org.mortbay.log.LogSink;
022:        import org.objectweb.util.monolog.Monolog;
023:        import org.objectweb.util.monolog.api.BasicLevel;
024:        import org.objectweb.util.monolog.api.Level;
025:        import org.objectweb.util.monolog.api.Logger;
026:        import org.objectweb.util.monolog.wrapper.common.Configurable;
027:
028:        import com.lutris.util.ConfigException;
029:
030:        public class MonologSink implements  LogSink {
031:            private String _options;
032:            private transient boolean _started;
033:            private org.objectweb.util.monolog.api.LoggerFactory lf;
034:            private Logger logger = null;
035:            //    private String path, jonas, fileName;
036:            private static ResourceBundle rb = null;
037:            public static String PROPERTY_FILE;
038:            static ObjectName objectName;
039:
040:            public MonologSink() throws ConfigException {
041:                this ("MonologSink");
042:            }
043:
044:            public MonologSink(String name) throws ConfigException {
045:
046:                try {
047:                    configure();
048:                } catch (ConfigException ex) {
049:                    throw new ConfigException(
050:                            "Cannot configure logger. Logger not initialized.");
051:                }
052:
053:            }
054:
055:            /** For use with a Monolog factory
056:             */
057:            public MonologSink(Logger logger) {
058:                this .logger = logger;
059:            }
060:
061:            /* ------------------------------------------------------------ */
062:            public void setOptions(String filename) {
063:                _options = filename;
064:            }
065:
066:            /* ------------------------------------------------------------ */
067:            public String getOptions() {
068:                return _options;
069:            }
070:
071:            /* ------------------------------------------------------------ */
072:            public void setLogImpl(LogImpl li) {
073:            }
074:
075:            /* ------------------------------------------------------------ */
076:            public void start() throws Exception {
077:                _started = true;
078:            }
079:
080:            /* ------------------------------------------------------------ */
081:            public void stop() {
082:                _started = false;
083:            }
084:
085:            /* ------------------------------------------------------------ */
086:            public boolean isStarted() {
087:                return _started;
088:            }
089:
090:            /* ------------------------------------------------------------ */
091:            public void log(String tag, Object msg, Frame frame, long time) {
092:                String method = frame.getMethod();
093:                int lb = method.indexOf('(');
094:                int ld = (lb > 0) ? method.lastIndexOf('.', lb) : method
095:                        .lastIndexOf('.');
096:                if (ld < 0)
097:                    ld = lb;
098:
099:                String class_name = (ld > 0) ? method.substring(0, ld) : method;
100:                // Finding a Monolog properties file or system property
101:
102:                Level priority = BasicLevel.LEVEL_INFO;
103:
104:                if (LogImpl.DEBUG.equals(tag))
105:                    priority = BasicLevel.LEVEL_DEBUG;
106:                else if (LogImpl.WARN.equals(tag) || LogImpl.ERROR.equals(tag))
107:                    priority = BasicLevel.LEVEL_ERROR;
108:                else if (LogImpl.FAIL.equals(tag))
109:                    priority = BasicLevel.LEVEL_FATAL;
110:
111:                if (!logger.isLoggable(priority))
112:                    return;
113:
114:                logger.log(priority, "org.enhydra.logging.MonologSink", ""
115:                        + msg, null);
116:            }
117:
118:            /* ------------------------------------------------------------ */
119:            public synchronized void log(String s) {
120:                logger.log(BasicLevel.LEVEL_INFO,
121:                        "org.enhydra.logging.MonologSink", s, null);
122:            }
123:
124:            public synchronized void configure() throws ConfigException {
125:                String b = null;
126:                String propkey;
127:                String propvalue;
128:                Properties props = new Properties();
129:
130:                try {
131:                    findMBeanServer();
132:                    findObjectName();
133:                    if (objectName != null)
134:                        PROPERTY_FILE = objectName.getKeyProperty("fname");
135:                    // Search the classpath for the logger configuration file        
136:                    rb = ResourceBundle.getBundle(PROPERTY_FILE, new Locale(
137:                            "en", "US"), ClassLoader.getSystemClassLoader());
138:
139:                    Enumeration enumeration = rb.getKeys();
140:
141:                    while (enumeration.hasMoreElements()) {
142:
143:                        propkey = (String) enumeration.nextElement();
144:                        propvalue = rb.getString(propkey);
145:                        props.setProperty(propkey, propvalue);
146:                    }
147:
148:                } catch (Exception e) {
149:                    throw new ConfigException(
150:                            "Logger configuration file could not be found:  logger could not be initialized!");
151:                }
152:
153:                try {
154:
155:                    // Search the class name of the LoggerFactory which must be instanciated
156:                    b = props.getProperty("log.config.classname", null);
157:                    if (b == null) {
158:                        throw new ConfigException(
159:                                "Malformed configuration log file:"
160:                                        + " log.config.classname not available");
161:                    }
162:
163:                    // Instanciate the LoggerFactory
164:
165:                    props.put(Configurable.LOG_CONFIGURATION_TYPE,
166:                            Configurable.PROPERTY);
167:                    lf = Monolog.getMonologFactory(b);
168:                    this .logger = lf.getLogger("MonologSink");
169:
170:                } catch (Exception e) {
171:                    throw new ConfigException(
172:                            "Malformed configuration log file:"
173:                                    + " log.config.classname not available");
174:                }
175:
176:            }
177:
178:            private MBeanServer findMBeanServer() throws Exception {
179:                MBeanServer mBeanServer;
180:                try {
181:                    java.util.ArrayList server = MBeanServerFactory
182:                            .findMBeanServer(null);
183:                    if (server == null) {
184:                        throw new Exception("MBeansServer not found");
185:                    } else {
186:                        mBeanServer = (MBeanServer) server.get(0);
187:                        //System.err.println("domain:" + mBeanServer.getDefaultDomain());
188:                    }
189:                } catch (Exception e) {
190:                    throw new com.lutris.appserver.server.session.SessionException(
191:                            e);
192:                }
193:                return mBeanServer;
194:            }
195:
196:            /**
197:             * finds the ObjectName which correspondes to the MBean of the jonas logger
198:             */
199:            private void findObjectName() throws Exception {
200:                try {
201:                    objectName = new ObjectName("jonas:type=service,name=log,*");
202:                    MBeanServer mBeanServer = findMBeanServer();
203:                    Set mBeans = mBeanServer.queryNames(objectName, null);
204:                    int l;
205:                    if ((l = mBeans.size()) > 1) {
206:                        throw new Exception("MBean set size not equal 1: " + l);
207:                    } else if (l == 0) {
208:                        objectName = null;
209:                        return;
210:                    }
211:                    Iterator i = mBeans.iterator();
212:                    objectName = (ObjectName) i.next();
213:                } catch (Exception e) {
214:                    throw new Exception(e);
215:                }
216:                return;
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.