Skip to content

Commit

Permalink
refact: 对原有文件进行重构
Browse files Browse the repository at this point in the history
1. 增加本地filebeat的压缩包
2. 清理给alpine使用的glibc
3. 改用kingpin重写命令行参数解析
  • Loading branch information
diablowu committed Apr 19, 2018
1 parent 3a6c450 commit ff9f0c4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ _testmain.go
*.prof
bin/
docker-images/pilot
log-pilot
1 change: 1 addition & 0 deletions assets/filebeat/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = filebeat-5.6.9-linux-x86_66
Binary file added assets/filebeat/filebeat.tar.gz
Binary file not shown.
Binary file removed assets/glibc/glibc-2.26-r0.apk
Binary file not shown.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions log-pilot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
log "github.com/Sirupsen/logrus"
"github.com/diablowu/log-pilot/pilot"
"io/ioutil"
"os"
"github.com/alecthomas/kingpin"
)

const DEFUALT_VERSION = "0.1"

func main() {

app := kingpin.New("log-pilot", "collect loggger file from docker host")

app.Version(DEFUALT_VERSION)

// 模板路径
template := app.Flag("template", "Template filepath for fluentd or filebeat.").Short('t').Required().ExistingFile()

// 主机文件系统挂在到容器内的路径,默认为 /host
baseDir := app.Flag("base", "Directory which mount host root.").Default("/host").Short('b').ExistingDir()

// 日志级别
level := app.Flag("log", "Log level").Default("info").Short('v').Enum("panic", "fatal", "error", "warn", "info", "debug")

dry := app.Flag("dryrun", "Dry run.").Short('d').Default("false").Bool()


kingpin.MustParse(app.Parse(os.Args[1:]))

log.SetOutput(os.Stdout)

// 不会error
logLevel, _ := log.ParseLevel(*level)
log.SetLevel(logLevel)

if !*dry {
b, err := ioutil.ReadFile(*template)
if err != nil {
log.Panic(err)
}

log.Fatal(pilot.Run(string(b), *baseDir))
}

}
45 changes: 0 additions & 45 deletions main.go

This file was deleted.

2 changes: 1 addition & 1 deletion pilot/pilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pilot

import (
"github.com/docker/docker/api/types"
log "github.com/sirupsen/logrus"
log "github.com/Sirupsen/logrus"
check "gopkg.in/check.v1"
"os"
"testing"
Expand Down

0 comments on commit ff9f0c4

Please sign in to comment.