func cliLogStderr(c *minicli.Command) *minicli.Response { resp := &minicli.Response{Host: hostname} if c.BoolArgs["false"] { // Turn off logging to stderr log.DelLogger("stdio") } else if len(c.BoolArgs) == 0 { // Print true or false depending on whether stderr is enabled _, err := log.GetLevel("stdio") resp.Response = strconv.FormatBool(err == nil) } else if c.BoolArgs["true"] { // Enable stderr logging or adjust the level if already enabled level, _ := log.LevelInt(*f_loglevel) _, err := log.GetLevel("stdio") if err != nil { log.AddLogger("stdio", os.Stderr, level, true) } else { // TODO: Why do this? cliLogLevel updates stdio level whenever // f_loglevel is changed. log.SetLevel("stdio", level) } } return resp }
func cliLogClear(c *minicli.Command) *minicli.Response { resp := &minicli.Response{Host: hostname} // Reset file if explicitly cleared or we're clearing everything if c.BoolArgs["file"] || len(c.BoolArgs) == 0 { if err := stopFileLogger(); err != nil { resp.Error = err.Error() return resp } } // Reset level if explicitly cleared or we're clearing everything if c.BoolArgs["level"] || len(c.BoolArgs) == 0 { // Reset to default level *f_loglevel = "error" log.SetLevel("stdio", log.ERROR) log.SetLevel("file", log.ERROR) } // Reset stderr if explicitly cleared or we're clearing everything if c.BoolArgs["stderr"] || len(c.BoolArgs) == 0 { // Delete logger to stdout log.DelLogger("stdio") } return resp }
// stopFileLogger gets rid of the previous file logger func stopFileLogger() error { log.DelLogger("file") err := logFile.Close() if err != nil { log.Error("error closing log file: %v", err) } else { logFile = nil } return err }
func cliLogClear(c *minicli.Command, resp *minicli.Response) error { // Reset file if explicitly cleared or we're clearing everything if c.BoolArgs["file"] || len(c.BoolArgs) == 0 { if err := stopFileLogger(); err != nil { return err } } // Reset syslog if explicitly cleared or we're clearing everything if c.BoolArgs["syslog"] || len(c.BoolArgs) == 0 { log.DelLogger("syslog") } // Reset level if explicitly cleared or we're clearing everything if c.BoolArgs["level"] || len(c.BoolArgs) == 0 { // Reset to default level *f_loglevel = "error" log.SetLevel("stdio", log.ERROR) log.SetLevel("file", log.ERROR) } // Reset stderr if explicitly cleared or we're clearing everything if c.BoolArgs["stderr"] || len(c.BoolArgs) == 0 { // Delete logger to stdout log.DelLogger("stdio") } if c.BoolArgs["filter"] || len(c.BoolArgs) == 0 { loggers := log.Loggers() for _, l := range loggers { filt, _ := log.Filters(l) for _, f := range filt { log.DelFilter(l, f) } } } return nil }