Lines 34-41
Link Here
|
34 |
public class SyslogWriter extends Writer { |
34 |
public class SyslogWriter extends Writer { |
35 |
|
35 |
|
36 |
final int SYSLOG_PORT = 514; |
36 |
final int SYSLOG_PORT = 514; |
37 |
static String syslogHost; |
|
|
38 |
|
37 |
|
|
|
38 |
private int port = SYSLOG_PORT; |
39 |
private InetAddress address; |
39 |
private InetAddress address; |
40 |
private DatagramSocket ds; |
40 |
private DatagramSocket ds; |
41 |
|
41 |
|
Lines 41-47
Link Here
|
41 |
|
41 |
|
42 |
public |
42 |
public |
43 |
SyslogWriter(String syslogHost) { |
43 |
SyslogWriter(String syslogHost) { |
44 |
this.syslogHost = syslogHost; |
44 |
int colon = syslogHost.indexOf(':'); |
|
|
45 |
if (colon != -1) { |
46 |
try { |
47 |
port = parsePort(syslogHost.substring(colon + 1)); |
48 |
} catch (IllegalArgumentException e) { |
49 |
LogLog.error("Illegal port specification in " + syslogHost + |
50 |
". Logging will go to syslog port 514."); |
51 |
} |
52 |
syslogHost = syslogHost.substring(0, colon); |
53 |
} |
45 |
|
54 |
|
46 |
try { |
55 |
try { |
47 |
this.address = InetAddress.getByName(syslogHost); |
56 |
this.address = InetAddress.getByName(syslogHost); |
Lines 61-66
Link Here
|
61 |
} |
70 |
} |
62 |
} |
71 |
} |
63 |
|
72 |
|
|
|
73 |
private static |
74 |
int parsePort(String s) { |
75 |
int no = Integer.parseInt(s); |
76 |
if (no <= 0 || no > 0xffff) |
77 |
throw new IllegalArgumentException(); |
78 |
return no; |
79 |
} |
64 |
|
80 |
|
65 |
public |
81 |
public |
66 |
void write(char[] buf, int off, int len) throws IOException { |
82 |
void write(char[] buf, int off, int len) throws IOException { |
Lines 71-77
Link Here
|
71 |
void write(String string) throws IOException { |
87 |
void write(String string) throws IOException { |
72 |
byte[] bytes = string.getBytes(); |
88 |
byte[] bytes = string.getBytes(); |
73 |
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, |
89 |
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, |
74 |
address, SYSLOG_PORT); |
90 |
address, port ); |
75 |
|
91 |
|
76 |
if(this.ds != null) |
92 |
if(this.ds != null) |
77 |
ds.send(packet); |
93 |
ds.send(packet); |