Skip to content

Commit f1e2b52

Browse files
committed
Merge pull request #1556 from deis/docs/syslog
docs(logger/syslog): amend syslog server docs
2 parents b7a7d19 + 8754a6f commit f1e2b52

6 files changed

Lines changed: 63 additions & 47 deletions

File tree

logger/syslog/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# syslog
2+
3+
[![GoDoc](https://godoc.org/github.com/deis/deis/logger/syslog?status.svg)](https://godoc.org/github.com/deis/deis/logger/syslog)
4+
5+
Package syslog implements a syslog server library. It is based on RFC 3164, as
6+
such it does not properly parse packets with an RFC 5424 header format.

logger/syslog/filehandler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"syscall"
88
)
99

10-
// FileHandler implements Handler interface in the way to save messages into a
10+
// FileHandler implements Handler interface to save messages into a
1111
// text file. It properly handles logrotate HUP signal (closes a file and tries
1212
// to open/create new one).
1313
type FileHandler struct {
@@ -89,6 +89,7 @@ func (h *FileHandler) checkErr(err error) bool {
8989
return true
9090
}
9191

92+
// See BaseHandler.Handle
9293
func (h *FileHandler) Handle(m *Message) *Message {
9394
return h.bh.Handle(m)
9495
}

logger/syslog/handler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package syslog
22

33
// Handler handles syslog messages
44
type Handler interface {
5-
// Handle should return Message (mayby modified) for future processing by
5+
// Handle should return Message (maybe modified) for future processing by
66
// other handlers or return nil. If Handle is called with nil message it
77
// should complete all remaining work and properly shutdown before return.
88
Handle(*Message) *Message
99
}
1010

11-
// BaseHandler is desigend for simplify the creation of real handlers. It
11+
// BaseHandler is designed to simplify the creation of real handlers. It
1212
// implements Handler interface using nonblocking queuing of messages and
1313
// simple message filtering.
1414
type BaseHandler struct {
@@ -18,7 +18,7 @@ type BaseHandler struct {
1818
ft bool
1919
}
2020

21-
// NewBaseHandler creates BaseHandler using specified filter. If filter is nil
21+
// NewBaseHandler creates BaseHandler using a specified filter. If filter is nil
2222
// or if it returns true messages are passed to BaseHandler internal queue
2323
// (of qlen length). If filter returns false or ft is true messages are returned
2424
// to server for future processing by other handlers.
@@ -36,7 +36,7 @@ func NewBaseHandler(qlen int, filter func(*Message) bool, ft bool) *BaseHandler
3636
// before return.
3737
func (h *BaseHandler) Handle(m *Message) *Message {
3838
if m == nil {
39-
close(h.queue) // signal that ther is no more messages for processing
39+
close(h.queue) // signal that there is no more messages for processing
4040
<-h.end // wait for handler shutdown
4141
return nil
4242
}
@@ -66,15 +66,15 @@ func (h *BaseHandler) Get() *Message {
6666
return nil
6767
}
6868

69-
// Queue returns BaseHandler internal queue as read-only channel. You can use
70-
// it directly, especially if your handler need to select from multiple channels
69+
// Queue returns the BaseHandler internal queue as a read-only channel. You can use
70+
// it directly, especially if your handler needs to select from multiple channels
7171
// or have to work without blocking. You need to check if this channel is closed by
7272
// sender and properly shutdown in this case.
7373
func (h *BaseHandler) Queue() <-chan *Message {
7474
return h.queue
7575
}
7676

77-
// End signals the server that handler properly shutdown. You need to call End
77+
// End signals the server that the handler properly shutdown. You need to call End
7878
// only if Get has returned nil before.
7979
func (h *BaseHandler) End() {
8080
close(h.end)

logger/syslog/message.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"time"
77
)
88

9+
// Struct Message defines an RFC 3164 syslog message.
910
type Message struct {
10-
Time time.Time
11-
Source net.Addr
12-
Facility
13-
Severity
11+
Time time.Time // time the message was logged
12+
Source net.Addr // source address of the log message
13+
Facility // facility tag (see type Facility)
14+
Severity // severity tag (see type Severity)
1415
Timestamp time.Time // optional
1516
Hostname string // optional
1617
Tag string // message tag as defined in RFC 3164
@@ -33,6 +34,8 @@ func (m *Message) NetSrc() string {
3334
return m.Source.String()
3435
}
3536

37+
// String returns the Message in a string format. This satisfies the fmt.Stringer
38+
// interface.
3639
func (m *Message) String() string {
3740
timeLayout := "2006-01-02 15:04:05"
3841
return fmt.Sprintf(

logger/syslog/priority.go

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@ package syslog
22

33
type Facility byte
44

5+
// The following is a list of Facilities as defined by RFC 3164.
56
const (
6-
Kern Facility = iota
7-
User
8-
Mail
9-
Daemon
10-
Auth
11-
Syslog
12-
Lpr
13-
News
14-
Uucp
15-
Cron
16-
Authpriv
17-
System0
18-
System1
19-
System2
20-
System3
21-
System4
22-
Local0
23-
Local1
24-
Local2
25-
Local3
26-
Local4
27-
Local5
28-
Local6
29-
Local7
7+
Kern Facility = iota // kernel messages
8+
User // user-level messages
9+
Mail // mail system
10+
Daemon // system daemons
11+
Auth // security/authorization messages
12+
Syslog // messages internal to syslogd
13+
Lpr // line printer subsystem
14+
News // newtork news subsystem
15+
Uucp // UUCP subsystem
16+
Cron // cron messages
17+
Authpriv // security/authorization messages
18+
System0 // historically FTP daemon
19+
System1 // historically NTP subsystem
20+
System2 // historically log audit
21+
System3 // historically log alert
22+
System4 // historically clock daemon, some operating systems use this for cron
23+
Local0 // local use 0
24+
Local1 // local use 1
25+
Local2 // local use 2
26+
Local3 // local use 3
27+
Local4 // local use 4
28+
Local5 // local use 5
29+
Local6 // local use 6
30+
Local7 // local use 7
3031
)
3132

3233
var facToStr = [...]string{
@@ -56,6 +57,8 @@ var facToStr = [...]string{
5657
"local7",
5758
}
5859

60+
// String returns a string representation of the Facility. This satisfies the
61+
// fmt.Stringer interface.
5962
func (f Facility) String() string {
6063
if f > Local7 {
6164
return "unknown"
@@ -66,14 +69,14 @@ func (f Facility) String() string {
6669
type Severity byte
6770

6871
const (
69-
Emerg Severity = iota
70-
Alert
71-
Crit
72-
Err
73-
Warning
74-
Notice
75-
Info
76-
Debug
72+
Emerg Severity = iota // Emergency: system is unusable
73+
Alert // immediate action required
74+
Crit // critical conditions
75+
Err // error conditions
76+
Warning // warning conditions
77+
Notice // normal but significant condition
78+
Info // information message
79+
Debug // debug-level message
7780
)
7881

7982
var sevToStr = [...]string{
@@ -87,6 +90,8 @@ var sevToStr = [...]string{
8790
"debug",
8891
}
8992

93+
// String returns a string representation of the Severity. This satisfies the
94+
// fmt.Stringer interface.
9095
func (s Severity) String() string {
9196
if s > Debug {
9297
return "unknown"

logger/syslog/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Syslog server library. It is based on RFC 3164 so it doesn't parse properly
2-
// packets with new header format (described in RFC 5424).
1+
// Package syslog implements a syslog server library. It is based on RFC 3164,
2+
// as such it does not properly parse packets with an RFC 5424 header format.
33
package syslog
44

55
import (
@@ -13,14 +13,15 @@ import (
1313
"unicode"
1414
)
1515

16+
// Struct Server is the wrapper for a syslog server.
1617
type Server struct {
1718
conns []net.PacketConn
1819
handlers []Handler
1920
shutdown bool
2021
l FatalLogger
2122
}
2223

23-
// NewServer creates idle server
24+
// NewServer creates an idle server
2425
func NewServer() *Server {
2526
return &Server{l: log.New(os.Stderr, "", log.LstdFlags)}
2627
}

0 commit comments

Comments
 (0)