You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
973 B
Go

package main
import (
"flag"
"io/ioutil"
"os"
"os/signal"
"syscall"
log "github.com/fangdingjun/go-log/v5"
"gopkg.in/yaml.v2"
)
func main() {
var cfgfile string
var logfile string
var loglevel string
flag.StringVar(&cfgfile, "c", "config.yaml", "config file")
flag.StringVar(&logfile, "log_file", "", "log file")
flag.StringVar(&loglevel, "log_level", "INFO", "log level")
flag.Parse()
data, err := ioutil.ReadFile(cfgfile)
if err != nil {
log.Fatal(err)
}
var cfg conf
if err := yaml.Unmarshal(data, &cfg); err != nil {
log.Fatal(err)
}
if logfile != "" {
log.Default.Out = &log.FixedSizeFileWriter{
MaxCount: 4,
Name: logfile,
MaxSize: 10 * 1024 * 1024,
}
}
if lv, err := log.ParseLevel(loglevel); err == nil {
log.Default.Level = lv
}
makeServers(cfg)
ch := make(chan os.Signal, 2)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
select {
case s := <-ch:
log.Printf("received signal %s, exit.", s)
}
}