ceki        2003/06/25 11:15:08

  Modified:    src/java/org/apache/log4j/net SocketAppender.java
  Log:
  This is a simplified version of what was in the sandbox.
  
  - The log4japp option is no longer set from the system properties if not 
     already set by the user.
  
  - The overrideProperties option is no longer used. Why was it 
    introduced anyway?
  
  - log4japp renamed to log4jApp to follow the regular Java property
     naming
  
  The rationale for these changes is to make it easier to document the 
  SockerAppender. Too many options tend to confuse the user.
  
  Revision  Changes    Path
  1.18      +44 -7     jakarta-log4j/src/java/org/apache/log4j/net/SocketAppender.java
  
  Index: SocketAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SocketAppender.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SocketAppender.java       25 Jun 2003 17:21:18 -0000      1.17
  +++ SocketAppender.java       25 Jun 2003 18:15:07 -0000      1.18
  @@ -60,6 +60,7 @@
   
   import java.net.InetAddress;
   import java.net.Socket;
  +import java.net.UnknownHostException;
   
   
   /**
  @@ -132,13 +133,13 @@
           @since 0.8.4 */
   public class SocketAppender extends AppenderSkeleton {
     /**
  -         The default port number of remote logging server (4560).
  -  */
  +   * The default port number of remote logging server (4560).
  +   */
     static final int DEFAULT_PORT = 4560;
   
     /**
  -         The default reconnection delay (30000 milliseconds or 30 seconds).
  -  */
  +   * The default reconnection delay (30000 milliseconds or 30 seconds).
  +   */
     static final int DEFAULT_RECONNECTION_DELAY = 30000;
   
     // reset the ObjectOutputStream every 70 calls
  @@ -146,9 +147,9 @@
     private static final int RESET_FREQUENCY = 1;
   
     /**
  -         We remember host name as String in addition to the resolved
  -         InetAddress so that it can be returned via getOption().
  -  */
  +   * We remember host name as String in addition to the resolved
  +   * InetAddress so that it can be returned via getOption().
  +   */
     String remoteHost;
     InetAddress address;
     int port = DEFAULT_PORT;
  @@ -157,6 +158,8 @@
     boolean locationInfo = false;
     private Connector connector;
     int counter = 0;
  +  String localMachine;
  +  String log4jApp;
   
     public SocketAppender() {
     }
  @@ -185,6 +188,16 @@
            Connect to the specified <b>RemoteHost</b> and <b>Port</b>.
     */
     public void activateOptions() {
  +    try {
  +      localMachine = InetAddress.getLocalHost().getHostName();
  +    } catch (UnknownHostException uhe) {
  +      try {
  +        localMachine = InetAddress.getLocalHost().getHostAddress();
  +      } catch (UnknownHostException uhe2) {
  +        localMachine = "unknown";
  +      }
  +    }
  +
       connect(address, port);
     }
   
  @@ -268,6 +281,14 @@
             event.getLocationInformation();
           }
   
  +        if (localMachine != null) {
  +          event.setProperty("log4jMachineName", localMachine);
  +        }
  +
  +        if (log4jApp != null) {
  +          event.setProperty("log4jApp", log4jApp);
  +        }
  +
           oos.writeObject(event);
   
           //LogLog.debug("=========Flushing.");
  @@ -366,6 +387,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 setLog4jApp(String lapp) {
  +    this.log4jApp = lapp;
  +  }
  +
  +  /**
  +         Returns value of the <b>Log4jApp</b> option.
  +   */
  +  public String getLog4jApp() {
  +    return log4jApp;
     }
   
     /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to