本文整理汇总了Golang中github.com/spf13/jwalterweatherman.SetStdoutThreshold函数的典型用法代码示例。如果您正苦于以下问题:Golang SetStdoutThreshold函数的具体用法?Golang SetStdoutThreshold怎么用?Golang SetStdoutThreshold使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetStdoutThreshold函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelInfo)
log.Println("initing config ...")
viper.SetConfigName("zookeeper-helper")
viper.AddConfigPath("./")
viper.AddConfigPath("$HOME/.omega/")
viper.AddConfigPath("/etc/omega/")
viper.SetConfigType("yaml")
if err := viper.ReadInConfig(); err != nil {
log.Panicln("can't read config file:", err)
}
initDefault()
if err := viper.Unmarshal(&pairs); err != nil {
log.Panicln("can't covert to config pairs: ", err)
}
if !pairs.Debugging {
jww.SetLogThreshold(jww.LevelError)
jww.SetStdoutThreshold(jww.LevelError)
}
log.Printf("initialized config pairs: %+v\n", pairs)
}
示例2: init
func init() {
GrasshopperCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
GrasshopperCmd.PersistentFlags().BoolVarP(&Quiet, "quiet", "q", false, "quiet output")
GrasshopperCmd.PersistentFlags().BoolVarP(&Log, "log", "l", true, "write logging output to file")
GrasshopperCmd.PersistentFlags().BoolVarP(&Experimental, "experimental", "x", true, "write experimental output to stdout")
grasshopperCmdV = GrasshopperCmd
viper.BindPFlag("verbose", GrasshopperCmd.PersistentFlags().Lookup("verbose"))
viper.BindPFlag("quiet", GrasshopperCmd.PersistentFlags().Lookup("quiet"))
viper.BindPFlag("log", GrasshopperCmd.PersistentFlags().Lookup("log"))
viper.BindPFlag("experimental", GrasshopperCmd.PersistentFlags().Lookup("experimental"))
if Log {
jww.SetLogFile("grasshopper.log")
}
if Quiet {
jww.SetStdoutThreshold(jww.LevelWarn)
}
if Verbose {
jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelTrace)
}
}
示例3: SetLogFile
func (c *Config) SetLogFile(s string) {
if c.verbose {
jww.SetLogThreshold(jww.LevelDebug)
jww.SetStdoutThreshold(jww.LevelInfo)
} else {
jww.SetLogThreshold(jww.LevelWarn)
jww.SetStdoutThreshold(jww.LevelError)
}
jww.SetLogFile(s)
}
示例4: TestCheckExcuse
func TestCheckExcuse(t *testing.T) {
if testing.Verbose() {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
createEmptyGitRepo(t)
runCheckP(t, "foobar", true, "foo,5")
// Increase on "barfoo" prefix is okay
runCheckP(t, "barfoo", true, "foo,6")
t.Logf("Running check command p: %s w: %t i: %s", "foobar", false, "foo,6")
errCode := Check("foobar", 0, false, "csv", false, strings.NewReader("foo,6"))
if errCode != 50 {
t.Fatalf("Check command passed unexpectedly!")
}
writeExcuse(t, "foobar", "foo", "PROD's down right now, I'll clean foo up later")
runCheckP(t, "foobar", true, "foo,6")
t.Logf("Running check command p: %s w: %t i: %s", "barfoo", false, "foo,7")
errCode = Check("barfoo", 0, false, "csv", false, strings.NewReader("foo,7"))
if errCode != 50 {
t.Fatalf("Check command passed unexpectedly!")
}
}
示例5: parser
func parser(cmd *cobra.Command, args []string) {
if verbose {
jww.SetStdoutThreshold(jww.LevelTrace)
}
opts := MQTT.NewClientOptions().AddBroker(viper.GetString("broker")).SetClientID("parser").SetCleanSession(true)
client := MQTT.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
jww.FATAL.Println(token.Error())
panic(token.Error())
}
defer client.Disconnect(0)
fi, err := os.Stat(viper.GetString("port"))
if err != nil {
jww.FATAL.Println(err)
panic(err)
}
if fi.Mode()&os.ModeType != 0 {
serialLoop(client)
} else {
file, err := os.Open(viper.GetString("port"))
if err != nil {
jww.FATAL.Println(err)
panic(err)
}
defer file.Close()
loop(file, client)
}
}
示例6: TestDump
func TestDump(t *testing.T) {
if testing.Verbose() {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
repo := createEmptyGitRepo(t)
runCheckP(t, "foo", true, "foo,5")
runCommand(t, repo, exec.Command("git", "add", createFile(t, repo, "bar.txt").Name()))
runCommand(t, repo, exec.Command("git", "commit", "-m", "Third Commit"))
runCheckP(t, "foo", true, "foo,4")
dump := bufio.NewScanner(bytes.NewReader(runDump(t, "foo").Bytes()))
dump.Scan()
checkString(t, "foo,4,4", dump.Text())
dump.Scan()
checkString(t, "foo,5,5", dump.Text())
if len(runDump(t, "bar").Bytes()) > 0 {
t.Fatalf("Should be no data under prefix bar")
}
}
示例7: TestCheckWithCheckstyleInput
func TestCheckWithCheckstyleInput(t *testing.T) {
if testing.Verbose() {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
if checkStyleFileErr != nil {
t.Fatalf("Failure opening test data", checkStyleFileErr)
}
createEmptyGitRepo(t)
t.Logf("Running check command p: %s w: %t i: %s", "jshint", true, checkStyleFile)
errCode := Check("jshint", 0, true, "checkstyle", false, checkStyleFile)
if errCode != 0 {
t.Fatalf("Check command failed! Error code: %d", errCode)
}
t.Logf("Running check command p: %s w: %t i: %s", "jshint", false, "errors,951")
errCode = Check("jshint", 0, false, "csv", false, strings.NewReader("errors,951"))
if errCode != 50 {
t.Fatalf("Check command passed unexpectedly!")
}
}
示例8: initConfig
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" { // enable ability to specify config file via flag
viper.SetConfigFile(cfgFile)
}
viper.SetConfigName(".gogetgithubstats") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
viper.AutomaticEnv() // read in environment variables that match
// This is the defaults
viper.SetDefault("Verbose", true)
// If a config file is found, read it in.
err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigParseError); ok {
jww.ERROR.Println(err)
} else {
jww.ERROR.Println("Unable to locate Config file.", err)
}
}
if rootCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}
if rootCmdV.PersistentFlags().Lookup("access-token").Changed {
viper.Set("access-token", accessToken)
}
if viper.GetBool("verbose") {
jww.SetStdoutThreshold(jww.LevelDebug)
}
}
示例9: TestZeroMissing
func TestZeroMissing(t *testing.T) {
if testing.Verbose() {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
createEmptyGitRepo(t)
runCheck(t, true, "foo,5")
t.Logf("Running check command w: %t i: %s", false, "")
errCode := Check("", 0, true, "csv", false, strings.NewReader(""))
if errCode != 50 {
t.Fatalf("Check command passed unexpectedly!")
}
t.Logf("Running check command zero on missing w: %t i: %s", false, "")
errCode = Check("", 0, true, "csv", false, strings.NewReader(""))
if errCode != 0 {
t.Fatalf("Check command failed unexpectedly!")
}
}
示例10: TestCheckSlackPercent
func TestCheckSlackPercent(t *testing.T) {
if testing.Verbose() {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
createEmptyGitRepo(t)
slack := 20.0
usePercents := true
runCheckPS(t, "pageweight", slack, usePercents, true, "gzippedjs,100")
runCheckPS(t, "pageweight", slack, usePercents, false, "gzippedjs,101")
t.Logf("Running check command p: %s w: %t i: %s", "pageweight", false, "gzippedjs,120")
errCode := Check("pageweight", slack, usePercents, false, "csv", false, strings.NewReader("gzippedjs,120"))
if errCode != 0 {
t.Fatalf("Check command failed unexpectedly!")
}
t.Logf("Running check command p: %s w: %t i: %s", "pageweight", false, "gzippedjs,121")
errCode = Check("pageweight", slack, usePercents, false, "csv", false, strings.NewReader("gzippedjs,121"))
if errCode != 50 {
t.Fatalf("Check command passed unexpectedly!")
}
}
示例11: InitializeConfig
// InitializeConfig reads in config file and ENV variables if set.
func InitializeConfig(subCmdVs ...*cobra.Command) error {
viper.SetConfigType("json")
viper.SetConfigName("grasshopper") // name of config file (without extension)
// viper.AddConfigPath("/etc/grasshopper.d/") // path to look for the config file
// viper.AddConfigPath("$HOME/.grasshopper.d") // call multiple times to add many search paths
viper.AddConfigPath(".") // optionally look for config in the working directory
// read config from storage
err := viper.ReadInConfig()
if err != nil {
jww.WARN.Printf("Unable to read Config file. %#v I will fall back to my defaults...", err)
err = nil // we just skip this error
}
// set some sane defaults
viper.SetDefault("Verbose", false)
viper.SetDefault("Quiet", false)
viper.SetDefault("Log", true)
viper.SetDefault("Experimental", true)
if grasshopperCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}
if viper.GetBool("verbose") {
jww.SetStdoutThreshold(jww.LevelTrace)
jww.SetLogThreshold(jww.LevelTrace)
}
return err
}
示例12: InitializeConfig
// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() {
if Quiet {
jww.SetStdoutThreshold(jww.LevelWarn)
}
viper.SetConfigName("grasshopper") // name of config file (without extension)
viper.AddConfigPath("/etc/grasshopper.d/") // path to look for the config file
viper.AddConfigPath("$HOME/.grasshopper.d") // call multiple times to add many search paths
viper.AddConfigPath(".") // optionally look for config in the working directory
// read config from storage
err := viper.ReadInConfig() // FIXME
if err != nil {
jww.WARN.Println("Unable to locate Config file. I will fall back to my defaults...")
}
// default settings
viper.SetDefault("Verbose", false)
viper.SetDefault("Quiet", false)
viper.SetDefault("DryRun", false)
viper.SetDefault("DoLog", true)
viper.SetDefault("Experimental", true)
// bind config to command flags
if grasshopperCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}
if grasshopperCmdV.PersistentFlags().Lookup("quiet").Changed {
viper.Set("Quiet", Quiet)
}
if grasshopperCmdV.PersistentFlags().Lookup("log").Changed {
viper.Set("DoLog", DoLog)
}
if grasshopperCmdV.PersistentFlags().Lookup("experimental").Changed {
viper.Set("Experimental", Experimental)
}
if DoLog {
jww.SetLogFile("grasshopper.log")
}
if Verbose {
jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelTrace)
}
}
示例13: initLogging
// initialize logging...
func initLogging(configuration *Configuration) {
log.SetLogFile(configuration.LogFile)
threshold := configuration.LogThreshold
if threshold == "TRACE" {
log.SetLogThreshold(log.LevelTrace)
log.SetStdoutThreshold(log.LevelTrace)
} else if threshold == "DEBUG" {
log.SetLogThreshold(log.LevelDebug)
log.SetStdoutThreshold(log.LevelDebug)
} else if threshold == "INFO" {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
} else if threshold == "WARN" {
log.SetLogThreshold(log.LevelWarn)
log.SetStdoutThreshold(log.LevelWarn)
} else if threshold == "ERROR" {
log.SetLogThreshold(log.LevelError)
log.SetStdoutThreshold(log.LevelError)
} else if threshold == "CRITICAL" {
log.SetLogThreshold(log.LevelCritical)
log.SetStdoutThreshold(log.LevelCritical)
} else if threshold == "FATAL" {
log.SetLogThreshold(log.LevelFatal)
log.SetStdoutThreshold(log.LevelFatal)
}
}
示例14: FetchFunction
//FetchFunction is the function that downloads all Nulecule container images
func FetchFunction(cmd *cobra.Command, args []string) {
if Verbose {
jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelInfo)
}
if len(args) < 1 {
cmd.Usage()
jww.FATAL.Println("URL to be fetched is missing")
}
jww.INFO.Printf("fetching: %q", strings.Join(args, " "))
}
示例15: printIndexList
func printIndexList(cmd *cobra.Command, args []string) {
InitializeConfig()
if Verbose {
jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelInfo)
}
nuleculeLibraryIndexZip, err := getNuleculeLibraryIndexfromGithubAsZIP()
if err != nil {
jww.FATAL.Println(err)
return
}
w := new(tabwriter.Writer)
w.Init(os.Stdout, 26, 8, 2, '\t', 0)
fmt.Fprintln(w, "This is the Nulecule Library Index")
fmt.Fprintln(w, "Application Name\tAppID\tVersion")
// Iterate through the files in the archive
for _, item := range nuleculeLibraryIndexZip.File {
if item.FileInfo().IsDir() {
continue
}
// if the file is a Nulecule, getit!
if item.FileInfo().Name() == "Nulecule" {
jww.DEBUG.Printf("Found a Nulecule, size of it's description is %d\n", item.FileInfo().Size())
rc, err := item.Open()
if err != nil {
jww.FATAL.Println(err)
return
}
defer rc.Close()
// get the Nulecules content
nuci, parseError := nulecule.Parse(rc)
if parseError != nil {
jww.INFO.Println(parseError, " This may be due to unsupported (by Grasshopper) artifact inheritance.")
continue
}
fmt.Fprintf(w, "%s\t%s\t%s\n", nuci.Metadata.Name, nuci.AppID, nuci.Metadata.AppVersion)
}
w.Flush()
}
}