Browse Source

feat: log into file

v1.x.x
dnomd343 2 years ago
parent
commit
7d950c0613
  1. 35
      cmd/xproxy.go

35
cmd/xproxy.go

@ -6,12 +6,13 @@ import (
"XProxy/cmd/process" "XProxy/cmd/process"
"flag" "flag"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io"
"os" "os"
"path" "path"
"strconv" "strconv"
) )
var version = "0.9.3" var version = "0.9.4"
var v4RouteTable = 104 var v4RouteTable = 104
var v6RouteTable = 106 var v6RouteTable = 106
var v4TProxyPort = 7288 var v4TProxyPort = 7288
@ -23,8 +24,9 @@ var goVersion string
var subProcess []*process.Process var subProcess []*process.Process
var assetDir, exposeDir, configFile string var assetDir, exposeDir, configFile string
func logInit(isDebug bool) { func logInit(isDebug bool, logDir string) {
log.SetFormatter(&log.TextFormatter{ log.SetFormatter(&log.TextFormatter{
ForceColors: true,
FullTimestamp: true, FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05", TimestampFormat: "2006-01-02 15:04:05",
}) })
@ -32,13 +34,29 @@ func logInit(isDebug bool) {
if isDebug { if isDebug {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
} }
logFile, err := os.OpenFile(path.Join(logDir, "xproxy.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Errorf("Unable to open log file -> %s", path.Join(logDir, "xproxy.log"))
}
log.SetOutput(io.MultiWriter(os.Stderr, logFile))
} }
func xproxyInit() { func xproxyInit() {
var isDebug = flag.Bool("debug", false, "Enable debug mode") var isDebug = flag.Bool("debug", false, "Enable debug mode")
var configName = flag.String("config", "xproxy.yml", "Config file name") var configName = flag.String("config", "xproxy.yml", "Config file name")
flag.Parse() flag.Parse()
logInit(*isDebug)
exposeDir = "/xproxy" // default folder
if os.Getenv("EXPOSE_DIR") != "" {
exposeDir = os.Getenv("EXPOSE_DIR")
}
logInit(*isDebug, path.Join(exposeDir, "log"))
common.CreateFolder(exposeDir)
assetDir = path.Join(exposeDir, "assets")
configFile = path.Join(exposeDir, *configName)
log.Debugf("Expose folder -> %s", exposeDir)
log.Debugf("Assets folder -> %s", assetDir)
log.Debugf("Config file -> %s", configFile)
if os.Getenv("IPV4_TABLE") != "" { if os.Getenv("IPV4_TABLE") != "" {
v4RouteTable, _ = strconv.Atoi(os.Getenv("IPV4_TABLE")) v4RouteTable, _ = strconv.Atoi(os.Getenv("IPV4_TABLE"))
@ -56,17 +74,6 @@ func xproxyInit() {
log.Debugf("IPv6 Route Table -> %d", v6RouteTable) log.Debugf("IPv6 Route Table -> %d", v6RouteTable)
log.Debugf("IPv4 TProxy Port -> %d", v4TProxyPort) log.Debugf("IPv4 TProxy Port -> %d", v4TProxyPort)
log.Debugf("IPv6 TProxy Port -> %d", v6TProxyPort) log.Debugf("IPv6 TProxy Port -> %d", v6TProxyPort)
exposeDir = "/xproxy" // default folder
if os.Getenv("EXPOSE_DIR") != "" {
exposeDir = os.Getenv("EXPOSE_DIR")
}
common.CreateFolder(exposeDir)
assetDir = path.Join(exposeDir, "assets")
configFile = path.Join(exposeDir, *configName)
log.Debugf("Expose folder -> %s", exposeDir)
log.Debugf("Assets folder -> %s", assetDir)
log.Debugf("Config file -> %s", configFile)
} }
func main() { func main() {

Loading…
Cancel
Save