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); |