View | Details | Raw Unified | Return to bug 39687
Collapse All | Expand All

(-)/home/gunter/work/log4j/src/java/org/apache/log4j/helpers/SyslogWriter.java (-3 / +19 lines)
Lines 37-43 Link Here
37
*/
37
*/
38
public class SyslogWriter extends Writer {
38
public class SyslogWriter extends Writer {
39
  final int SYSLOG_PORT = 514;
39
  final int SYSLOG_PORT = 514;
40
  String syslogHost;
40
  private int port = SYSLOG_PORT;
41
  private InetAddress address;
41
  private InetAddress address;
42
  private DatagramSocket ds;
42
  private DatagramSocket ds;
43
43
Lines 45-51 Link Here
45
  StringBuffer buf = new StringBuffer();
45
  StringBuffer buf = new StringBuffer();
46
  
46
  
47
  public SyslogWriter(String syslogHost) {
47
  public SyslogWriter(String syslogHost) {
48
    this.syslogHost = syslogHost;
48
    int colon = syslogHost.indexOf(':');
49
    if (colon != -1) {
50
      try {
51
        port = parsePort(syslogHost.substring(colon + 1));
52
      } catch (IllegalArgumentException e) {
53
        logger.error("Illegal port specification in " + syslogHost +
54
               ". Logging will go to syslog port 514.");
55
      }
56
      syslogHost = syslogHost.substring(0, colon);
57
    }
49
58
50
    try {
59
    try {
51
      this.address = InetAddress.getByName(syslogHost);
60
      this.address = InetAddress.getByName(syslogHost);
Lines 64-69 Link Here
64
    }
73
    }
65
  }
74
  }
66
75
76
  private static int parsePort(String s) {
77
    int no = Integer.parseInt(s);
78
    if (no <= 0 || no > 0xffff)
79
      throw new IllegalArgumentException();
80
    return no;
81
  }
82
67
  public void write(char[] charArray, int offset, int len) throws IOException {
83
  public void write(char[] charArray, int offset, int len) throws IOException {
68
    buf.append(charArray, offset, len);
84
    buf.append(charArray, offset, len);
69
  }
85
  }
Lines 77-83 Link Here
77
    logger.debug("Writing out [{}]", buf);
93
    logger.debug("Writing out [{}]", buf);
78
    byte[] bytes = buf.toString().getBytes();
94
    byte[] bytes = buf.toString().getBytes();
79
    DatagramPacket packet =
95
    DatagramPacket packet =
80
      new DatagramPacket(bytes, bytes.length, address, SYSLOG_PORT);
96
      new DatagramPacket(bytes, bytes.length, address, port);
81
97
82
    if (this.ds != null) {
98
    if (this.ds != null) {
83
      ds.send(packet);
99
      ds.send(packet);
(-)/home/gunter/work/log4j/src/java/org/apache/log4j/net/SyslogAppender.java (-1 / +2 lines)
Lines 286-292 Link Here
286
286
287
  /**
287
  /**
288
   * The <b>SyslogHost</b> option is the name of the the syslog host where log
288
   * The <b>SyslogHost</b> option is the name of the the syslog host where log
289
   * output should go.
289
   * output should go. Format: host[:port]. If no port number is specified,
290
   * output goes to syslog standard port 514.
290
   *
291
   *
291
   * <b>WARNING</b> If the SyslogHost is not set, then this appender will fail.
292
   * <b>WARNING</b> If the SyslogHost is not set, then this appender will fail.
292
   */
293
   */

Return to bug 39687