Example #1
0
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
}
Example #2
0
func cliLogFilter(c *minicli.Command) *minicli.Response {
	resp := &minicli.Response{Host: hostname}

	if len(c.StringArgs) == 0 {
		var filters []string
		loggers := log.Loggers()

		for _, l := range loggers {
			filt, _ := log.Filters(l)
			for _, f := range filt {
				var found bool
				for _, v := range filters {
					if v == f {
						found = true
					}
				}
				if !found {
					filters = append(filters, f)
				}
			}
		}
		if len(filters) != 0 {
			resp.Response = fmt.Sprintf("%v", filters)
		}
	} else {
		filter := c.StringArgs["filter"]

		loggers := log.Loggers()
		for _, l := range loggers {
			err := log.AddFilter(l, filter)
			if err != nil {
				resp.Error = err.Error()
				return resp
			}
		}
	}

	return resp
}
Example #3
0
func cliLogFilter(c *minicli.Command, resp *minicli.Response) error {
	if len(c.StringArgs) == 0 {
		var filters []string
		loggers := log.Loggers()

		for _, l := range loggers {
			filt, _ := log.Filters(l)
			for _, f := range filt {
				var found bool
				for _, v := range filters {
					if v == f {
						found = true
					}
				}
				if !found {
					filters = append(filters, f)
				}
			}
		}

		if len(filters) != 0 {
			resp.Response = fmt.Sprintf("%v", filters)
		}

		return nil
	}

	filter := c.StringArgs["filter"]

	for _, l := range log.Loggers() {
		err := log.AddFilter(l, filter)
		if err != nil {
			return err
		}
	}

	return nil
}