add debug option

addon-dailer
lqqyt2423 2 years ago
parent 949d1a94cf
commit 57770b464f

@ -3,9 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
rawLog "log"
// slog "log"
"os" "os"
"github.com/lqqyt2423/go-mitmproxy/addon" "github.com/lqqyt2423/go-mitmproxy/addon"
@ -16,6 +14,7 @@ import (
) )
type Config struct { type Config struct {
debug int
version bool version bool
certPath string certPath string
@ -32,6 +31,7 @@ type Config struct {
func loadConfig() *Config { func loadConfig() *Config {
config := new(Config) config := new(Config)
flag.IntVar(&config.debug, "debug", 0, "debug mode: 1 - print debug log, 2 - show debug from")
flag.BoolVar(&config.version, "version", false, "show version") flag.BoolVar(&config.version, "version", false, "show version")
flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr") flag.StringVar(&config.addr, "addr", ":9080", "proxy listen addr")
flag.StringVar(&config.webAddr, "web_addr", ":9081", "web interface listen addr") flag.StringVar(&config.webAddr, "web_addr", ":9081", "web interface listen addr")
@ -48,18 +48,22 @@ func loadConfig() *Config {
func main() { func main() {
config := loadConfig() config := loadConfig()
// for debug if config.debug > 0 {
// slog.SetFlags(slog.LstdFlags | slog.Lshortfile) rawLog.SetFlags(rawLog.LstdFlags | rawLog.Lshortfile)
// log.SetReportCaller(true) log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel) log.SetLevel(log.InfoLevel)
log.SetReportCaller(false) }
if config.debug == 2 {
log.SetReportCaller(true)
}
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
log.SetFormatter(&log.TextFormatter{ log.SetFormatter(&log.TextFormatter{
FullTimestamp: true, FullTimestamp: true,
}) })
opts := &proxy.Options{ opts := &proxy.Options{
Debug: config.debug,
Addr: config.addr, Addr: config.addr,
StreamLargeBodies: 1024 * 1024 * 5, StreamLargeBodies: 1024 * 1024 * 5,
SslInsecure: config.ssl_insecure, SslInsecure: config.ssl_insecure,

@ -17,6 +17,7 @@ import (
var log = _log.WithField("at", "proxy") var log = _log.WithField("at", "proxy")
type Options struct { type Options struct {
Debug int
Addr string Addr string
StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式 StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式
SslInsecure bool SslInsecure bool

Loading…
Cancel
Save