Skip to content

Commit ccbe539

Browse files
committed
golint fixes for daemon/logger/*
- downcase and privatize exported variables that were unused - make accurate an error message - added package comments - remove unused var ReadLogsNotSupported - enable linter - some spelling corrections Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
1 parent 0f85fad commit ccbe539

File tree

8 files changed

+113
-60
lines changed

8 files changed

+113
-60
lines changed

daemon/logger/factory.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
"time"
99
)
1010

11-
// Creator is a method that builds a logging driver instance with given context
11+
// Creator builds a logging driver instance with given context.
1212
type Creator func(Context) (Logger, error)
1313

14-
//LogOptValidator is a method that validates the log opts provided
14+
// LogOptValidator checks the options specific to the underlying
15+
// logging implementation.
1516
type LogOptValidator func(cfg map[string]string) error
1617

17-
// Context provides enough information for a logging driver to do its function
18+
// Context provides enough information for a logging driver to do its function.
1819
type Context struct {
1920
Config map[string]string
2021
ContainerID string
@@ -27,7 +28,7 @@ type Context struct {
2728
LogPath string
2829
}
2930

30-
// Hostname returns the hostname from the underlying OS
31+
// Hostname returns the hostname from the underlying OS.
3132
func (ctx *Context) Hostname() (string, error) {
3233
hostname, err := os.Hostname()
3334
if err != nil {
@@ -36,7 +37,9 @@ func (ctx *Context) Hostname() (string, error) {
3637
return hostname, nil
3738
}
3839

39-
// Command returns the command that the container being logged was started with
40+
// Command returns the command that the container being logged was
41+
// started with. The Entrypoint is prepended to the container
42+
// arguments.
4043
func (ctx *Context) Command() string {
4144
terms := []string{ctx.ContainerEntrypoint}
4245
for _, arg := range ctx.ContainerArgs {
@@ -68,7 +71,7 @@ func (lf *logdriverFactory) registerLogOptValidator(name string, l LogOptValidat
6871
defer lf.m.Unlock()
6972

7073
if _, ok := lf.optValidator[name]; ok {
71-
return fmt.Errorf("logger: log driver named '%s' is already registered", name)
74+
return fmt.Errorf("logger: log validator named '%s' is already registered", name)
7275
}
7376
lf.optValidator[name] = l
7477
return nil
@@ -101,6 +104,8 @@ func RegisterLogDriver(name string, c Creator) error {
101104
return factory.register(name, c)
102105
}
103106

107+
// RegisterLogOptValidator registers the logging option validator with
108+
// the given logging driver name.
104109
func RegisterLogOptValidator(name string, l LogOptValidator) error {
105110
return factory.registerLogOptValidator(name, l)
106111
}
@@ -110,6 +115,8 @@ func GetLogDriver(name string) (Creator, error) {
110115
return factory.get(name)
111116
}
112117

118+
// ValidateLogOpts checks the options for the given log driver. The
119+
// options supported are specific to the LogDriver implementation.
113120
func ValidateLogOpts(name string, cfg map[string]string) error {
114121
l := factory.getLogOptValidator(name)
115122
if l != nil {

daemon/logger/fluentd/fluentd.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package fluentd provides the log driver for forwarding server logs
2+
// to fluentd endpoints.
13
package fluentd
24

35
import (
@@ -14,14 +16,14 @@ import (
1416
"github.com/fluent/fluent-logger-golang/fluent"
1517
)
1618

17-
type Fluentd struct {
19+
type fluentd struct {
1820
tag string
1921
containerID string
2022
containerName string
2123
writer *fluent.Fluent
2224
}
2325

24-
type Receiver struct {
26+
type receiver struct {
2527
ID string
2628
FullID string
2729
Name string
@@ -67,7 +69,7 @@ func parseConfig(ctx logger.Context) (string, int, string, error) {
6769
}
6870

6971
if config["fluentd-tag"] != "" {
70-
receiver := &Receiver{
72+
receiver := &receiver{
7173
ID: ctx.ContainerID[:12],
7274
FullID: ctx.ContainerID,
7375
Name: ctx.ContainerName,
@@ -86,6 +88,9 @@ func parseConfig(ctx logger.Context) (string, int, string, error) {
8688
return host, port, tag, nil
8789
}
8890

91+
// New creates a fluentd logger using the configuration passed in on
92+
// the context. Supported context configuration variables are
93+
// fluentd-address & fluentd-tag.
8994
func New(ctx logger.Context) (logger.Logger, error) {
9095
host, port, tag, err := parseConfig(ctx)
9196
if err != nil {
@@ -99,15 +104,15 @@ func New(ctx logger.Context) (logger.Logger, error) {
99104
if err != nil {
100105
return nil, err
101106
}
102-
return &Fluentd{
107+
return &fluentd{
103108
tag: tag,
104109
containerID: ctx.ContainerID,
105110
containerName: ctx.ContainerName,
106111
writer: log,
107112
}, nil
108113
}
109114

110-
func (f *Fluentd) Log(msg *logger.Message) error {
115+
func (f *fluentd) Log(msg *logger.Message) error {
111116
data := map[string]string{
112117
"container_id": f.containerID,
113118
"container_name": f.containerName,
@@ -119,6 +124,7 @@ func (f *Fluentd) Log(msg *logger.Message) error {
119124
return f.writer.PostWithTime(f.tag, msg.Timestamp, data)
120125
}
121126

127+
// ValidateLogOpt looks for fluentd specific log options fluentd-address & fluentd-tag.
122128
func ValidateLogOpt(cfg map[string]string) error {
123129
for key := range cfg {
124130
switch key {
@@ -131,10 +137,10 @@ func ValidateLogOpt(cfg map[string]string) error {
131137
return nil
132138
}
133139

134-
func (f *Fluentd) Close() error {
140+
func (f *fluentd) Close() error {
135141
return f.writer.Close()
136142
}
137143

138-
func (f *Fluentd) Name() string {
144+
func (f *fluentd) Name() string {
139145
return name
140146
}

daemon/logger/gelf/gelf.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// +build linux
22

3+
// Package gelf provides the log driver for forwarding server logs to
4+
// endpoints that support the Graylog Extended Log Format.
35
package gelf
46

57
import (
@@ -17,17 +19,17 @@ import (
1719

1820
const name = "gelf"
1921

20-
type GelfLogger struct {
22+
type gelfLogger struct {
2123
writer *gelf.Writer
2224
ctx logger.Context
23-
fields GelfFields
25+
fields gelfFields
2426
}
2527

26-
type GelfFields struct {
28+
type gelfFields struct {
2729
hostname string
28-
containerId string
30+
containerID string
2931
containerName string
30-
imageId string
32+
imageID string
3133
imageName string
3234
command string
3335
tag string
@@ -43,6 +45,9 @@ func init() {
4345
}
4446
}
4547

48+
// New creates a gelf logger using the configuration passed in on the
49+
// context. Supported context configuration variables are
50+
// gelf-address, & gelf-tag.
4651
func New(ctx logger.Context) (logger.Logger, error) {
4752
// parse gelf address
4853
address, err := parseAddress(ctx.Config["gelf-address"])
@@ -59,11 +64,11 @@ func New(ctx logger.Context) (logger.Logger, error) {
5964
// remove trailing slash from container name
6065
containerName := bytes.TrimLeft([]byte(ctx.ContainerName), "/")
6166

62-
fields := GelfFields{
67+
fields := gelfFields{
6368
hostname: hostname,
64-
containerId: ctx.ContainerID,
69+
containerID: ctx.ContainerID,
6570
containerName: string(containerName),
66-
imageId: ctx.ContainerImageID,
71+
imageID: ctx.ContainerImageID,
6772
imageName: ctx.ContainerImageName,
6873
command: ctx.Command(),
6974
tag: ctx.Config["gelf-tag"],
@@ -76,14 +81,14 @@ func New(ctx logger.Context) (logger.Logger, error) {
7681
return nil, fmt.Errorf("gelf: cannot connect to GELF endpoint: %s %v", address, err)
7782
}
7883

79-
return &GelfLogger{
84+
return &gelfLogger{
8085
writer: gelfWriter,
8186
ctx: ctx,
8287
fields: fields,
8388
}, nil
8489
}
8590

86-
func (s *GelfLogger) Log(msg *logger.Message) error {
91+
func (s *gelfLogger) Log(msg *logger.Message) error {
8792
// remove trailing and leading whitespace
8893
short := bytes.TrimSpace([]byte(msg.Line))
8994

@@ -99,9 +104,9 @@ func (s *GelfLogger) Log(msg *logger.Message) error {
99104
TimeUnix: float64(msg.Timestamp.UnixNano()/int64(time.Millisecond)) / 1000.0,
100105
Level: level,
101106
Extra: map[string]interface{}{
102-
"_container_id": s.fields.containerId,
107+
"_container_id": s.fields.containerID,
103108
"_container_name": s.fields.containerName,
104-
"_image_id": s.fields.imageId,
109+
"_image_id": s.fields.imageID,
105110
"_image_name": s.fields.imageName,
106111
"_command": s.fields.command,
107112
"_tag": s.fields.tag,
@@ -115,14 +120,16 @@ func (s *GelfLogger) Log(msg *logger.Message) error {
115120
return nil
116121
}
117122

118-
func (s *GelfLogger) Close() error {
123+
func (s *gelfLogger) Close() error {
119124
return s.writer.Close()
120125
}
121126

122-
func (s *GelfLogger) Name() string {
127+
func (s *gelfLogger) Name() string {
123128
return name
124129
}
125130

131+
// ValidateLogOpt looks for gelf specific log options gelf-address, &
132+
// gelf-tag.
126133
func ValidateLogOpt(cfg map[string]string) error {
127134
for key := range cfg {
128135
switch key {

daemon/logger/journald/journald.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// +build linux
22

3+
// Package journald provides the log driver for forwarding server logs
4+
// to endpoints that receive the systemd format.
35
package journald
46

57
import (
@@ -12,7 +14,7 @@ import (
1214

1315
const name = "journald"
1416

15-
type Journald struct {
17+
type journald struct {
1618
Jmap map[string]string
1719
}
1820

@@ -22,6 +24,9 @@ func init() {
2224
}
2325
}
2426

27+
// New creates a journald logger using the configuration passed in on
28+
// the context. Supported context configuration variables are
29+
// syslog-address, syslog-facility, & syslog-tag.
2530
func New(ctx logger.Context) (logger.Logger, error) {
2631
if !journal.Enabled() {
2732
return nil, fmt.Errorf("journald is not enabled on this host")
@@ -36,20 +41,20 @@ func New(ctx logger.Context) (logger.Logger, error) {
3641
"CONTAINER_ID": ctx.ContainerID[:12],
3742
"CONTAINER_ID_FULL": ctx.ContainerID,
3843
"CONTAINER_NAME": name}
39-
return &Journald{Jmap: jmap}, nil
44+
return &journald{Jmap: jmap}, nil
4045
}
4146

42-
func (s *Journald) Log(msg *logger.Message) error {
47+
func (s *journald) Log(msg *logger.Message) error {
4348
if msg.Source == "stderr" {
4449
return journal.Send(string(msg.Line), journal.PriErr, s.Jmap)
4550
}
4651
return journal.Send(string(msg.Line), journal.PriInfo, s.Jmap)
4752
}
4853

49-
func (s *Journald) Close() error {
54+
func (s *journald) Close() error {
5055
return nil
5156
}
5257

53-
func (s *Journald) Name() string {
58+
func (s *journald) Name() string {
5459
return name
5560
}

0 commit comments

Comments
 (0)