InitialContextFactory option takes a string value.
+ * Its value, along with the ProviderUrl option will be used
+ * to get the InitialContext.
+ */
+ public void setInitialContextFactory(String initialContextFactory) {
+ this.initialContextFactory = initialContextFactory;
+ }
+
+ /**
+ * Returns the value of the InitialContextFactory option.
+ */
+ public String getInitialContextFactory() {
+ return initialContextFactory;
+ }
+
+ /**
+ * The ProviderUrl option takes a string value.
+ * Its value, along with the InitialContextFactory option will be used
+ * to get the InitialContext.
+ */
+ public void setProviderUrl(String providerUrl) {
+ this.providerUrl = providerUrl;
+ }
+
+ /**
+ * Returns the value of the ProviderUrl option.
+ */
+ public String getProviderUrl() {
+ return providerUrl;
+ }
+
+ /**
+ * The QueueConnectionFactoryBindingName option takes a
+ * string value. Its value will be used to lookup the appropriate
+ * QueueConnectionFactory from the JNDI context.
+ */
+ public void setQueueConnectionFactoryBindingName(String queueConnectionFactoryBindingName) {
+ this.queueConnectionFactoryBindingName = queueConnectionFactoryBindingName;
+ }
+
+ /**
+ * Returns the value of the QueueConnectionFactoryBindingName option.
+ */
+ public String getQueueConnectionFactoryBindingName() {
+ return queueConnectionFactoryBindingName;
+ }
+
+ /**
+ * The QueueBindingName option takes a
+ * string value. Its value will be used to lookup the appropriate
+ * destination Queue from the JNDI context.
+ */
+ public void setQueueBindingName(String queueBindingName) {
+ this.queueBindingName = queueBindingName;
+ }
+
+ /**
+ Returns the value of the QueueBindingName option.
+ */
+ public String getQueueBindingName() {
+ return queueBindingName;
+ }
+
+
+ /**
+ * Overriding this method to activate the options for this class
+ * i.e. Looking up the Connection factory ...
+ */
+ public void activateOptions() {
+
+ QueueConnectionFactory queueConnectionFactory;
+
+ try {
+
+ Context ctx = getInitialContext();
+ queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(queueConnectionFactoryBindingName);
+ queueConnection = queueConnectionFactory.createQueueConnection();
+
+ queueSession = queueConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+
+ Queue queue = (Queue) ctx.lookup(queueBindingName);
+ queueSender = queueSession.createSender(queue);
+
+ queueConnection.start();
+
+ ctx.close();
+
+ } catch(Exception e) {
+ errorHandler.error("Error while activating options for appender named ["+name+
+ "].", e, ErrorCode.GENERIC_FAILURE);
+ }
+ }
+
+ protected InitialContext getInitialContext() throws NamingException {
+ try {
+ Hashtable ht = new Hashtable();
+
+ //Populate property hashtable with data to retrieve the context.
+ ht.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
+ ht.put(Context.PROVIDER_URL, providerUrl);
+
+ return (new InitialContext(ht));
+
+ } catch (NamingException ne) {
+ LogLog.error("Could not get initial context with ["+initialContextFactory + "] and [" + providerUrl + "].");
+ throw ne;
+ }
+ }
+
+
+ protected boolean checkEntryConditions() {
+
+ String fail = null;
+
+ if(this.queueConnection == null) {
+ fail = "No QueueConnection";
+ } else if(this.queueSession == null) {
+ fail = "No QueueSession";
+ } else if(this.queueSender == null) {
+ fail = "No QueueSender";
+ }
+
+ if(fail != null) {
+ errorHandler.error(fail +" for JMSQueueAppender named ["+name+"].");
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Close this JMSQueueAppender. Closing releases all resources used by the
+ * appender. A closed appender cannot be re-opened.
+ */
+ public synchronized // avoid concurrent append and close operations
+ void close() {
+
+ if(this.closed)
+ return;
+
+ LogLog.debug("Closing appender ["+name+"].");
+ this.closed = true;
+
+ try {
+ if(queueSession != null)
+ queueSession.close();
+ if(queueConnection != null)
+ queueConnection.close();
+ } catch(Exception e) {
+ LogLog.error("Error while closing JMSQueueAppender ["+name+"].", e);
+ }
+
+ // Help garbage collection
+ queueSender = null;
+ queueSession = null;
+ queueConnection = null;
+ }
+
+ /**
+ * This method called by {@link AppenderSkeleton#doAppend} method to
+ * do most of the real appending work. The LoggingEvent will be
+ * be wrapped in an ObjectMessage to be put on the JMS queue.
+ */
+ public void append(LoggingEvent event) {
+
+ if(!checkEntryConditions()) {
+ return;
+ }
+
+ try {
+
+ ObjectMessage msg = queueSession.createObjectMessage();
+ msg.setObject(event);
+ queueSender.send(msg);
+
+ } catch(Exception e) {
+ errorHandler.error("Could not send message in JMSQueueAppender ["+name+"].", e,
+ ErrorCode.GENERIC_FAILURE);
+ }
+ }
+
+ public boolean requiresLayout() {
+ return false;
+ }
+}
\ No newline at end of file
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/JMSQueueAppender.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/Log4jRequestHandler.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/Log4jRequestHandler.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/Log4jRequestHandler.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/Log4jRequestHandler.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.net;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import org.apache.log4j.*;
+
+/**
+ * This class implements a RequestHandler for log4j configuration. It serves the "/log4j/" path
+ * in the PluggableHTTPServer. If this path is requested a list of all current log4j categories
+ * with their current priorities is created. All priority settings can be changed by the user
+ * and can be submitted and taken over.
+ *
+ * @author Volker Mentzner
+ */
+public class Log4jRequestHandler extends RootRequestHandler {
+
+ private Priority[] prios = Priority.getAllPossiblePriorities();
+
+ /**
+ * Creates a new Log4jRequestHandler object
+ */
+ public Log4jRequestHandler() {
+ this.setTitle("log4j");
+ this.setDescription("log4j configuration");
+ this.setHandledPath("/log4j/");
+ }
+
+ /**
+ * Handles the given request and writes the reply to the given out-stream.
+ *
+ * @param request - client browser request
+ * @param out - Out stream for sending data to client browser
+ * @return if the request was handled by this handler : true, else : false
+ */
+ public boolean handleRequest(String request, Writer out) {
+ String path = "";
+ String query = null;
+ String name;
+ try {
+ // check request url
+ URL url = new URL("http://localhost"+request);
+ path = url.getPath();
+ query = url.getQuery();
+ if (path.startsWith(this.getHandledPath()) == false) {
+ return false;
+ }
+
+ out.write("HTTP/1.0 200 OK\r\n");
+ out.write("Content-type: text/html\r\n\r\n");
+ out.write("" + this.getTitle() + "\r\n");
+ out.write("log4j
\r\n");
+ out.write(this.getDescription() + "
\r\n");
+
+ // handle a request with query
+ if ((query != null) && (query.length() >= 0)) {
+ StringTokenizer st = new StringTokenizer(query, "&");
+ String cmd;
+ String catname;
+ String catval;
+ int idx;
+ while (st.hasMoreTokens()) {
+ cmd = st.nextToken();
+ idx = cmd.indexOf("=");
+ catname = cmd.substring(0, idx);
+ catval = cmd.substring(idx+1, cmd.length());
+ if (catname.equalsIgnoreCase("root"))
+ Category.getRoot().setPriority(Priority.toPriority(catval));
+ else
+ Category.getInstance(catname).setPriority(Priority.toPriority(catval));
+ }
+ }
+
+ // output category information in a form with a simple table
+ out.write("");
+ out.write("\r\n");
+ out.flush();
+ return true;
+ } catch (Exception ex) {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/Log4jRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/LogType.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/LogType.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/LogType.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/LogType.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,42 @@
+package org.apache.log4j.net;
+
+/**
+This class contains all constants which are necessary to define a columns log-type.
+*/
+public class LogType
+{
+ //A column of this type will receive the message.
+ public static final int MSG = 1;
+
+ //A column of this type will be a unique identifier of the logged row.
+ public static final int ID = 2;
+
+ //A column of this type will contain a static, one-time-defined value.
+ public static final int STATIC = 3;
+
+ //A column of this type will be filled with an actual timestamp depending by the time the logging will be done.
+ public static final int TIMESTAMP = 4;
+
+ //A column of this type will contain no value and will not be included in logging insert-statement.
+ //This could be a column which will be filled not by creation but otherwhere...
+ public static final int EMPTY = 5;
+
+
+ public static boolean isLogType(int _lt)
+ {
+ if(_lt == MSG || _lt == STATIC || _lt == ID || _lt == TIMESTAMP || _lt == EMPTY) return true;
+
+ return false;
+ }
+
+ public static int parseLogType(String _lt)
+ {
+ if(_lt.equals("MSG")) return MSG;
+ if(_lt.equals("ID")) return ID;
+ if(_lt.equals("STATIC")) return STATIC;
+ if(_lt.equals("TIMESTAMP")) return TIMESTAMP;
+ if(_lt.equals("EMPTY")) return EMPTY;
+
+ return -1;
+ }
+}
\ No newline at end of file
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/LogType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/RootRequestHandler.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/RootRequestHandler.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/RootRequestHandler.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/RootRequestHandler.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.net;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+/**
+ * This class implements a RequestHandler for the root path "/" in the PluggableHTTPServer.
+ * A simple HTML message will be replied to the client.
+ *
+ * @author Volker Mentzner
+ */
+public class RootRequestHandler implements HTTPRequestHandler {
+
+ private String title;
+ private String description;
+ private String handledPath;
+ private String ReplyType = "Content-type: text/html\r\n\r\n";
+ private String ReplyHTML = "Root\r\n"
+ + "Root
\r\n"
+ + "\r\n";
+
+ /**
+ * Creates a new RootRequestHandler object
+ */
+ public RootRequestHandler() {
+ this.setTitle("root page");
+ this.setDescription("root page");
+ this.setHandledPath("/");
+ }
+
+ /**
+ * Gets the content type of the reply HTTP message
+ *
+ * @return content type as String
+ */
+ public String getReplyType() {
+ return this.ReplyType;
+ }
+
+ /**
+ * Sets the content type of the reply HTTP message
+ *
+ * @param ReplyType - content type as String
+ */
+ public void setReplyType(String ReplyType) {
+ this.ReplyType = ReplyType;
+ }
+
+ /**
+ * Gets the HTML data of the reply HTTP message
+ *
+ * @return HTML message as String
+ */
+ public String getReplyHTML() {
+ return this.ReplyHTML;
+ }
+
+ /**
+ * Sets the HTML data of the reply HTTP message
+ *
+ * @param ReplyHTML - HTML message as String
+ */
+ public void setReplyHTML(String ReplyHTML) {
+ this.ReplyHTML = ReplyHTML;
+ }
+
+ /**
+ * Gets the title for html page
+ */
+ public String getTitle() {
+ return this.title;
+ }
+
+ /**
+ * Sets the title for html page
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Gets the description for html page
+ */
+ public String getDescription() {
+ return this.description;
+ }
+
+ /**
+ * Sets the description for html page
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Gets the server path
+ *
+ * @return the server path
+ */
+ public String getHandledPath() {
+ return this.handledPath;
+ }
+
+ /**
+ * Sets the server path
+ *
+ * @param path - the server path
+ */
+ public void setHandledPath(String path) {
+ this.handledPath = path;
+ }
+
+ /**
+ * Handles the given request and writes the reply to the given out-stream.
+ *
+ * @param request - client browser request
+ * @param out - Out stream for sending data to client browser
+ * @return if the request was handled by this handler : true, else : false
+ */
+ public boolean handleRequest(String request, Writer out) {
+ String path = "";
+ String query = null;
+ try {
+ URL url = new URL("http://localhost"+request);
+ path = url.getPath();
+ query = url.getPath();
+ if (path.equals(handledPath) == false) {
+ return false;
+ }
+
+ out.write("HTTP/1.0 200 OK\r\n");
+ if (ReplyType != null)
+ out.write(ReplyType);
+ if (ReplyHTML != null)
+ out.write(ReplyHTML);
+ out.flush();
+ return true;
+ } catch (Exception ex) {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/main/java/org/apache/log4j/net/RootRequestHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderLog4JTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderLog4JTest.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderLog4JTest.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderLog4JTest.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,53 @@
+package org.apache.log4j.contribs.ThomasFenner;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Here is a code example to configure the JDBCAppender with a configuration-file
+
+import org.apache.log4j.*;
+
+import java.sql.*;
+
+public class JDBCAppenderLog4JTest
+{
+ // Create a category instance for this class
+ static Category cat = Category.getInstance(JDBCAppenderLog4JTest.class.getName());
+
+ public static void main(String[] args)
+ {
+ // Ensure to have all necessary drivers installed !
+ try
+ {
+ Driver d = (Driver)(Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
+ DriverManager.registerDriver(d);
+ }
+ catch(Exception e){}
+
+ // Set the priority which messages have to be logged
+ cat.setPriority(Priority.INFO);
+
+ // Configuration with configuration-file
+ PropertyConfigurator.configure("log4jtestprops.txt");
+
+ // These messages with Priority >= setted priority will be logged to the database.
+ cat.debug("debug"); //this not, because Priority DEBUG is less than INFO
+ cat.info("info");
+ cat.error("error");
+ cat.fatal("fatal");
+ }
+}
+
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderLog4JTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderNoConfigFileLog4JTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderNoConfigFileLog4JTest.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderNoConfigFileLog4JTest.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderNoConfigFileLog4JTest.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,134 @@
+package org.apache.log4j.contribs.ThomasFenner;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Here is a code example to configure the JDBCAppender without a configuration-file
+
+import org.apache.log4j.*;
+import org.apache.log4j.net.JDBCAppender;
+import org.apache.log4j.net.JDBCConnectionHandler;
+import org.apache.log4j.net.JDBCIDHandler;
+import org.apache.log4j.net.LogType;
+
+import java.sql.*;
+import java.util.*;
+
+public class JDBCAppenderNoConfigFileLog4JTest
+{
+ // Create a category instance for this class
+ static Category cat = Category.getInstance(JDBCAppenderNoConfigFileLog4JTest.class.getName());
+
+ public static void main(String[] args)
+ {
+ // A JDBCIDHandler
+ MyIDHandler idhandler = new MyIDHandler();
+
+ // Ensure to have all necessary drivers installed !
+ try
+ {
+ Driver d = (Driver)(Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
+ DriverManager.registerDriver(d);
+ }
+ catch(Exception e){}
+
+ // Set the priority which messages have to be logged
+ cat.setPriority(Priority.DEBUG);
+
+ // Create a new instance of JDBCAppender
+ JDBCAppender ja = new JDBCAppender();
+
+ // Set options with method setOption()
+ ja.setOption(JDBCAppender.CONNECTOR_OPTION, "MyConnectionHandler");
+ ja.setOption(JDBCAppender.URL_OPTION, "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1521))(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1526)))(CONNECT_DATA=(SID=LENZI)))");
+ ja.setOption(JDBCAppender.USERNAME_OPTION, "mex_pr_dev60");
+ ja.setOption(JDBCAppender.PASSWORD_OPTION, "mex_pr_dev60");
+
+ ja.setOption(JDBCAppender.TABLE_OPTION, "logtest");
+
+ // There are two ways to setup the column-descriptions :
+ // 1. Use the the method setOption(JDBCAppender.COLUMNS_OPTION, column-description)
+ //ja.setOption(JDBCAppender.COLUMNS_OPTION, "id_seq~EMPTY id~ID~MyIDHandler msg~MSG created_on~TIMESTAMP created_by~STATIC~:-) Thomas Fenner (t.fenner@klopotek.de)");
+
+ // 2. Use the better way of coding with method setLogType(String columnname, int LogType.xxx, Object xxx)
+ ja.setLogType("id_seq", LogType.EMPTY, "");
+ ja.setLogType("id", LogType.ID, idhandler);
+ ja.setLogType("msg", LogType.MSG, "");
+ ja.setLogType("created_on", LogType.TIMESTAMP, "");
+ ja.setLogType("created_by", LogType.STATIC, "FEN");
+
+ // If you just want to perform a static sql-statement, forget about the table- and columns-options,
+ // and use this one :
+ //ja.setOption(JDBCAppender.SQL_OPTION, "INSERT INTO LOGTEST (id, msg, created_on, created_by) VALUES (1, @MSG@, sysdate, 'me')");
+
+ // other options
+ //ja.setOption(JDBCAppender.BUFFER_OPTION, "1");
+ //ja.setOption(JDBCAppender.COMMIT_OPTION, "Y");
+
+ // Define a layout
+ //ja.setLayout(new PatternLayout("%m"));
+
+ // Add the appender to a category
+ cat.addAppender(ja);
+
+ // These messages with Priority >= setted priority will be logged to the database.
+ cat.debug("debug");
+ cat.info("info");
+ cat.error("error");
+ cat.fatal("fatal");
+ }
+}
+
+// Implement a sample JDBCConnectionHandler
+class MyConnectionHandler implements JDBCConnectionHandler
+{
+ Connection con = null;
+ //Default connection
+ String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1521))(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1526)))(CONNECT_DATA=(SID=LENZI)))";
+ String username = "mex_pr_dev60";
+ String password = "mex_pr_dev60";
+
+ public Connection getConnection()
+ {
+ return getConnection(url, username, password);
+ }
+
+ public Connection getConnection(String _url, String _username, String _password)
+ {
+ try
+ {
+ if(con != null && !con.isClosed()) con.close();
+ con = DriverManager.getConnection(_url, _username, _password);
+ con.setAutoCommit(false);
+ }
+ catch(Exception e){}
+
+ return con;
+ }
+}
+
+
+// Implement a sample JDBCIDHandler
+class MyIDHandler implements JDBCIDHandler
+{
+ private static long id = 0;
+
+ public synchronized Object getID()
+ {
+ return new Long(++id);
+ }
+}
+
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderNoConfigFileLog4JTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderWithConfigFileLog4JTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderWithConfigFileLog4JTest.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderWithConfigFileLog4JTest.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderWithConfigFileLog4JTest.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,274 @@
+package org.apache.log4j.contribs.ThomasFenner;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+// Class JDBCAppender, writes messages into a database
+
+// The JDBCAppender is configurable at runtime in two alternatives :
+// 1. Configuration-file
+// Define the options in a file and call a PropertyConfigurator.configure(file)-method.
+// 2. method JDBCAppender::setOption(JDBCAppender.xxx_OPTION, String value)
+
+// The sequence of some options is important :
+// 1. Connector-option OR/AND Database-options
+// Any database connection is required !
+// 2. (Table-option AND Columns-option) OR SQL-option
+// Any statement is required !
+// 3. All other options can be set at any time...
+// The other options are optional and have a default initialization, which can be custumized.
+
+// All available options are defined as static String-constants in JDBCAppender named xxx_OPTION.
+
+// Here is a description of all available options :
+// 1. Database-options to connect to the database
+// - URL_OPTION : a database url of the form jdbc:subprotocol:subname
+// - USERNAME_OPTION : the database user on whose behalf the connection is being made
+// - PASSWORD_OPTION : the user's password
+//
+// 2. Connector-option to specify your own JDBCConnectionHandler
+// - CONNECTOR_OPTION : a classname which is implementing the JDBCConnectionHandler-interface
+// This interface is used to get a customized connection.
+// If in addition the database-options are given, these options will be used
+// for invocation of the JDBCConnectionHandler-interface to get a connection.
+// Else if no database-options are given, the JDBCConnectionHandler-interface is called without these options.
+//
+// 3. SQL-option to specify a static sql-statement which will be performed with every occuring message-event
+// - SQL_OPTION : a sql-statement which will be used to write to the database
+// If you give this option, the table-option and columns-option will be ignored !
+// Use the variable @MSG@ on that location in the statement, which has to be dynamically replaced by the message.
+//
+// 4. Table-option to specify one table contained by the database
+// - TABLE_OPTION : the table in which the logging will be done
+//
+// 5. Columns-option to describe the important columns of the table (Not nullable columns are mandatory to describe!)
+// - COLUMNS_OPTION : a formatted list of column-descriptions
+// Each column description consists of
+// - the name of the column (required)
+// - a logtype which is a static constant of class LogType (required)
+// - and a value which depends by the LogType (optional/required, depending by logtype)
+// Here is a description of the available logtypes of class LogType :
+// o MSG = a value will be ignored, the column will get the message. (One columns need to be of this type!)
+// o STATIC = the value will be filled into the column with every logged message. (Ensure that the type of value can be casted into the sql-type of the column!)
+// o ID = value must be a classname, which implements the JDBCIDHandler-interface.
+// o TIMESTAMP = a value will be ignored, the column will be filled with a actually timestamp with every logged message.
+// o EMPTY = a value will be ignored, the column will be ignored when writing to the database (Ensure to fill not nullable columns by a database trigger!)
+// If there are more than one column to describe, the columns must be separated by a TAB-delimiter (' ') !
+// The arguments of a column-description must be separated by the delimiter '~' !
+// (Example : name1~logtype1~value1 name2~logtype2~value2...)
+//
+// 6. Layout-options to define the layout of the messages (optional)
+// - the layout wont be set by a xxx_OPTION
+// Configuration-file : see at the following configuration-file example
+// JDBCAppender::setOption() : see at the following code example
+// The default is a layout of class org.apache.log4j.PatternLayout with ConversionPattern=%m
+//
+// 7. Buffer-option to define the size of the message-event-buffer (optional)
+// - BUFFER_OPTION : define how many messages will be buffered until they will be updated to the database.
+// The default is a update on every message (buffer=1=no buffer).
+//
+// 8. Commit-option to define a auto-commitment
+// - COMMIT_OPTION : define whether updated messages should be committed to the database (Y) or not (N).
+// The default is a commit on every buffer-flush.
+
+
+// Here is a Configuration-file example, which can be used with the PropertyConfigurator :
+//
+// Declare a appender variable named JDBC
+log4j.rootCategory=JDBC
+
+// JDBC is a class of JDBCAppender, which writes messages into a database
+log4j.appender.JDBC=JDBCAppender
+
+// 1. Database-options to connect to the database
+log4j.appender.JDBC.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1521))(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1526)))(CONNECT_DATA=(SID=LENZI)))
+log4j.appender.JDBC.username=mex_pr_dev60
+log4j.appender.JDBC.password=mex_pr_dev60
+
+// 2. Connector-option to specify your own JDBCConnectionHandler
+log4j.appender.JDBC.connector=MyConnectionHandler
+
+// 3. SQL-option to specify a static sql-statement which will be performed with every occuring message-event
+log4j.appender.JDBC.sql=INSERT INTO LOGTEST (id, msg, created_on, created_by) VALUES (1, @MSG@, sysdate, 'me')
+
+// 4. Table-option to specify one table contained by the database
+log4j.appender.JDBC.table=logtest
+
+// 5. Columns-option to describe the important columns of the table (Not nullable columns are mandatory to describe!)
+log4j.appender.JDBC.columns=id_seq~EMPTY id~ID~MyIDHandler msg~MSG created_on~TIMESTAMP created_by~STATIC~Thomas Fenner (t.fenner@klopotek.de)
+
+// 6. Layout-options to define the layout of the messages (optional)
+log4j.appender.JDBC.layout=org.apache.log4j.PatternLayout
+log4j.appender.JDBC.layout.ConversionPattern=%m
+
+// 7. Buffer-option to define the size of the message-event-buffer (optional)
+log4j.appender.JDBC.buffer=1
+
+// 8. Commit-option to define a auto-commitment
+log4j.appender.JDBC.commit=Y
+*/
+
+// Here is a code example to configure the JDBCAppender with a configuration-file :
+
+import org.apache.log4j.*;
+import org.apache.log4j.net.JDBCConnectionHandler;
+import org.apache.log4j.net.JDBCIDHandler;
+
+import java.sql.*;
+import java.util.*;
+
+public class JDBCAppenderWithConfigFileLog4JTest
+{
+ // Create a category instance for this class
+ static Category cat = Category.getInstance(JDBCAppenderWithConfigFileLog4JTest.class.getName());
+
+ public static void main(String[] args)
+ {
+ // Ensure to have all necessary drivers installed !
+ try
+ {
+ Driver d = (Driver)(Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
+ DriverManager.registerDriver(d);
+ }
+ catch(Exception e){}
+
+ // Set the priority which messages have to be logged
+ cat.setPriority(Priority.INFO);
+
+ // Configuration with configuration-file
+ PropertyConfigurator.configure("log4jtestprops.txt");
+
+ // These messages with Priority >= setted priority will be logged to the database.
+ cat.debug("debug"); //this not, because Priority DEBUG is less than INFO
+ cat.info("info");
+ cat.error("error");
+ cat.fatal("fatal");
+ }
+}
+
+// Here is a code example to configure the JDBCAppender without a configuration-file :
+/*
+import org.apache.log4j.*;
+import java.sql.*;
+import java.lang.*;
+import java.util.*;
+
+public class Log4JTest
+{
+ // Create a category instance for this class
+ static Category cat = Category.getInstance(Log4JTest.class.getName());
+
+ public static void main(String[] args)
+ {
+ // A JDBCIDHandler
+ MyIDHandler idhandler = new MyIDHandler();
+
+ // Ensure to have all necessary drivers installed !
+ try
+ {
+ Driver d = (Driver)(Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
+ DriverManager.registerDriver(d);
+ }
+ catch(Exception e){}
+
+ // Set the priority which messages have to be logged
+ cat.setPriority(Priority.DEBUG);
+
+ // Create a new instance of JDBCAppender
+ JDBCAppender ja = new JDBCAppender();
+
+ // Set options with method setOption()
+ ja.setOption(JDBCAppender.CONNECTOR_OPTION, "MyConnectionHandler");
+ ja.setOption(JDBCAppender.URL_OPTION, "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1521))(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1526)))(CONNECT_DATA=(SID=LENZI)))");
+ ja.setOption(JDBCAppender.USERNAME_OPTION, "mex_pr_dev60");
+ ja.setOption(JDBCAppender.PASSWORD_OPTION, "mex_pr_dev60");
+
+ ja.setOption(JDBCAppender.TABLE_OPTION, "logtest");
+
+ // There are two ways to setup the column-descriptions :
+ // 1. Use the the method setOption(JDBCAppender.COLUMNS_OPTION, column-description)
+ //ja.setOption(JDBCAppender.COLUMNS_OPTION, "id_seq~EMPTY id~ID~MyIDHandler msg~MSG created_on~TIMESTAMP created_by~STATIC~:-) Thomas Fenner (t.fenner@klopotek.de)");
+ // 2. Use the better way of coding with method setLogType(String columnname, int LogType.xxx, Object xxx)
+ ja.setLogType("id_seq", LogType.EMPTY, "");
+ ja.setLogType("id", LogType.ID, idhandler);
+ ja.setLogType("msg", LogType.MSG, "");
+ ja.setLogType("created_on", LogType.TIMESTAMP, "");
+ ja.setLogType("created_by", LogType.STATIC, "FEN");
+
+ // If you just want to perform a static sql-statement, forget about the table- and columns-options,
+ // and use this one :
+ //ja.setOption(JDBCAppender.SQL_OPTION, "INSERT INTO LOGTEST (id, msg, created_on, created_by) VALUES (1, @MSG@, sysdate, 'me')");
+
+ // other options
+ //ja.setOption(JDBCAppender.BUFFER_OPTION, "1");
+ //ja.setOption(JDBCAppender.COMMIT_OPTION, "Y");
+
+ // Define a layout
+ //ja.setLayout(new PatternLayout("%m"));
+
+ // Add the appender to a category
+ cat.addAppender(ja);
+
+ // These messages with Priority >= setted priority will be logged to the database.
+ cat.debug("debug");
+ cat.info("info");
+ cat.error("error");
+ cat.fatal("fatal");
+ }
+}
+*/
+
+// Implement a sample JDBCConnectionHandler
+class JDBCAppenderWithConfigFileLog4JTestConnectionHandler implements JDBCConnectionHandler
+{
+ Connection con = null;
+ //Default connection
+ String url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1521))(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(Host=LENZI)(Port=1526)))(CONNECT_DATA=(SID=LENZI)))";
+ String username = "mex_pr_dev60";
+ String password = "mex_pr_dev60";
+
+ public Connection getConnection()
+ {
+ return getConnection(url, username, password);
+ }
+
+ public Connection getConnection(String _url, String _username, String _password)
+ {
+ try
+ {
+ if(con != null && !con.isClosed()) con.close();
+ con = DriverManager.getConnection(_url, _username, _password);
+ con.setAutoCommit(false);
+ }
+ catch(Exception e){}
+
+ return con;
+ }
+}
+
+
+// Implement a sample JDBCIDHandler
+class JDBCAppenderWithConfigFileIDHandler implements JDBCIDHandler
+{
+ private static long id = 0;
+
+ public synchronized Object getID()
+ {
+ return new Long(++id);
+ }
+}
+
+
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/JDBCAppenderWithConfigFileLog4JTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/configfile_example.txt (from r1345516, logging/log4j/branches/log4j12-bz53299/contribs/ThomasFenner/configfile_example.txt)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/configfile_example.txt?p2=logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/configfile_example.txt&p1=logging/log4j/branches/log4j12-bz53299/contribs/ThomasFenner/configfile_example.txt&r1=1345516&r2=1345524&rev=1345524&view=diff
==============================================================================
(empty)
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/configfile_example.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/java/org/apache/log4j/contribs/ThomasFenner/configfile_example.txt
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Copied: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/CompositeRollingAppender.java (from r1345516, logging/log4j/branches/log4j12-bz53299/contribs/KevinSteppe/CompositeRollingAppender.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/CompositeRollingAppender.java?p2=logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/CompositeRollingAppender.java&p1=logging/log4j/branches/log4j12-bz53299/contribs/KevinSteppe/CompositeRollingAppender.java&r1=1345516&r2=1345524&rev=1345524&view=diff
==============================================================================
(empty)
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/CompositeRollingAppender.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/CompositeRollingAppender.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Copied: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/DailyFileAppender.java (from r1345516, logging/log4j/branches/log4j12-bz53299/contribs/EirikLygre/DailyFileAppender1.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/DailyFileAppender.java?p2=logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/DailyFileAppender.java&p1=logging/log4j/branches/log4j12-bz53299/contribs/EirikLygre/DailyFileAppender1.java&r1=1345516&r2=1345524&rev=1345524&view=diff
==============================================================================
(empty)
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/DailyFileAppender.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/DailyFileAppender.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/TempFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/TempFileAppender.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/TempFileAppender.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/TempFileAppender.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j;
+
+import java.io.File;
+import java.io.Writer;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.helpers.OptionConverter;
+import org.apache.log4j.spi.ErrorHandler;
+
+/**
+ TempFileAppender creates new unique file for each logging statement.
+
+ @author Leos Literak
+ @author Ceki Gülcü
+
+*/
+public class TempFileAppender extends AppenderSkeleton {
+
+ /**
+ A string constant used in naming the option for setting the
+ directory where the log files will be created. Current value
+ of this string constant is Path. java.io.tmpdir directory
+ will be used, if ommited.
+ */
+ static final public String PATH_OPTION = "Path";
+
+ /**
+ The default path is actual directory.
+ */
+ protected String path = null;
+
+ /**
+ A string constant used in naming the option for setting the
+ prefix of the log files. It has to have at least 3 characters!
+ Current value of this string constant is Prefix.
+ */
+ static final public String PREFIX_OPTION = "Prefix";
+
+ /**
+ The default path is actual directory.
+ */
+ protected String prefix = "l4j_";
+
+ /**
+ A string constant used in naming the option for setting the
+ suffix of the log files. Current value of this string constant
+ is Suffix.
+ */
+ static final public String SUFFIX_OPTION = "Suffix";
+
+ /**
+ The default path is actual directory.
+ */
+ protected String suffix = ".tmp";
+
+ /**
+ Default dir
+ */
+
+ protected File dir = null;
+
+
+
+
+ /**
+ The default constructor simply calls its parent's constructor.
+ */
+ public TempFileAppender() {
+ super();
+ }
+
+ /**
+ Retuns the option names for this component
+ */
+ public String[] getOptionStrings() {
+ return OptionConverter.concatanateArrays(super.getOptionStrings(),
+ new String[] {PATH_OPTION,PREFIX_OPTION,SUFFIX_OPTION});
+ }
+
+ /**
+ Set TempFileAppender specific options.
+
+ The recognized options are Path, Prefix and Suffix,
+ i.e. the values of the string constants {@link #PATH_OPTION},
+ {@link #PREFIX_OPTION} and respectively {@link #SUFFIX_OPTION}.
+ The options of the super class {@link AppenderSkeleton} are also
+ recognized.
+ */
+
+ public void setOption(String key, String value) {
+ super.setOption(key, value);
+ if(key.equalsIgnoreCase(PATH_OPTION)) {
+ path = value;
+ if(path==null) {
+ errorHandler.error("Path cannot be empty!",null,0);
+ }
+
+ dir = new File(path);
+ if(!(dir.exists() && dir.isDirectory() && dir.canWrite())) {
+ errorHandler.error("Cannot write to directory " + path + "!",null,0);
+ }
+ }
+ else if(key.equalsIgnoreCase(PREFIX_OPTION)) {
+ if(value!=null && value.length()>=3) {
+ prefix = value;
+ } else {
+ errorHandler.error("Prefix cannot be shorter than 3 characters!",
+ null,0);
+ }
+ }
+ else if(key.equalsIgnoreCase(SUFFIX_OPTION)) {
+ if(value!=null && value.length()>=1) {
+ suffix = value;
+ } else {
+ errorHandler.error("Suffix cannot be empty!",null,0);
+ }
+ }
+ }
+
+ /**
+ This method is called by {@link AppenderSkeleton#doAppend}
+ method.
+
+ Whenever this method is called, new unique file is created
+ with specified prefix and suffix. The file is closed afterwards.
+
+
The format of the output will depend on this appender's
+ layout.
+
+ */
+ public void append(LoggingEvent event) {
+ if(!checkEntryConditions()) {
+ return;
+ }
+ subAppend(event);
+ }
+
+ /**
+ This method determines if there is a sense in attempting to append.
+ */
+ protected boolean checkEntryConditions() {
+ return true;
+ }
+
+ /**
+ This method does actual writing
+ */
+ protected void subAppend(LoggingEvent event) {
+ try {
+ File tmp = File.createTempFile(prefix,suffix,dir);
+ Writer out = new BufferedWriter(new FileWriter(tmp));
+ out.write(event.message);
+ out.close();
+ /* this Appender is not supposed to be used for logging of Exceptions */
+ } catch (Exception e) {
+ errorHandler.error("Error during creation of temporary File!",e,1);
+ }
+ }
+
+ public boolean requiresLayout() {
+ return false;
+ }
+
+ public void close() {
+ /* nothing to do */
+ }
+}
+/*
+ * @author $Author$
+ * @version $Revision$
+ * @since $Date$
+ *
+ * $Log$
+ * Revision 1.1.2.1 2005/05/27 03:27:54 mwomack
+ * Fix for #35032. Added license header to .java files that did not already have a license.
+ *
+ * Revision 1.1 2001/04/20 17:38:31 ceki
+ *
+ * Added LeosLiterak's TempFileAppender.java
+ *
+*/
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/TempFileAppender.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/LogTextPanel.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/LogTextPanel.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/LogTextPanel.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/LogTextPanel.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.gui;
+
+import java.awt.Color;
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.awt.BorderLayout;
+
+import javax.swing.*;
+import javax.swing.text.StyledDocument;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.StyleConstants;
+
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Enumeration;
+import java.util.ArrayList;
+
+import org.apache.log4j.*;
+
+/**
+ * @author James House
+ */
+public class LogTextPanel extends JPanel {
+
+ private JScrollBar scrollBar;
+ private JTextPane textPane;
+ private JCheckBox cbxTail;
+ private StyledDocument doc;
+
+ private Hashtable fontAttributes;
+
+ private int eventBufferMaxSize = 10000;
+ private ArrayList eventBuffer = new ArrayList(eventBufferMaxSize);
+ private int eventViewIndex = 0;
+
+ public LogTextPanel() {
+ constructComponents();
+ createDefaultFontAttributes();
+ }
+
+ private void constructComponents() {
+ // setup the panel's additional components...
+ this.setLayout(new BorderLayout());
+
+ cbxTail = new JCheckBox();
+ cbxTail.setSelected(true);
+ cbxTail.setText("Tail log events");
+
+ JPanel bottomPanel = new JPanel();
+ bottomPanel.add(cbxTail, null);
+
+ textPane = new JTextPane();
+ textPane.setEditable(false);
+ textPane.setText("");
+ doc = textPane.getStyledDocument();
+
+ scrollBar = new JScrollBar(JScrollBar.VERTICAL);
+
+ this.add(bottomPanel, BorderLayout.SOUTH);
+ this.add(scrollBar, BorderLayout.EAST);
+ this.add(textPane, BorderLayout.CENTER);
+ }
+
+ public
+ void setTextBackground(Color color) {
+ textPane.setBackground(color);
+ }
+
+ public
+ void setTextBackground(String v) {
+ textPane.setBackground(parseColor(v));
+ }
+
+ private void createDefaultFontAttributes() {
+ Priority[] prio = Priority.getAllPossiblePriorities();
+
+ fontAttributes = new Hashtable();
+ for (int i=0; i= eventBufferMaxSize) {
+ for(int i=0; i < evts.length; i++) {
+ eventBuffer.remove(0);
+ }
+ eventViewIndex -= evts.length;
+ if(eventViewIndex < 0)
+ eventViewIndex = 0;
+ }
+ for(int i=0; i < evts.length; i++)
+ eventBuffer.add(evts[i]);
+
+ if((eventBuffer.size() > maxR) && cbxTail.isSelected()) {
+ eventViewIndex = (eventBuffer.size() - maxR);
+ }
+
+ // only redraw if new line is visible...
+ if((maxR < 0) || (eventBuffer.size() >= eventViewIndex && eventBuffer.size() <= (eventViewIndex + maxR)))
+ drawText();
+ }
+
+ int maxR = -1;
+
+ void drawText() {
+ if(maxR < 0)
+ maxR = textPane.getHeight() / textPane.getFontMetrics(textPane.getFont()).getHeight();
+ try {
+ doc.remove(0, doc.getLength());
+ } catch(Exception e) { e.printStackTrace(); }
+
+ for(int i=eventViewIndex; (i < eventBuffer.size()) && (i < (eventViewIndex + maxR)); i++) {
+ EventBufferElement evt = (EventBufferElement)eventBuffer.get(i);
+
+ try {
+ doc.insertString(doc.getLength(), evt.text, (MutableAttributeSet)fontAttributes.get(evt.prio));
+ } catch(Exception e) { e.printStackTrace(); }
+ }
+ }
+
+
+}
\ No newline at end of file
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/LogTextPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/TextPaneAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/TextPaneAppender.java?rev=1345524&view=auto
==============================================================================
--- logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/TextPaneAppender.java (added)
+++ logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/TextPaneAppender.java Sat Jun 2 15:35:46 2012
@@ -0,0 +1,354 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.log4j.gui;
+
+
+import java.awt.Color;
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.io.*;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.Hashtable;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JTextPane;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+import javax.swing.text.TabSet;
+import javax.swing.text.TabStop;
+
+import org.apache.log4j.*;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.helpers.Loader;
+import org.apache.log4j.helpers.QuietWriter;
+import org.apache.log4j.helpers.TracerPrintWriter;
+import org.apache.log4j.helpers.OptionConverter;
+
+
+/**
+ * Experimental TextPaneAppender.
+ *
+ *
+ * Created: Sat Feb 26 18:50:27 2000
+ *
+ * @author Sven Reimers
+ */
+public class TextPaneAppender extends AppenderSkeleton {
+
+ JTextPane textpane;
+ StyledDocument doc;
+ TracerPrintWriter tp;
+ StringWriter sw;
+ QuietWriter qw;
+ Hashtable attributes;
+ Hashtable icons;
+
+ private String label;
+
+ private boolean fancy;
+
+ final String LABEL_OPTION = "Label";
+ final String COLOR_OPTION_FATAL = "Color.Emerg";
+ final String COLOR_OPTION_ERROR = "Color.Error";
+ final String COLOR_OPTION_WARN = "Color.Warn";
+ final String COLOR_OPTION_INFO = "Color.Info";
+ final String COLOR_OPTION_DEBUG = "Color.Debug";
+ final String COLOR_OPTION_BACKGROUND = "Color.Background";
+ final String FANCY_OPTION = "Fancy";
+ final String FONT_NAME_OPTION = "Font.Name";
+ final String FONT_SIZE_OPTION = "Font.Size";
+
+ public static Image loadIcon ( String path ) {
+ Image img = null;
+ try {
+ URL url = ClassLoader.getSystemResource(path);
+ img = (Image) (Toolkit.getDefaultToolkit()).getImage(url);
+ } catch (Exception e) {
+ System.out.println("Exception occured: " + e.getMessage() +
+ " - " + e );
+ }
+ return (img);
+ }
+
+ public TextPaneAppender(Layout layout, String name) {
+ this();
+ this.layout = layout;
+ this.name = name;
+ setTextPane(new JTextPane());
+ createAttributes();
+ createIcons();
+ }
+
+ public TextPaneAppender() {
+ super();
+ setTextPane(new JTextPane());
+ createAttributes();
+ createIcons();
+ this.label="";
+ this.sw = new StringWriter();
+ this.qw = new QuietWriter(sw, errorHandler);
+ this.tp = new TracerPrintWriter(qw);
+ this.fancy =true;
+ }
+
+ public
+ void close() {
+
+ }
+
+ private void createAttributes() {
+ Priority prio[] = Priority.getAllPossiblePriorities();
+
+ attributes = new Hashtable();
+ for (int i=0; i= 255 ? res : res + ","+c.getAlpha();
+ }
+
+ public
+ void setLayout(Layout layout) {
+ this.layout=layout;
+ }
+
+ public
+ void setName(String name) {
+ this.name = name;
+ }
+
+
+ public
+ void setTextPane(JTextPane textpane) {
+ this.textpane=textpane;
+ textpane.setEditable(false);
+ textpane.setBackground(Color.lightGray);
+ this.doc=textpane.getStyledDocument();
+ }
+
+ private
+ void setColor(Priority p, String v) {
+ StyleConstants.setForeground(
+ (MutableAttributeSet)attributes.get(p),parseColor(v));
+ }
+
+ private
+ String getColor(Priority p) {
+ Color c = StyleConstants.getForeground(
+ (MutableAttributeSet)attributes.get(p));
+ return c == null ? null : colorToString(c);
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ // option setters and getters
+
+ public
+ void setLabel(String label) {
+ this.label = label;
+ }
+ public
+ String getLabel() {
+ return label;
+ }
+
+ public
+ void setColorEmerg(String color) {
+ setColor(Priority.FATAL, color);
+ }
+ public
+ String getColorEmerg() {
+ return getColor(Priority.FATAL);
+ }
+
+ public
+ void setColorError(String color) {
+ setColor(Priority.ERROR, color);
+ }
+ public
+ String getColorError() {
+ return getColor(Priority.ERROR);
+ }
+
+ public
+ void setColorWarn(String color) {
+ setColor(Priority.WARN, color);
+ }
+ public
+ String getColorWarn() {
+ return getColor(Priority.WARN);
+ }
+
+ public
+ void setColorInfo(String color) {
+ setColor(Priority.INFO, color);
+ }
+ public
+ String getColorInfo() {
+ return getColor(Priority.INFO);
+ }
+
+ public
+ void setColorDebug(String color) {
+ setColor(Priority.DEBUG, color);
+ }
+ public
+ String getColorDebug() {
+ return getColor(Priority.DEBUG);
+ }
+
+ public
+ void setColorBackground(String color) {
+ textpane.setBackground(parseColor(color));
+ }
+ public
+ String getColorBackground() {
+ return colorToString(textpane.getBackground());
+ }
+
+ public
+ void setFancy(boolean fancy) {
+ this.fancy = fancy;
+ }
+ public
+ boolean getFancy() {
+ return fancy;
+ }
+
+ public
+ void setFontSize(int size) {
+ Enumeration e = attributes.elements();
+ while (e.hasMoreElements()) {
+ StyleConstants.setFontSize((MutableAttributeSet)e.nextElement(),size);
+ }
+ return;
+ }
+
+ public
+ int getFontSize() {
+ AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO);
+ return StyleConstants.getFontSize(attrSet);
+ }
+
+ public
+ void setFontName(String name) {
+ Enumeration e = attributes.elements();
+ while (e.hasMoreElements()) {
+ StyleConstants.setFontFamily((MutableAttributeSet)e.nextElement(),name);
+ }
+ return;
+ }
+
+ public
+ String getFontName() {
+ AttributeSet attrSet = (AttributeSet) attributes.get(Priority.INFO);
+ return StyleConstants.getFontFamily(attrSet);
+ }
+
+ public
+ boolean requiresLayout() {
+ return true;
+ }
+} // TextPaneAppender
+
+
+
Propchange: logging/log4j/branches/log4j12-bz53299/modules/contribs/src/stale/org/apache/log4j/gui/TextPaneAppender.java
------------------------------------------------------------------------------
svn:eol-style = native