logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r568980 - in /logging/log4j/trunk/src/main/java/org/apache/log4j: helpers/Constants.java net/SocketAppender.java
Date Thu, 23 Aug 2007 13:38:12 GMT
Author: sdeboy
Date: Thu Aug 23 06:38:12 2007
New Revision: 568980

URL: http://svn.apache.org/viewvc?rev=568980&view=rev
Log:
Moved Constants out of component & extras
Added application property & remote host now available as properties via socketappender

Added:
    logging/log4j/trunk/src/main/java/org/apache/log4j/helpers/Constants.java
Modified:
    logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketAppender.java

Added: logging/log4j/trunk/src/main/java/org/apache/log4j/helpers/Constants.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/helpers/Constants.java?rev=568980&view=auto
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/helpers/Constants.java (added)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/helpers/Constants.java Thu Aug 23 06:38:12
2007
@@ -0,0 +1,122 @@
+/*
+ * 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.helpers;
+
+
+/**
+ * Constants used internally throughout log4j.
+ *
+ */
+public interface Constants {
+
+    /**
+     * log4j package name string literal.
+     */
+  String LOG4J_PACKAGE_NAME = "org.apache.log4j";
+
+  /**
+   *  The name of the default repository is "default" (without the quotes).
+   */
+  String DEFAULT_REPOSITORY_NAME  = "default";
+
+    /**
+     * application string literal.
+     */
+  String APPLICATION_KEY = "application";
+    /**
+     * hostname string literal.
+     */
+  String HOSTNAME_KEY = "hostname";
+    /**
+     * receiver string literal.
+     */
+  String RECEIVER_NAME_KEY = "receiver";
+    /**
+     * log4jid string literal.
+     */
+  String LOG4J_ID_KEY = "log4jid";
+    /**
+     * time stamp pattern string literal.
+     */
+  String TIMESTAMP_RULE_FORMAT = "yyyy/MM/dd HH:mm:ss";
+
+  /**
+   * The default property file name for automatic configuration.
+   */
+  String DEFAULT_CONFIGURATION_FILE = "log4j.properties";
+  /**
+   * The default XML configuration file name for automatic configuration.
+   */
+  String DEFAULT_XML_CONFIGURATION_FILE = "log4j.xml";
+    /**
+     * log4j.configuration string literal.
+     */
+  String DEFAULT_CONFIGURATION_KEY = "log4j.configuration";
+    /**
+     * log4j.configuratorClass string literal.
+     */
+  String CONFIGURATOR_CLASS_KEY = "log4j.configuratorClass";
+
+    /**
+     * JNDI context name string literal.
+     */
+  String JNDI_CONTEXT_NAME = "java:comp/env/log4j/context-name";
+
+    /**
+     * TEMP_LIST_APPENDER string literal.
+     */
+  String TEMP_LIST_APPENDER_NAME = "TEMP_LIST_APPENDER";
+    /**
+     * TEMP_CONSOLE_APPENDER string literal.
+     */
+  String TEMP_CONSOLE_APPENDER_NAME = "TEMP_CONSOLE_APPENDER";
+    /**
+     * Codes URL string literal.
+     */
+  String CODES_HREF =
+          "http://logging.apache.org/log4j/docs/codes.html";
+
+
+    /**
+     * ABSOLUTE string literal.
+     */
+  String ABSOLUTE_FORMAT = "ABSOLUTE";
+    /**
+     * SimpleTimePattern for ABSOLUTE.
+     */
+  String ABSOLUTE_TIME_PATTERN = "HH:mm:ss,SSS";
+
+
+    /**
+     * DATE string literal.
+     */
+  String DATE_AND_TIME_FORMAT = "DATE";
+    /**
+     * SimpleTimePattern for DATE.
+     */
+  String DATE_AND_TIME_PATTERN = "dd MMM yyyy HH:mm:ss,SSS";
+
+    /**
+     * ISO8601 string literal.
+     */
+  String ISO8601_FORMAT = "ISO8601";
+    /**
+     * SimpleTimePattern for ISO8601.
+     */
+  String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS";
+}

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketAppender.java?rev=568980&r1=568979&r2=568980&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketAppender.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/net/SocketAppender.java Thu Aug 23
06:38:12 2007
@@ -19,15 +19,17 @@
 
 package org.apache.log4j.net;
 
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.helpers.LogLog;
-import org.apache.log4j.spi.ErrorCode;
-import org.apache.log4j.spi.LoggingEvent;
-
 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.net.InetAddress;
 import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.helpers.Constants;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.ErrorCode;
+import org.apache.log4j.spi.LoggingEvent;
 
 /**
     Sends {@link LoggingEvent} objects to a remote a log server,
@@ -122,12 +124,13 @@
   ObjectOutputStream oos;
   int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
   boolean locationInfo = false;
+  private String hostname;
+  private String application;
 
   private Connector connector;
 
   int counter = 0;
 
-
   // reset the ObjectOutputStream every 70 calls
   //private static final int RESET_FREQUENCY = 70;
   private static final int RESET_FREQUENCY = 1;
@@ -159,6 +162,16 @@
      Connect to the specified <b>RemoteHost</b> and <b>Port</b>.
   */
   public void activateOptions() {
+    try {
+	  hostname = InetAddress.getLocalHost().getHostName();
+	} catch (UnknownHostException uhe) {
+	  try {
+      hostname = InetAddress.getLocalHost().getHostAddress();
+    } catch (UnknownHostException uhe2) {
+	    hostname = "unknown";
+    }
+  }
+
     connect(address, port);
   }
 
@@ -231,9 +244,17 @@
 
     if(oos != null) {
       try {
+    	 
 	if(locationInfo) {
 	   event.getLocationInformation();
 	}
+    if (application != null) {
+        event.setProperty(Constants.APPLICATION_KEY, application);
+    }
+    if (hostname != null) {
+        event.setProperty(Constants.HOSTNAME_KEY, hostname);
+      }
+
 	oos.writeObject(event);
 	//LogLog.debug("=========Flushing.");
 	oos.flush();
@@ -331,6 +352,22 @@
    */
   public boolean getLocationInfo() {
     return locationInfo;
+  }
+
+  /**
+   * The <b>App</b> option takes a string value which should be the name of the

+   * application getting logged.
+   * If property was already set (via system property), don't set here.
+   */
+  public void setApplication(String lapp) {
+    this.application = lapp;
+  }
+
+  /**
+   *  Returns value of the <b>Application</b> option.
+   */
+  public String getApplication() {
+    return application;
   }
 
   /**



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message