log: show caller's info in verbose mode

This commit is contained in:
nadoo 2019-10-20 17:52:25 +08:00
parent ef8cdfa703
commit 486c455236
6 changed files with 23 additions and 4 deletions

View File

@ -1,6 +1,12 @@
package log package log
import stdlog "log" import (
stdlog "log"
)
func init() {
stdlog.SetFlags(stdlog.LstdFlags | stdlog.Lshortfile)
}
// Func defines a simple log function // Func defines a simple log function
type Func func(f string, v ...interface{}) type Func func(f string, v ...interface{})

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
stdlog "log" stdlog "log"
"os" "os"
"os/signal" "os/signal"
@ -38,7 +39,7 @@ func main() {
// setup a log func // setup a log func
log.F = func(f string, v ...interface{}) { log.F = func(f string, v ...interface{}) {
if conf.Verbose { if conf.Verbose {
stdlog.Printf(f, v...) stdlog.Output(2, fmt.Sprintf(f, v...))
} }
} }

View File

@ -61,7 +61,7 @@ func (s *HTTP) Serve(cc net.Conn) {
if s.pretend { if s.pretend {
fmt.Fprintf(c, "%s 404 Not Found\r\nServer: nginx\r\n\r\n404 Not Found\r\n", req.proto) fmt.Fprintf(c, "%s 404 Not Found\r\nServer: nginx\r\n\r\n404 Not Found\r\n", req.proto)
log.F("[http] accessed by %s as web server", c.RemoteAddr().String()) log.F("[http] %s <-> %s,pretend as web server", c.RemoteAddr().String(), s.Addr())
return return
} }

View File

@ -1,6 +1,7 @@
package tcptun package tcptun
import ( import (
"errors"
"net" "net"
"net/url" "net/url"
"strings" "strings"
@ -26,12 +27,15 @@ func init() {
func NewTCPTun(s string, p proxy.Proxy) (*TCPTun, error) { func NewTCPTun(s string, p proxy.Proxy) (*TCPTun, error) {
u, err := url.Parse(s) u, err := url.Parse(s)
if err != nil { if err != nil {
log.F("parse err: %s", err) log.F("[tcptun] parse err: %s", err)
return nil, err return nil, err
} }
addr := u.Host addr := u.Host
d := strings.Split(addr, "=") d := strings.Split(addr, "=")
if len(d) < 2 {
return nil, errors.New("error in strings.Split")
}
t := &TCPTun{ t := &TCPTun{
proxy: p, proxy: p,

View File

@ -1,6 +1,7 @@
package udptun package udptun
import ( import (
"errors"
"net" "net"
"net/url" "net/url"
"strings" "strings"
@ -34,6 +35,9 @@ func NewUDPTun(s string, p proxy.Proxy) (*UDPTun, error) {
addr := u.Host addr := u.Host
d := strings.Split(addr, "=") d := strings.Split(addr, "=")
if len(d) < 2 {
return nil, errors.New("error in strings.Split")
}
ut := &UDPTun{ ut := &UDPTun{
proxy: p, proxy: p,

View File

@ -1,6 +1,7 @@
package uottun package uottun
import ( import (
"errors"
"io/ioutil" "io/ioutil"
"net" "net"
"net/url" "net/url"
@ -34,6 +35,9 @@ func NewUoTTun(s string, p proxy.Proxy) (*UoTTun, error) {
addr := u.Host addr := u.Host
d := strings.Split(addr, "=") d := strings.Split(addr, "=")
if len(d) < 2 {
return nil, errors.New("error in strings.Split")
}
ut := &UoTTun{ ut := &UoTTun{
proxy: p, proxy: p,