forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (38 loc) · 1.15 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"os"
"github.com/cortexproject/cortex/pkg/util"
"github.com/docker/go-plugins-helpers/sdk"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/common/version"
"github.com/weaveworks/common/logging"
)
const socketAddress = "/run/docker/plugins/loki.sock"
var logLevel logging.Level
func main() {
levelVal := os.Getenv("LOG_LEVEL")
if levelVal == "" {
levelVal = "info"
}
if err := logLevel.Set(levelVal); err != nil {
fmt.Fprintln(os.Stdout, "invalid log level: ", levelVal)
os.Exit(1)
}
logger := newLogger(logLevel)
level.Info(util.Logger).Log("msg", "Starting docker-plugin", "version", version.Info())
h := sdk.NewHandler(`{"Implements": ["LoggingDriver"]}`)
handlers(&h, newDriver(logger))
if err := h.ServeUnix(socketAddress, 0); err != nil {
panic(err)
}
}
func newLogger(lvl logging.Level) log.Logger {
// plugin logs must be stdout to appear.
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
logger = level.NewFilter(logger, lvl.Gokit)
logger = log.With(logger, "ts", log.DefaultTimestampUTC)
logger = log.With(logger, "caller", log.Caller(3))
return logger
}