Skip to content

Commit

Permalink
use logging directly
Browse files Browse the repository at this point in the history
  • Loading branch information
xjdrew committed Dec 19, 2023
1 parent 66909a1 commit e46dccb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 41 deletions.
21 changes: 18 additions & 3 deletions cmd/kone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@ import (
"fmt"
"os"

"github.com/op/go-logging"
"github.com/xjdrew/kone"
. "github.com/xjdrew/kone/internal"
)

var VERSION = "0.2-dev"
var VERSION = "0.3-dev"

var logger = logging.MustGetLogger("kone")

func InitLogger(debug bool) {
format := logging.MustStringFormatter(
`%{color}%{time:06-01-02 15:04:05.000} %{level:.4s} @%{shortfile}%{color:reset} %{message}`,
)
logging.SetFormatter(format)
logging.SetBackend(logging.NewLogBackend(os.Stdout, "", 0))

if debug {
logging.SetLevel(logging.DEBUG, "kone")
} else {
logging.SetLevel(logging.INFO, "kone")
}
}

func main() {
version := flag.Bool("version", false, "Get version info")
Expand All @@ -28,7 +44,6 @@ func main() {
}

InitLogger(*debug)
logger := GetLogger()

configFile := *config
if configFile == "" {
Expand Down
32 changes: 0 additions & 32 deletions internal/logger.go

This file was deleted.

4 changes: 2 additions & 2 deletions one.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"net"
"sync"

. "github.com/xjdrew/kone/internal"
"github.com/op/go-logging"
"github.com/xjdrew/kone/tcpip"
)

var logger = GetLogger()
var logger = logging.MustGetLogger("kone")

type One struct {
// tun ip
Expand Down
5 changes: 3 additions & 2 deletions pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func CreatePattern(rc RuleConfig) Pattern {
proxy := rc.Proxy
pattern := rc.Pattern
schema := strings.ToUpper(rc.Scheme)

switch schema {
case "DOMAIN":
return NewDomainPattern(proxy, pattern)
Expand All @@ -187,18 +188,18 @@ func CreatePattern(rc RuleConfig) Pattern {
fallthrough
case "IP-CIDR6":
if proxy == "DIRECT" { // all IPNet default proxy is DIRECT
logger.Debugf("skip DIRECT rule: %s,%s,%s", rc.Scheme, rc.Pattern, rc.Proxy)
return nil
}
_, ipNet, err := net.ParseCIDR(pattern)
if err == nil {
return NewIPCIDRPattern(proxy, ipNet)
} else {
return nil
}
case "GEOIP":
return NewGEOIPPattern(proxy, pattern)
case "FINAL":
return NewFinalPattern(proxy)
}
logger.Errorf("invalid rule: %s,%s,%s", rc.Scheme, rc.Pattern, rc.Proxy)
return nil
}
2 changes: 0 additions & 2 deletions rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func NewRule(rcs []RuleConfig) *Rule {
for _, rc := range rcs {
if pattern := CreatePattern(rc); pattern != nil {
rule.patterns = append(rule.patterns, pattern)
} else {
logger.Errorf("invalid rule: %s,%s,%s", rc.Scheme, rc.Pattern, rc.Proxy)
}
}
return rule
Expand Down

0 comments on commit e46dccb

Please sign in to comment.