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 }
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, 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 }
func cliLogLevel(c *minicli.Command) *minicli.Response { resp := &minicli.Response{Host: hostname} if len(c.BoolArgs) == 0 { // Print the level resp.Response = *f_loglevel } else { // Bool args should only have a single key that is the log level for k := range c.BoolArgs { level, err := log.LevelInt(k) if err != nil { log.Fatalln("someone goofed on the patterns") } *f_loglevel = k // forget the error, if they don't exist we shouldn't be setting // their level, so we're fine. log.SetLevel("stdio", level) log.SetLevel("file", level) } } return resp }
func cliLogLevel(c *minicli.Command, resp *minicli.Response) error { if len(c.BoolArgs) == 0 { // Print the level resp.Response = *f_loglevel return nil } // Bool args should only have a single key that is the log level for k := range c.BoolArgs { level, err := log.LevelInt(k) if err != nil { return errors.New("unreachable") } *f_loglevel = k // forget the error, if they don't exist we shouldn't be setting // their level, so we're fine. log.SetLevel("stdio", level) log.SetLevel("file", level) log.SetLevel("syslog", level) } return nil }
func handleLog(c *minicli.Command, r chan<- minicli.Responses) { defer func() { r <- nil }() var level int if c.BoolArgs["fatal"] { level = log.FATAL } else if c.BoolArgs["error"] { level = log.ERROR } else if c.BoolArgs["warn"] { level = log.WARN } else if c.BoolArgs["info"] { level = log.INFO } else if c.BoolArgs["debug"] { level = log.DEBUG } loggers := log.Loggers() for _, l := range loggers { log.SetLevel(l, level) } }