Skip to content

Commit 6fa64be

Browse files
authored
Merge pull request #62 from rchicoli/development
new minor release
2 parents ac7f997 + 13147c4 commit 6fa64be

File tree

15 files changed

+91
-76
lines changed

15 files changed

+91
-76
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Before creating a docker container, a healthy instance of Elasticsearch service
120120

121121
### How to test ###
122122

123-
1. Creating and running a container:
123+
1 - Creating and running a container:
124124

125125
```bash
126126
$ docker run --rm -ti \
@@ -162,7 +162,7 @@ $ curl 127.0.0.1:9200/docker/log/_search\?pretty=true
162162
}
163163
```
164164

165-
2. Using grok extension for parsing the log messages:
165+
2 - Using grok extension for parsing the log messages:
166166

167167
```bash
168168
docker run --rm -ti \
@@ -234,7 +234,7 @@ In case you want to save the complete log line and its meta fields, you can set
234234
}
235235
```
236236

237-
3. There are two different ways of adding custom grok patterns.
237+
3 - There are two different ways of adding custom grok patterns.
238238

239239
a. by providing the grok pattern as parameter, e.g.:
240240

@@ -278,7 +278,7 @@ docker run -ti --rm --log-driver rchicoli/docker-log-elasticsearch:development -
278278
rchicoli/webapper
279279
```
280280

281-
4. If grok is not able to parse the log line, then it will still send the unparsed message to Elasticsearch with an error description, e.g.:
281+
4 - If grok is not able to parse the log line, then it will still send the unparsed message to Elasticsearch with an error description, e.g.:
282282

283283
```bash
284284
"grok": {

ROADMAP.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Goals:
1010
- [ ] Create an API for dumping or changing config on the fly
1111
- [ ] Parse partial log messages and merge them, if wished
1212
- [ ] Add performance tests
13+
- [ ] Add metrics
1314

1415
## Docker Log Elasticsearch 1.0.0
1516

@@ -27,5 +28,5 @@ Goals:
2728
- [ ] if queue is full, then write to file
2829
- [ ] if file buffer is full, discard messages
2930
- [ ] Implement Readlog capability
30-
- [ ] Implement grok for parsing docker logs
31+
- [X] Implement grok for parsing docker logs
3132
- [ ] Add CONTRIBUTING file

main.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
6-
74
"github.com/docker/go-plugins-helpers/sdk"
8-
"github.com/sirupsen/logrus"
95

106
"github.com/rchicoli/docker-log-elasticsearch/pkg/docker"
117
)
128

13-
var logLevels = map[string]logrus.Level{
14-
"debug": logrus.DebugLevel,
15-
"info": logrus.InfoLevel,
16-
"warn": logrus.WarnLevel,
17-
"error": logrus.ErrorLevel,
18-
}
19-
209
func main() {
21-
levelVal := os.Getenv("LOG_LEVEL")
22-
if levelVal == "" {
23-
levelVal = "info"
24-
}
25-
if level, exists := logLevels[levelVal]; exists {
26-
logrus.SetLevel(level)
27-
} else {
28-
fmt.Fprintln(os.Stderr, "invalid log level: ", levelVal)
29-
os.Exit(1)
30-
}
3110

3211
h := sdk.NewHandler(`{"Implements": ["LoggingDriver"]}`)
3312
d := docker.NewDriver()

pkg/docker/config.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"strings"
99

1010
"github.com/docker/docker/daemon/logger"
11-
"github.com/pkg/errors"
1211
)
1312

13+
// LogOpt ...
1414
type LogOpt struct {
1515
index string
1616
tzpe string
@@ -26,6 +26,7 @@ type LogOpt struct {
2626
Grok
2727
}
2828

29+
// Grok ...
2930
type Grok struct {
3031
grokPattern string
3132
grokPatternFrom string
@@ -109,33 +110,33 @@ func (c *LogOpt) validateLogOpt(cfg map[string]string) error {
109110
case "daemonName":
110111
case "none", "null", "":
111112
default:
112-
return fmt.Errorf("elasticsearch-fields: invalid parameter %s", v)
113+
return fmt.Errorf("error: invalid parameter elasticsearch-fields: %s", v)
113114
}
114115
}
115116
c.fields = v
116117
case "elasticsearch-sniff":
117118
s, err := strconv.ParseBool(v)
118119
if err != nil {
119-
return errors.Wrapf(err, "error: elasticsearch-sniff: %q", err)
120+
return fmt.Errorf("error: parsing elasticsearch-sniff: %q", err)
120121
}
121122
c.sniff = s
122123
case "elasticsearch-insecure":
123124
s, err := strconv.ParseBool(v)
124125
if err != nil {
125-
return errors.Wrapf(err, "error: elasticsearch-insecure: %q", err)
126+
return fmt.Errorf("error: parsing elasticsearch-insecure: %q", err)
126127
}
127128
c.insecure = s
128129
case "elasticsearch-version":
129130
switch v {
130131
case "1", "2", "5", "6":
131132
c.version = v
132133
default:
133-
return fmt.Errorf("elasticsearch-version: version not support %s", v)
134+
return fmt.Errorf("error: elasticsearch-version not supported: %s", v)
134135
}
135136
case "elasticsearch-timeout":
136137
timeout, err := strconv.Atoi(v)
137138
if err != nil {
138-
return errors.Wrapf(err, "error: elasticsearch-timeout: %q", err)
139+
return fmt.Errorf("error: parsing elasticsearch-timeout: %q", err)
139140
}
140141
c.timeout = timeout
141142
case "grok-pattern":
@@ -149,14 +150,14 @@ func (c *LogOpt) validateLogOpt(cfg map[string]string) error {
149150
case "grok-named-capture":
150151
s, err := strconv.ParseBool(v)
151152
if err != nil {
152-
return errors.Wrapf(err, "error: grok-named-capture: %q", err)
153+
return fmt.Errorf("error: parsing grok-named-capture: %q", err)
153154
}
154155
c.grokNamedCapture = s
155156
// case "tag":
156157
// case "labels":
157158
// case "env":
158159
default:
159-
return fmt.Errorf("unknown log opt %q for elasticsearch log Driver", key)
160+
return fmt.Errorf("error: unknown log-opt: %q", v)
160161
}
161162
}
162163

0 commit comments

Comments
 (0)