Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace glog with klog #231

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ gohangout --config config.yml

### log

Gohangout use glog.
Gohangout use klog.

use `-v n` to set log level.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ outputs:

### 日志

日志模块使用 github.com/golang/glog , 几个常用参数如下:
日志模块使用 k8s.io/klog/v2 , 几个常用参数如下:

- -logtostderr
日志打印出标准错误
Expand Down
6 changes: 3 additions & 3 deletions codec/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package codec
import (
"plugin"

"github.com/golang/glog"
"k8s.io/klog/v2"
)

type Decoder interface {
Expand All @@ -21,11 +21,11 @@ func NewDecoder(t string) Decoder {
default:
p, err := plugin.Open(t)
if err != nil {
glog.Fatalf("could not open %s: %s", t, err)
klog.Fatalf("could not open %s: %s", t, err)
}
newFunc, err := p.Lookup("New")
if err != nil {
glog.Fatalf("could not find New function in %s: %s", t, err)
klog.Fatalf("could not find New function in %s: %s", t, err)
}
return newFunc.(func() interface{})().(Decoder)
}
Expand Down
8 changes: 4 additions & 4 deletions codec/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/childe/gohangout/simplejson"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type Encoder interface {
Expand All @@ -24,7 +24,7 @@ func NewEncoder(t string) Encoder {
if strings.HasPrefix(t, "format:") {
splited := strings.SplitN(t, ":", 2)
if len(splited) != 2 {
glog.Fatalf("format of `%s` is incorrect", t)
klog.Fatalf("format of `%s` is incorrect", t)
}
format := splited[1]
return NewFormatEncoder(format)
Expand All @@ -33,11 +33,11 @@ func NewEncoder(t string) Encoder {
// try plugin
p, err := plugin.Open(t)
if err != nil {
glog.Fatalf("could not open %s: %s", t, err)
klog.Fatalf("could not open %s: %s", t, err)
}
newFunc, err := p.Lookup("New")
if err != nil {
glog.Fatalf("could not find New function in %s: %s", t, err)
klog.Fatalf("could not find New function in %s: %s", t, err)
}
return newFunc.(func() interface{})().(Encoder)
}
8 changes: 4 additions & 4 deletions condition_filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/oliveagle/jsonpath"

"github.com/childe/gohangout/value_render"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type Condition interface {
Expand Down Expand Up @@ -592,7 +592,7 @@ type BeforeCondition struct {
func NewBeforeCondition(value string) *BeforeCondition {
d, err := time.ParseDuration(value)
if err != nil {
glog.Fatalf("could not parse %s to duration: %s", value, err)
klog.Fatalf("could not parse %s to duration: %s", value, err)
}
return &BeforeCondition{d}
}
Expand All @@ -612,7 +612,7 @@ type AfterCondition struct {
func NewAfterCondition(value string) *AfterCondition {
d, err := time.ParseDuration(value)
if err != nil {
glog.Fatalf("could not parse %s to duration: %s", value, err)
klog.Fatalf("could not parse %s to duration: %s", value, err)
}
return &AfterCondition{d}
}
Expand All @@ -635,7 +635,7 @@ func NewCondition(c string) Condition {
}

if root, err := parseBoolTree(c); err != nil {
glog.Errorf("could not build Condition from `%s` : %s", original_c, err)
klog.Errorf("could not build Condition from `%s` : %s", original_c, err)
return nil
} else {
return root
Expand Down
12 changes: 6 additions & 6 deletions condition_filter/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"strings"

"github.com/golang/glog"
"k8s.io/klog/v2"
)

const (
Expand All @@ -27,13 +27,13 @@ var errorParse = errors.New("parse condition error")
func parseBoolTree(c string) (node *OPNode, err error) {
defer func() {
if r := recover(); r != nil {
glog.Errorf("parse `%s` error at `%s`", c, r)
klog.Errorf("parse `%s` error at `%s`", c, r)
node = nil
err = errorParse
}
}()

//glog.Info(c)
//klog.Info(c)
c = strings.Trim(c, " ")
if c == "" {
return nil, nil
Expand All @@ -43,7 +43,7 @@ func parseBoolTree(c string) (node *OPNode, err error) {
if err != nil {
return nil, err
}
//glog.Info(s2)
//klog.Info(s2)
s := make([]interface{}, 0)

for _, e := range s2 {
Expand Down Expand Up @@ -74,7 +74,7 @@ func parseBoolTree(c string) (node *OPNode, err error) {
}
}

//glog.Info(s)
//klog.Info(s)
if len(s) != 1 {
return nil, errorParse
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func buildRPNStack(c string) ([]interface{}, error) {
if parenthesis == 0 {
condition, err := NewSingleCondition(c[condition_start_pos : i+1])
if err != nil {
glog.Error(err)
klog.Error(err)
panic(c[:i+1])
}
n := &OPNode{
Expand Down
6 changes: 3 additions & 3 deletions filter/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/childe/gohangout/field_setter"
"github.com/childe/gohangout/topology"
"github.com/childe/gohangout/value_render"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type AddFilter struct {
Expand Down Expand Up @@ -32,12 +32,12 @@ func newAddFilter(config map[interface{}]interface{}) topology.Filter {
for f, v := range fieldsValue.(map[interface{}]interface{}) {
fieldSetter := field_setter.NewFieldSetter(f.(string))
if fieldSetter == nil {
glog.Fatalf("could build field setter from %s", f.(string))
klog.Fatalf("could build field setter from %s", f.(string))
}
plugin.fields[fieldSetter] = value_render.GetValueRender(v.(string))
}
} else {
glog.Fatal("fields must be set in add filter plugin")
klog.Fatal("fields must be set in add filter plugin")
}
return plugin
}
Expand Down
10 changes: 5 additions & 5 deletions filter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/childe/gohangout/field_setter"
"github.com/childe/gohangout/topology"
"github.com/childe/gohangout/value_render"
"github.com/golang/glog"
"github.com/spf13/cast"
"k8s.io/klog/v2"
)

type Converter interface {
Expand Down Expand Up @@ -131,7 +131,7 @@ func newConvertFilter(config map[interface{}]interface{}) topology.Filter {
v := vI.(map[interface{}]interface{})
fieldSetter := field_setter.NewFieldSetter(f.(string))
if fieldSetter == nil {
glog.Fatalf("could build field setter from %s", f.(string))
klog.Fatalf("could build field setter from %s", f.(string))
}

to := v["to"].(string)
Expand All @@ -158,7 +158,7 @@ func newConvertFilter(config map[interface{}]interface{}) topology.Filter {
} else if to == "array(float)" {
converter = &ArrayFloatConverter{}
} else {
glog.Fatal("can only convert to int/float/bool/array(int)/array(float)")
klog.Fatal("can only convert to int/float/bool/array(int)/array(float)")
}

plugin.fields[fieldSetter] = ConveterAndRender{
Expand All @@ -170,7 +170,7 @@ func newConvertFilter(config map[interface{}]interface{}) topology.Filter {
}
}
} else {
glog.Fatal("fileds must be set in convert filter plugin")
klog.Fatal("fileds must be set in convert filter plugin")
}
return plugin
}
Expand All @@ -188,7 +188,7 @@ func (plugin *ConvertFilter) Filter(event map[string]interface{}) (map[string]in
if err == nil {
event = fs.SetField(event, v, "", true)
} else {
glog.V(10).Infof("convert error: %s", err)
klog.V(10).Infof("convert error: %s", err)
if conveterAndRender.removeIfFail {
event = fs.SetField(event, nil, "", true)
} else if conveterAndRender.settoIfFail != nil {
Expand Down
8 changes: 4 additions & 4 deletions filter/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/childe/gohangout/field_setter"
"github.com/childe/gohangout/topology"
"github.com/childe/gohangout/value_render"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type DateParser interface {
Expand Down Expand Up @@ -160,7 +160,7 @@ func newDateFilter(config map[interface{}]interface{}) topology.Filter {
if srcValue, ok := config["src"]; ok {
plugin.src = srcValue.(string)
} else {
glog.Fatal("src must be set in date filter plugin")
klog.Fatal("src must be set in date filter plugin")
}
plugin.srcVR = value_render.GetValueRender2(plugin.src)

Expand All @@ -179,7 +179,7 @@ func newDateFilter(config map[interface{}]interface{}) topology.Filter {
if locationI, ok := config["location"]; ok {
location, err = time.LoadLocation(locationI.(string))
if err != nil {
glog.Fatalf("load location error:%s", err)
klog.Fatalf("load location error:%s", err)
}
} else {
location = nil
Expand All @@ -192,7 +192,7 @@ func newDateFilter(config map[interface{}]interface{}) topology.Filter {
plugin.dateParsers = append(plugin.dateParsers, getDateParser(formatI.(string), location, addYear))
}
} else {
glog.Fatal("formats must be set in date filter plugin")
klog.Fatal("formats must be set in date filter plugin")
}

return plugin
Expand Down
8 changes: 4 additions & 4 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"plugin"

"github.com/childe/gohangout/topology"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type BuildFilterFunc func(map[interface{}]interface{}) topology.Filter
Expand All @@ -15,7 +15,7 @@ var registeredFilter map[string]BuildFilterFunc = make(map[string]BuildFilterFun
// Register is used by input plugins to register themselves
func Register(filterType string, bf BuildFilterFunc) {
if _, ok := registeredFilter[filterType]; ok {
glog.Errorf("%s has been registered, ignore %T", filterType, bf)
klog.Errorf("%s has been registered, ignore %T", filterType, bf)
return
}
registeredFilter[filterType] = bf
Expand All @@ -26,12 +26,12 @@ func BuildFilter(filterType string, config map[interface{}]interface{}) topology
if v, ok := registeredFilter[filterType]; ok {
return v(config)
}
glog.Infof("could not load %s filter plugin, try third party plugin", filterType)
klog.Infof("could not load %s filter plugin, try third party plugin", filterType)

pluginPath := filterType
filter, err := getFilterFromPlugin(pluginPath, config)
if err != nil {
glog.Errorf("could not open %s: %s", pluginPath, err)
klog.Errorf("could not open %s: %s", pluginPath, err)
return nil
}
return filter
Expand Down
4 changes: 2 additions & 2 deletions filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"

"github.com/childe/gohangout/topology"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type FiltersFilter struct {
Expand All @@ -29,7 +29,7 @@ func newFiltersFilter(config map[interface{}]interface{}) topology.Filter {

f.filterBoxes = topology.BuildFilterBoxes(_config, BuildFilter)
if len(f.filterBoxes) == 0 {
glog.Fatal("no filters configured in Filters")
klog.Fatal("no filters configured in Filters")
}

for _, b := range f.filterBoxes {
Expand Down
Loading
Loading