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

(-)src/main/java/org/apache/log4j/helpers/SyslogWriter.java (-2 / +15 lines)
Lines 36-41 Link Here
36
*/
36
*/
37
public class SyslogWriter extends Writer {
37
public class SyslogWriter extends Writer {
38
38
39
  public static final int DEFAULT_MAX_PACKET_LENGTH = 1024;
40
39
  final int SYSLOG_PORT = 514;
41
  final int SYSLOG_PORT = 514;
40
  /**
42
  /**
41
   *  Host string from last constructed SyslogWriter.
43
   *  Host string from last constructed SyslogWriter.
Lines 46-51 Link Here
46
  private InetAddress address;
48
  private InetAddress address;
47
  private final int port;
49
  private final int port;
48
  private DatagramSocket ds;
50
  private DatagramSocket ds;
51
  private int maxPacketLength = DEFAULT_MAX_PACKET_LENGTH;
49
52
50
  /**
53
  /**
51
   *  Constructs a new instance of SyslogWriter.
54
   *  Constructs a new instance of SyslogWriter.
Lines 124-131 Link Here
124
        //  syslog packets must be less than 1024 bytes
127
        //  syslog packets must be less than 1024 bytes
125
        //
128
        //
126
        int bytesLength = bytes.length;
129
        int bytesLength = bytes.length;
127
        if (bytesLength >= 1024) {
130
        if (bytesLength >= maxPacketLength) {
128
            bytesLength = 1024;
131
            bytesLength = maxPacketLength;
129
        }
132
        }
130
        DatagramPacket packet = new DatagramPacket(bytes, bytesLength,
133
        DatagramPacket packet = new DatagramPacket(bytes, bytesLength,
131
                               address, port);
134
                               address, port);
Lines 135-140 Link Here
135
  }
138
  }
136
139
137
  public
140
  public
141
  void setMaxPacketLength(int max) {
142
     maxPacketLength = max;
143
  }
144
145
  public
146
  int getMaxPacketLength() {
147
     return maxPacketLength;
148
  }
149
150
  public
138
  void flush() {}
151
  void flush() {}
139
152
140
  public void close() {
153
  public void close() {
(-)src/main/java/org/apache/log4j/net/SyslogAppender.java (-3 / +24 lines)
Lines 97-105 Link Here
97
  int syslogFacility = LOG_USER;
97
  int syslogFacility = LOG_USER;
98
  String facilityStr;
98
  String facilityStr;
99
  boolean facilityPrinting = false;
99
  boolean facilityPrinting = false;
100
  int maxPacketLength = SyslogWriter.DEFAULT_MAX_PACKET_LENGTH;
100
101
101
  //SyslogTracerPrintWriter stp;
102
  //SyslogTracerPrintWriter stp;
102
  SyslogQuietWriter sqw;
103
  SyslogQuietWriter sqw;
104
  SyslogWriter sw;
103
  String syslogHost;
105
  String syslogHost;
104
106
105
    /**
107
    /**
Lines 283-289 Link Here
283
      //      of 1024 bytes, then write it
285
      //      of 1024 bytes, then write it
284
      //      (must allow for up 5to 5 characters in the PRI section
286
      //      (must allow for up 5to 5 characters in the PRI section
285
      //          added by SyslogQuietWriter)
287
      //          added by SyslogQuietWriter)
286
      if (byteCount <= 1019) {
288
      if (byteCount <= (maxPacketLength-5)) {
287
          sqw.write(packet);
289
          sqw.write(packet);
288
      } else {
290
      } else {
289
          int split = header.length() + (packet.length() - header.length())/2;
291
          int split = header.length() + (packet.length() - header.length())/2;
Lines 388-395 Link Here
388
   */
390
   */
389
  public
391
  public
390
  void setSyslogHost(final String syslogHost) {
392
  void setSyslogHost(final String syslogHost) {
391
    this.sqw = new SyslogQuietWriter(new SyslogWriter(syslogHost),
393
    this.sw = new SyslogWriter(syslogHost);
392
				     syslogFacility, errorHandler);
394
    sw.setMaxPacketLength(maxPacketLength);
395
    this.sqw = new SyslogQuietWriter(sw, syslogFacility, errorHandler);
393
    //this.stp = new SyslogTracerPrintWriter(sqw);
396
    //this.stp = new SyslogTracerPrintWriter(sqw);
394
    this.syslogHost = syslogHost;
397
    this.syslogHost = syslogHost;
395
  }
398
  }
Lines 403-408 Link Here
403
  }
406
  }
404
407
405
  /**
408
  /**
409
   */
410
  public
411
  void setMaxPacketLength(final int maxPacketLength) {
412
    this.maxPacketLength = maxPacketLength;
413
    if (sw != null) {
414
       sw.setMaxPacketLength(maxPacketLength);
415
    }
416
  }
417
418
  /**
419
     Returns the value of the <b>SyslogHost</b> option.
420
   */
421
  public
422
  int getMaxPacketLength() {
423
    return maxPacketLength;
424
  }
425
426
  /**
406
     Set the syslog facility. This is the <b>Facility</b> option.
427
     Set the syslog facility. This is the <b>Facility</b> option.
407
428
408
     <p>The <code>facilityName</code> parameter must be one of the
429
     <p>The <code>facilityName</code> parameter must be one of the

Return to bug 49177