change log library

master
dingjun 6 years ago
parent a1cfdbc1d6
commit 804836b7cb

@ -2,9 +2,10 @@ package main
import (
"fmt"
"github.com/go-yaml/yaml"
"io/ioutil"
"testing"
yaml "gopkg.in/yaml.v2"
)
func TestConf(t *testing.T) {
@ -18,8 +19,8 @@ func TestConf(t *testing.T) {
}
fmt.Printf("%+v\n", c)
var testdata = map[string]string{
"www.example.com": "127.0.0.1:8443",
"b.example.com": "127.0.0.1:8541",
"www.example.com": "127.0.0.1:8443 proxy-v2",
"b.example.com": "127.0.0.1:8542",
}
r := forwardRules(c.ForwardRules)
for k, v := range testdata {

@ -1,19 +1,16 @@
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"net"
"strings"
"github.com/go-yaml/yaml"
"github.com/golang/glog"
glog "github.com/fangdingjun/go-log"
proxyproto "github.com/pires/go-proxyproto"
//"crypto/tls"
"flag"
//"log"
"net"
yaml "gopkg.in/yaml.v2"
)
func getSNIServerName(buf []byte) string {
@ -99,6 +96,7 @@ func forward(c net.Conn, data []byte, dst string) {
defer c1.Close()
if proxyProto != 0 {
glog.Debugf("send proxy proto v%d to %s", proxyProto, addr)
hdr.WriteTo(c1)
}
@ -143,12 +141,14 @@ func serve(c net.Conn) {
}
servername := getSNIServerName(buf[:n])
if servername == "" {
glog.Debugf("no sni, send to default")
forward(c, buf[:n], getDefaultDST())
return
}
dst := getDST(c, servername)
if dst == "" {
dst = getDefaultDST()
glog.Debugf("use default dst %s for sni %s", dst, servername)
}
forward(c, buf[:n], dst)
}
@ -157,8 +157,11 @@ var cfg conf
func main() {
var cfgfile string
var logfile string
var loglevel string
flag.StringVar(&cfgfile, "c", "config.yaml", "config file")
flag.Set("logtostderr", "true")
flag.StringVar(&logfile, "log_file", "", "log file")
flag.StringVar(&loglevel, "log_level", "INFO", "log level")
flag.Parse()
data, err := ioutil.ReadFile(cfgfile)
@ -169,6 +172,18 @@ func main() {
glog.Fatal(err)
}
if logfile != "" {
glog.Default.Out = &glog.FixedSizeFileWriter{
MaxCount: 4,
Name: logfile,
MaxSize: 10 * 1024 * 1024,
}
}
if lv, err := glog.ParseLevel(loglevel); err == nil {
glog.Default.Level = lv
}
for _, d := range cfg.Listen {
glog.Infof("listen on :%d", d)
l, err := net.Listen("tcp", fmt.Sprintf(":%d", d))

Loading…
Cancel
Save