コード例 #1
0
ファイル: log_cli.go プロジェクト: jenareljam/minimega
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
}
コード例 #2
0
ファイル: log_cli.go プロジェクト: cdshann/minimega
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
}
コード例 #3
0
ファイル: log_cli.go プロジェクト: cdshann/minimega
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
}
コード例 #4
0
ファイル: log.go プロジェクト: cdshann/minimega
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)
	}
}