fixed null pointer dereference in accessing the log mask configuration value
This commit is contained in:
parent
2c7c08c22f
commit
db48395b13
@ -152,9 +152,6 @@ func tls_string_to_client_auth_type(str string) tls.ClientAuthType {
|
||||
func log_strings_to_mask(str []string) hodu.LogMask {
|
||||
|
||||
var mask hodu.LogMask
|
||||
var all hodu.LogMask
|
||||
|
||||
all = hodu.LogMask(hodu.LOG_DEBUG | hodu.LOG_INFO | hodu.LOG_WARN | hodu.LOG_ERROR)
|
||||
|
||||
if len(str) > 0 {
|
||||
var name string
|
||||
@ -164,10 +161,10 @@ func log_strings_to_mask(str []string) hodu.LogMask {
|
||||
|
||||
switch name {
|
||||
case "all":
|
||||
mask = all
|
||||
mask = hodu.LOG_ALL
|
||||
|
||||
case "none":
|
||||
mask = hodu.LogMask(0)
|
||||
mask = hodu.LOG_NONE
|
||||
|
||||
case "debug":
|
||||
mask |= hodu.LogMask(hodu.LOG_DEBUG)
|
||||
@ -181,7 +178,7 @@ func log_strings_to_mask(str []string) hodu.LogMask {
|
||||
}
|
||||
} else {
|
||||
// if not specified, log messages of all levels
|
||||
mask = all
|
||||
mask = hodu.LOG_ALL
|
||||
}
|
||||
|
||||
return mask
|
||||
|
13
cmd/main.go
13
cmd/main.go
@ -149,8 +149,11 @@ func server_main(ctl_addrs []string, rpc_addrs []string, cfg *ServerConfig) erro
|
||||
var rpctlscfg *tls.Config
|
||||
var ctl_prefix string
|
||||
var logger *AppLogger
|
||||
var log_mask hodu.LogMask
|
||||
var err error
|
||||
|
||||
log_mask = hodu.LOG_ALL
|
||||
|
||||
if cfg != nil {
|
||||
ctltlscfg, err = make_tls_server_config(&cfg.CTL.TLS)
|
||||
if err != nil {
|
||||
@ -170,6 +173,7 @@ func server_main(ctl_addrs []string, rpc_addrs []string, cfg *ServerConfig) erro
|
||||
}
|
||||
|
||||
ctl_prefix = cfg.CTL.Service.Prefix
|
||||
log_mask = log_strings_to_mask(cfg.APP.LogMask)
|
||||
}
|
||||
|
||||
if len(rpc_addrs) <= 0 {
|
||||
@ -177,7 +181,7 @@ func server_main(ctl_addrs []string, rpc_addrs []string, cfg *ServerConfig) erro
|
||||
}
|
||||
|
||||
// TODO: Change out field depending on cfg.APP.LogFile
|
||||
logger = &AppLogger{id: "server", out: os.Stderr, mask: log_strings_to_mask(cfg.APP.LogMask)}
|
||||
logger = &AppLogger{id: "server", out: os.Stderr, mask: log_mask}
|
||||
s, err = hodu.NewServer(
|
||||
context.Background(),
|
||||
ctl_addrs,
|
||||
@ -207,8 +211,10 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
|
||||
var ctl_prefix string
|
||||
var cc hodu.ClientConfig
|
||||
var logger *AppLogger
|
||||
var log_mask hodu.LogMask
|
||||
var err error
|
||||
|
||||
log_mask = hodu.LOG_ALL
|
||||
if cfg != nil {
|
||||
ctltlscfg, err = make_tls_server_config(&cfg.CTL.TLS)
|
||||
if err != nil {
|
||||
@ -225,6 +231,7 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
|
||||
|
||||
cc.ServerSeedTimeout = cfg.RPC.Endpoint.SeedTimeout
|
||||
cc.ServerAuthority = cfg.RPC.Endpoint.Authority
|
||||
log_mask = log_strings_to_mask(cfg.APP.LogMask)
|
||||
}
|
||||
|
||||
if len(rpc_addrs) <= 0 {
|
||||
@ -235,7 +242,7 @@ func client_main(ctl_addrs []string, rpc_addrs []string, peer_addrs []string, cf
|
||||
cc.PeerAddrs = peer_addrs
|
||||
|
||||
// TODO: Change out field depending on cfg.APP.LogFile
|
||||
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_strings_to_mask(cfg.APP.LogMask)}
|
||||
logger = &AppLogger{id: "client", out: os.Stderr, mask: log_mask}
|
||||
c = hodu.NewClient(
|
||||
context.Background(),
|
||||
ctl_addrs,
|
||||
@ -280,6 +287,7 @@ func main() {
|
||||
cfgfile = v
|
||||
return nil
|
||||
})
|
||||
// TODO: add a command line option to specify log file and mask.
|
||||
flgs.SetOutput(io.Discard) // prevent usage output
|
||||
err = flgs.Parse(os.Args[2:])
|
||||
if err != nil {
|
||||
@ -324,6 +332,7 @@ func main() {
|
||||
cfgfile = v
|
||||
return nil
|
||||
})
|
||||
// TODO: add a command line option to specify log file and mask.
|
||||
flgs.SetOutput(io.Discard)
|
||||
err = flgs.Parse(os.Args[2:])
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user