Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.net;
 
 
Base class for SyslogAppender.

Parameters:
<E>
Author(s):
Ceki Gülcü
 
 public abstract class SyslogAppenderBase<E> extends AppenderBase<E> {
 
       + "#syslog_layout";
   final static int MSG_SIZE_LIMIT = 256 * 1024;
 
   Layout<E> layout;
   protected String suffixPattern;
 
   public void start() {
     int errorCount = 0;
     if ( == null) {
       addError("The Facility option is mandatory");
       errorCount++;
     }
 
     try {
        = new SyslogOutputStream();
     } catch (UnknownHostException e) {
       addError("Could not create SyslogWriter"e);
       errorCount++;
     } catch (SocketException e) {
       addWarn(
           "Failed to bind to a random datagram socket. Will try to reconnect later.",
           e);
     }
 
     if ( == null) {
        = buildLayout();
     }
 
     if (errorCount == 0) {
       super.start();
     }
   }
 
   abstract public Layout<E> buildLayout();
 
   abstract public int getSeverityForEvent(Object eventObject);
 
   @Override
   protected void append(E eventObject) {
     if (!isStarted()) {
       return;
     }
 
     try {
       String msg = .doLayout(eventObject);
       if(msg == null) {
         return;
       }
       if (msg.length() > ) {
         msg = msg.substring(0, );
       }
       .write(msg.getBytes());
       .flush();
       postProcess(eventObject);
     } catch (IOException ioe) {
       addError("Failed to send diagram to " + ioe);
     }
   }
 
   protected void postProcess(Object eventOutputStream sw) {
 
  }

  
Returns the integer value corresponding to the named syslog facility.

Throws:
java.lang.IllegalArgumentException if the facility string is not recognized
  static public int facilityStringToint(String facilityStr) {
    if ("KERN".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("USER".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("MAIL".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("DAEMON".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("AUTH".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("SYSLOG".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LPR".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("NEWS".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("UUCP".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("CRON".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("AUTHPRIV".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("FTP".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL0".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL1".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL2".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL3".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL4".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL5".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL6".equalsIgnoreCase(facilityStr)) {
      return .;
    } else if ("LOCAL7".equalsIgnoreCase(facilityStr)) {
      return .;
    } else {
      throw new IllegalArgumentException(facilityStr
          + " is not a valid syslog facility string");
    }
  }

  
Returns the value of the SyslogHost option.
  public String getSyslogHost() {
    return ;
  }

  
The SyslogHost option is the name of the the syslog host where log output should go. WARNING If the SyslogHost is not set, then this appender will fail.
  public void setSyslogHost(String syslogHost) {
    this. = syslogHost;
  }

  
Returns the string value of the Facility option. See setFacility(java.lang.String) for the set of allowed values.
  public String getFacility() {
    return ;
  }

  
The Facility option must be set one of the strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, NTP, AUDIT, ALERT, CLOCK, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. Case is not important.

See SyslogConstants and RFC 3164 for more information about the Facility option.

  public void setFacility(String facilityStr) {
    if (facilityStr != null) {
      facilityStr = facilityStr.trim();
    }
    this. = facilityStr;
  }

  

Returns:
  public int getPort() {
    return ;
  }

  
The port number on the syslog server to connect to. Normally, you would not want to change the default value, that is 514.
  public void setPort(int port) {
    this. = port;
  }
  public Layout<E> getLayout() {
    return ;
  }
  public void setLayout(Layout<E> layout) {
    addWarn("The layout of a SyslogAppender cannot be set directly. See also "
        + );
  }
  public void stop() {
    .close();
    super.stop();
  }

See @return
  public String getSuffixPattern() {
    return ;
  }

  
The suffixPattern option specifies the format of the non-standardized part of the message sent to the syslog server.

Parameters:
suffixPattern
  public void setSuffixPattern(String suffixPattern) {
    this. = suffixPattern;
  }
New to GrepCode? Check out our FAQ X