Source Code Cross Referenced for Log4jNotificationLoggerAgent.java in  » ESB » mule » org » mule » agent » 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 » ESB » mule » org.mule.agent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: Log4jNotificationLoggerAgent.java 11129 2008-02-29 15:13:29Z acooke $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:
011:        package org.mule.agent;
012:
013:        import org.mule.api.context.notification.ServerNotification;
014:        import org.mule.api.lifecycle.InitialisationException;
015:        import org.mule.config.i18n.CoreMessages;
016:        import org.mule.util.FileUtils;
017:        import org.mule.util.MapUtils;
018:        import org.mule.util.StringUtils;
019:
020:        import java.io.File;
021:        import java.io.IOException;
022:        import java.util.HashMap;
023:        import java.util.Map;
024:
025:        import org.apache.log4j.Appender;
026:        import org.apache.log4j.Level;
027:        import org.apache.log4j.Logger;
028:        import org.apache.log4j.PatternLayout;
029:        import org.apache.log4j.PropertyConfigurator;
030:        import org.apache.log4j.RollingFileAppender;
031:        import org.apache.log4j.xml.DOMConfigurator;
032:
033:        /**
034:         * <code>AbstractNotificationLoggerAgent</code> Receives Mule server notifications
035:         * and logs them and can optionally route them to an endpoint
036:         *
037:         */
038:        public class Log4jNotificationLoggerAgent extends
039:                AbstractNotificationLoggerAgent {
040:
041:            protected static final int DEFAULT_DESCRIPTION_BUFFER_SIZE = 64;
042:
043:            protected Logger eventLogger;
044:            private String logName = Log4jNotificationLoggerAgent.class
045:                    .getName();
046:            private String logFile = null;
047:            private String logConfigFile = null;
048:            private String chainsawHost = "localhost";
049:            private int chainsawPort = -1;
050:            private Map levelMappings = new HashMap();
051:
052:            public Log4jNotificationLoggerAgent() {
053:                super ("log4j-notifications");
054:            }
055:
056:            /**
057:             * Should be a 1 line description of the agent
058:             *
059:             * @return the description of this Agent
060:             */
061:            public String getDescription() {
062:                StringBuffer buf = new StringBuffer(
063:                        DEFAULT_DESCRIPTION_BUFFER_SIZE);
064:                if (StringUtils.isNotBlank(logFile)) {
065:                    buf.append("Logging notifications to: ").append(logFile);
066:                }
067:                if (chainsawPort > -1) {
068:                    buf.append(" Chainsaw: ").append(chainsawHost).append(":")
069:                            .append(chainsawPort);
070:                }
071:                if (buf.length() == 0) {
072:                    buf.append("No logging or event forwarding is configured");
073:                }
074:                return getName() + ": " + buf.toString();
075:            }
076:
077:            public String getLogName() {
078:                return logName;
079:            }
080:
081:            public void setLogName(String logName) {
082:                this .logName = logName;
083:            }
084:
085:            protected void doInitialise() throws InitialisationException {
086:                if (logConfigFile != null) {
087:                    if (logConfigFile.endsWith(".xml")) {
088:                        DOMConfigurator.configure(logConfigFile);
089:                    } else {
090:                        PropertyConfigurator.configure(logConfigFile);
091:                    }
092:                } else {
093:                    try {
094:                        eventLogger = Logger.getLogger(logName);
095:                        if (logFile != null) {
096:                            File f = FileUtils.newFile(logFile);
097:                            if (!f.exists()) {
098:                                FileUtils.createFile(logFile);
099:                            }
100:                            Appender file = new RollingFileAppender(
101:                                    new PatternLayout("%5p %m%n"), logFile,
102:                                    true);
103:                            eventLogger.addAppender(file);
104:                        }
105:                        /* Disable for now since the org.apache.log4j.net package is not
106:                            exported by the PAX Logging Log4J bundle.
107:                        if (chainsawPort > -1)
108:                        {
109:                            Appender chainsaw = new SocketAppender(chainsawHost, chainsawPort);
110:                            eventLogger.addAppender(chainsaw);
111:                        } */
112:                    } catch (IOException e) {
113:                        throw new InitialisationException(CoreMessages
114:                                .failedToLoad("Log4j configuration"), e, this );
115:                    }
116:                }
117:            }
118:
119:            protected void logEvent(ServerNotification e) {
120:                if (eventLogger != null) {
121:                    String actionKey = e.EVENT_NAME + "." + e.getActionName();
122:                    String level = MapUtils.getString(levelMappings, actionKey,
123:                            e.getType());
124:
125:                    eventLogger.log(Level.toLevel(level, Level.INFO), e);
126:                }
127:            }
128:
129:            public String getLogFile() {
130:                return logFile;
131:            }
132:
133:            public void setLogFile(String logFile) {
134:                this .logFile = logFile;
135:            }
136:
137:            public String getLogConfigFile() {
138:                return logConfigFile;
139:            }
140:
141:            public void setLogConfigFile(String logConfigFile) {
142:                this .logConfigFile = logConfigFile;
143:            }
144:
145:            public String getChainsawHost() {
146:                return chainsawHost;
147:            }
148:
149:            public void setChainsawHost(String chainsawHost) {
150:                this .chainsawHost = chainsawHost;
151:            }
152:
153:            public int getChainsawPort() {
154:                return chainsawPort;
155:            }
156:
157:            public void setChainsawPort(int chainsawPort) {
158:                this .chainsawPort = chainsawPort;
159:            }
160:
161:            public Map getLevelMappings() {
162:                return levelMappings;
163:            }
164:
165:            public void setLevelMappings(Map levelMappings) {
166:                this.levelMappings.putAll(levelMappings);
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.