Skip to content

Commit 3f1bb40

Browse files
committed
Modified Facility to use digits 0 - 23 instead of multiplied by 8, to conform with syslog spec
1 parent b680b9c commit 3f1bb40

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

src/main/java/com/cloudbees/syslog/Facility.java

100644100755
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,95 +37,95 @@ public enum Facility implements Comparable<Facility> {
3737
/**
3838
* user-level messages, numerical code 1.
3939
*/
40-
USER(1 << 3, "USER"),
40+
USER(1, "USER"),
4141
/**
4242
* mail system, numerical code 2.
4343
*/
44-
MAIL(2 << 3, "MAIL"),
44+
MAIL(2, "MAIL"),
4545
/**
4646
* system daemons, numerical code 3.
4747
*/
48-
DAEMON(3 << 3, "DAEMON"),
48+
DAEMON(3, "DAEMON"),
4949
/**
5050
* security/authorization messages, numerical code 4.
5151
*/
52-
AUTH(4 << 3, "AUTH"),
52+
AUTH(4, "AUTH"),
5353
/**
5454
* messages generated internally by syslogd, numerical code 5.
5555
*/
56-
SYSLOG(5 << 3, "SYSLOG"),
56+
SYSLOG(5, "SYSLOG"),
5757
/**
5858
* line printer subsystem, numerical code 6.
5959
*/
60-
LPR(6 << 3, "LPR"),
60+
LPR(6, "LPR"),
6161
/**
6262
* network news subsystem, numerical code 7.
6363
*/
64-
NEWS(7 << 3, "NEWS"),
64+
NEWS(7, "NEWS"),
6565
/**
6666
* UUCP subsystem, numerical code 8
6767
*/
68-
UUCP(8 << 3, "UUCP"),
68+
UUCP(8, "UUCP"),
6969
/**
7070
* clock daemon, numerical code 9.
7171
*/
72-
CRON(9 << 3, "CRON"),
72+
CRON(9, "CRON"),
7373
/**
7474
* security/authorization messages, numerical code 10.
7575
*/
76-
AUTHPRIV(10 << 3, "AUTHPRIV"),
76+
AUTHPRIV(10, "AUTHPRIV"),
7777
/**
7878
* ftp daemon, numerical code 11.
7979
*/
80-
FTP(11 << 3, "FTP"),
80+
FTP(11, "FTP"),
8181
/**
8282
* NTP subsystem, numerical code 12.
8383
*/
84-
NTP(12 << 3, "NTP"),
84+
NTP(12, "NTP"),
8585
/**
8686
* log audit, numerical code 13.
8787
*/
88-
AUDIT(13 << 3, "AUDIT"),
88+
AUDIT(13, "AUDIT"),
8989
/**
9090
* log alert, numerical code 14.
9191
*/
92-
ALERT(14 << 3, "ALERT"),
92+
ALERT(14, "ALERT"),
9393
/**
9494
* clock daemon, numerical code 15.
9595
*/
96-
CLOCK(15 << 3, "CLOCK"),
96+
CLOCK(15, "CLOCK"),
9797
/**
9898
* reserved for local use, numerical code 16.
9999
*/
100-
LOCAL0(16 << 3, "LOCAL0"),
100+
LOCAL0(16, "LOCAL0"),
101101
/**
102102
* reserved for local use, numerical code 17.
103103
*/
104-
LOCAL1(17 << 3, "LOCAL1"),
104+
LOCAL1(17, "LOCAL1"),
105105
/**
106106
* reserved for local use, numerical code 18.
107107
*/
108-
LOCAL2(18 << 3, "LOCAL2"),
108+
LOCAL2(18, "LOCAL2"),
109109
/**
110110
* reserved for local use, numerical code 19.
111111
*/
112-
LOCAL3(19 << 3, "LOCAL3"),
112+
LOCAL3(19, "LOCAL3"),
113113
/**
114114
* reserved for local use, numerical code 20.
115115
*/
116-
LOCAL4(20 << 3, "LOCAL4"),
116+
LOCAL4(20, "LOCAL4"),
117117
/**
118118
* reserved for local use, numerical code 21.
119119
*/
120-
LOCAL5(21 << 3, "LOCAL5"),
120+
LOCAL5(21, "LOCAL5"),
121121
/**
122122
* reserved for local use, numerical code 22.
123123
*/
124-
LOCAL6(22 << 3, "LOCAL6"),
124+
LOCAL6(22, "LOCAL6"),
125125
/**
126126
* reserved for local use, numerical code 23.
127127
*/
128-
LOCAL7(23 << 3, "LOCAL7");
128+
LOCAL7(23, "LOCAL7");
129129

130130
// mapping
131131
private final static Map<String, Facility> facilityFromLabel = new HashMap<String, Facility>();

src/main/java/com/cloudbees/syslog/SyslogMessage.java

100644100755
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package com.cloudbees.syslog;
1717

18-
import com.cloudbees.syslog.util.CachingReference;
19-
import com.cloudbees.syslog.util.ConcurrentDateFormat;
20-
2118
import javax.annotation.Nonnull;
2219
import javax.annotation.Nullable;
2320
import java.io.CharArrayWriter;
@@ -31,6 +28,9 @@
3128
import java.util.TimeZone;
3229
import java.util.concurrent.TimeUnit;
3330

31+
import com.cloudbees.syslog.util.CachingReference;
32+
import com.cloudbees.syslog.util.ConcurrentDateFormat;
33+
3434
/**
3535
* Syslog message as defined in <a href="https://tools.ietf.org/html/rfc5424">RFC 5424 - The Syslog Protocol</a>.
3636
*
@@ -267,10 +267,13 @@ public String toRfc5424SyslogMessage() {
267267

268268
/**
269269
* Generates an <a href="http://tools.ietf.org/html/rfc5424">RFC-5424</a> message.
270+
*
271+
* The priority is calculated by facility * 8 + severity, see
272+
* <a href="https://tools.ietf.org/html/rfc5424#section-6.2.1">RFC-5424, Section 6.2.1</a>
270273
*/
271274
public void toRfc5424SyslogMessage(Writer out) throws IOException {
272275

273-
int pri = facility.numericalCode() + severity.numericalCode();
276+
int pri = facility.numericalCode() * 8 + severity.numericalCode();
274277

275278
out.write('<');
276279
out.write(String.valueOf(pri));

src/test/java/com/cloudbees/syslog/SyslogMessageTest.java

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package com.cloudbees.syslog;
1717

18-
import org.junit.Test;
19-
2018
import java.util.Calendar;
2119
import java.util.TimeZone;
2220

21+
import org.junit.Test;
22+
2323
import static org.hamcrest.Matchers.is;
2424
import static org.junit.Assert.assertThat;
2525

@@ -78,7 +78,7 @@ public void testRfc3164Format() throws Exception {
7878
.withMsg("a syslog message");
7979

8080
String actual = message.toRfc3164SyslogMessage();
81-
String expected = "<14>Dec 05 10:30:05 myserver.example.com my_app: a syslog message";
81+
String expected = "<7>Dec 05 10:30:05 myserver.example.com my_app: a syslog message";
8282

8383
assertThat(actual, is(expected));
8484

0 commit comments

Comments
 (0)