mirror of
https://github.com/foxcpp/maddy.git
synced 2025-04-03 21:27:35 +03:00
cmd/maddy: Allow to set logging target from command line
Useful to redirect log messages generated before config is parsed.
This commit is contained in:
parent
6ba26d1e4e
commit
5b1622ad48
3 changed files with 22 additions and 5 deletions
12
config.go
12
config.go
|
@ -21,8 +21,12 @@ func logOutput(m *config.Map, node *config.Node) (interface{}, error) {
|
|||
return nil, m.MatchErr("can't declare block here")
|
||||
}
|
||||
|
||||
outs := make([]log.FuncLog, 0, len(node.Args))
|
||||
for _, arg := range node.Args {
|
||||
return LogOutputOption(node.Args)
|
||||
}
|
||||
|
||||
func LogOutputOption(args []string) (log.FuncLog, error) {
|
||||
outs := make([]log.FuncLog, 0, len(args))
|
||||
for _, arg := range args {
|
||||
switch arg {
|
||||
case "stderr":
|
||||
outs = append(outs, log.WriterLog(os.Stderr, false))
|
||||
|
@ -35,7 +39,7 @@ func logOutput(m *config.Map, node *config.Node) (interface{}, error) {
|
|||
}
|
||||
outs = append(outs, syslogOut)
|
||||
case "off":
|
||||
if len(node.Args) != 1 {
|
||||
if len(args) != 1 {
|
||||
return nil, errors.New("'off' can't be combined with other log targets")
|
||||
}
|
||||
return nil, nil
|
||||
|
@ -56,5 +60,5 @@ func logOutput(m *config.Map, node *config.Node) (interface{}, error) {
|
|||
}
|
||||
|
||||
func defaultLogOutput() (interface{}, error) {
|
||||
return log.WriterLog(os.Stderr, false), nil
|
||||
return log.DefaultLogger.Out, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue