-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
main.go
50 lines (39 loc) · 1.19 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
47
48
49
50
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"
_ "github.com/grafana/loki/pkg/build"
)
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
}