Skip to content

Commit 6a36c3f

Browse files
committed
Add -access-log flag to replace the option in config file
The commandline -access-log flag is useful to write the rc script for this program.
1 parent 1855673 commit 6a36c3f

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

common/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ type MonitorConfig struct {
4747
type Config struct {
4848
Debug bool `mapstructure:"debug"`
4949
Listen string `mapstructure:"listen"`
50-
LogFile string `mapstructure:"log_file"`
5150
MirrorListFile string `mapstructure:"mirror_list"`
5251
Mirrors map[string]*Mirror
5352
MMDBType string `mapstructure:"mmdb_type"`

main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ import (
5454

5555
func main() {
5656
var cfgfile string
57+
var accesslog string
5758
var f_version bool
5859
flag.StringVar(&cfgfile, "config", common.AppName+".toml", "config file")
60+
flag.StringVar(&accesslog, "access-log", "", "web access log file")
5961
flag.BoolVar(&f_version, "version", false, "show version")
6062
flag.Parse()
6163

@@ -75,15 +77,15 @@ func main() {
7577
gin.SetMode(gin.DebugMode)
7678
}
7779

78-
if cfg.LogFile != "" {
79-
f, err := os.OpenFile(cfg.LogFile,
80+
if accesslog != "" {
81+
f, err := os.OpenFile(accesslog,
8082
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
8183
if err != nil {
82-
common.Fatalf("Failed to open logfile: %v\n", err)
84+
common.Fatalf("Failed to open access log: %v\n", err)
8385
}
8486
gin.DisableConsoleColor()
8587
gin.DefaultWriter = io.MultiWriter(f)
86-
common.InfoPrintf("Write log to file: %s\n", cfg.LogFile)
88+
common.InfoPrintf("Write access log to file: %s\n", accesslog)
8789
}
8890

8991
router := gin.Default()

mirrorselect.dev.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ debug = true
77

88
listen = "127.0.0.1:3130"
99

10-
# Uncomment to write log to a file
11-
#log_file = "mirrorselect.log"
12-
1310
# File containing the mirrors (path relative to this file)
1411
mirror_list = "mirrors.dev.toml"
1512

mirrorselect.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
listen = "127.0.0.1:3130"
99

10-
# Uncomment to write log to a file
11-
#log_file = "mirrorselect.log"
12-
1310
# File containing the mirrors (path relative to this file)
1411
mirror_list = "mirrors.toml"
1512

@@ -44,7 +41,7 @@ tls_verify = true
4441

4542
# Executable to invoke when a mirror is down/up
4643
# The command to run is: $notify_exec <mirror_name> <DOWN|UP>
47-
notify_exec = "echo"
44+
#notify_exec = "echo"
4845

4946
# Timeout for executing the above command (unit: second)
5047
exec_timeout = 2

0 commit comments

Comments
 (0)