• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang jwalterweatherman.SetLogFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/spf13/jwalterweatherman.SetLogFile函数的典型用法代码示例。如果您正苦于以下问题:Golang SetLogFile函数的具体用法?Golang SetLogFile怎么用?Golang SetLogFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SetLogFile函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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)
	}

}
开发者ID:kadel,项目名称:grasshopper,代码行数:27,代码来源:grasshopper.go


示例2: 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)
	}
}
开发者ID:milkywayproject,项目名称:singularity,代码行数:29,代码来源:agent.go


示例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)
}
开发者ID:nwlucas,项目名称:cfg,代码行数:10,代码来源:cfg.go


示例4: 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)
	}
}
开发者ID:navidshaikh,项目名称:grasshopper,代码行数:47,代码来源:grasshopper.go


示例5: Execute

//Execute adds all child commands to the root command GrasshopperCmd and sets flags appropriately.
func Execute() {
	if Verbose {
		jww.SetLogThreshold(jww.LevelTrace)
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

	if DoLog {
		jww.SetLogFile("grasshopper.log")
	}

	jww.DEBUG.Println("Gentlemen, start your engines!!")
	GrasshopperCmd.SuggestionsMinimumDistance = 1

	//add child commands to the root command.
	GrasshopperCmd.AddCommand(versionCmd)

	// FIXME unsupported bashAutogenerateCmd
	// GrasshopperCmd.AddCommand(bashAutogenerateCmd)

	GrasshopperCmd.AddCommand(IndexCmd)

	GrasshopperCmd.AddCommand(FetchCmd)
	GrasshopperCmd.AddCommand(InstallCmd)
	GrasshopperCmd.AddCommand(RunCmd)
	GrasshopperCmd.AddCommand(StopCmd)
	GrasshopperCmd.AddCommand(UninstallCmd)
	GrasshopperCmd.AddCommand(CleanCmd)

	/* FIxME this is nice, but we need a better one!
	manHeader := &cobra.GenManHeader{
		Title:   "grasshopper",
		Section: "1",
	}
	out := new(bytes.Buffer)
	GrasshopperCmd.GenMan(manHeader, out)
	fmt.Println(out.String())
	*/

	if err := GrasshopperCmd.Execute(); err != nil {
		// the err is already logged by Cobra
		os.Exit(-1)
	}

}
开发者ID:vpavlin,项目名称:grasshopper,代码行数:45,代码来源:grasshopper.go


示例6: InitializeConfig


//.........这里部分代码省略.........
		if flagChanged(cmdV.Flags(), "preserveTaxonomyNames") {
			viper.Set("PreserveTaxonomyNames", preserveTaxonomyNames)
		}
		if flagChanged(cmdV.Flags(), "ignoreCache") {
			viper.Set("IgnoreCache", ignoreCache)
		}
		if flagChanged(cmdV.Flags(), "forceSyncStatic") {
			viper.Set("ForceSyncStatic", forceSync)
		}
		if flagChanged(cmdV.Flags(), "noTimes") {
			viper.Set("NoTimes", noTimes)
		}

	}

	if baseURL != "" {
		if !strings.HasSuffix(baseURL, "/") {
			baseURL = baseURL + "/"
		}
		viper.Set("BaseURL", baseURL)
	}

	if !viper.GetBool("RelativeURLs") && viper.GetString("BaseURL") == "" {
		jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
	}

	if theme != "" {
		viper.Set("theme", theme)
	}

	if destination != "" {
		viper.Set("PublishDir", destination)
	}

	if source != "" {
		dir, _ := filepath.Abs(source)
		viper.Set("WorkingDir", dir)
	} else {
		dir, _ := os.Getwd()
		viper.Set("WorkingDir", dir)
	}

	if contentDir != "" {
		viper.Set("ContentDir", contentDir)
	}

	if layoutDir != "" {
		viper.Set("LayoutDir", layoutDir)
	}

	if cacheDir != "" {
		if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
			cacheDir = cacheDir + helpers.FilePathSeparator
		}
		isDir, err := helpers.DirExists(cacheDir, hugofs.SourceFs)
		utils.CheckErr(err)
		if isDir == false {
			mkdir(cacheDir)
		}
		viper.Set("CacheDir", cacheDir)
	} else {
		viper.Set("CacheDir", helpers.GetTempDir("hugo_cache", hugofs.SourceFs))
	}

	if verboseLog || logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

	if verboseLog {
		jww.SetLogThreshold(jww.LevelInfo)
	}

	jww.INFO.Println("Using config file:", viper.ConfigFileUsed())

	themeDir := helpers.GetThemeDir()
	if themeDir != "" {
		if _, err := os.Stat(themeDir); os.IsNotExist(err) {
			return newSystemError("Unable to find theme Directory:", themeDir)
		}
	}

	themeVersionMismatch, minVersion := isThemeVsHugoVersionMismatch()

	if themeVersionMismatch {
		jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
			helpers.HugoReleaseVersion(), minVersion)
	}

	return nil
}
开发者ID:nitoyon,项目名称:hugo,代码行数:101,代码来源:hugo.go


示例7: InitializeConfig

// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() {
	viper.SetConfigFile(CfgFile)
	viper.AddConfigPath(Source)
	err := viper.ReadInConfig()
	if err != nil {
		jww.ERROR.Println("Unable to locate Config file. Perhaps you need to create a new site. Run `hugo help new` for details")
	}

	viper.RegisterAlias("indexes", "taxonomies")

	LoadDefaultSettings()

	if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
		viper.Set("BuildDrafts", Draft)
	}

	if hugoCmdV.PersistentFlags().Lookup("buildFuture").Changed {
		viper.Set("BuildFuture", Future)
	}

	if hugoCmdV.PersistentFlags().Lookup("uglyUrls").Changed {
		viper.Set("UglyURLs", UglyURLs)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableRSS").Changed {
		viper.Set("DisableRSS", DisableRSS)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableSitemap").Changed {
		viper.Set("DisableSitemap", DisableSitemap)
	}

	if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}

	if hugoCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
		viper.Set("PluralizeListTitles", PluralizeListTitles)
	}

	if hugoCmdV.PersistentFlags().Lookup("preserveTaxonomyNames").Changed {
		viper.Set("PreserveTaxonomyNames", PreserveTaxonomyNames)
	}

	if hugoCmdV.PersistentFlags().Lookup("editor").Changed {
		viper.Set("NewContentEditor", Editor)
	}

	if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
		viper.Set("LogFile", LogFile)
	}
	if BaseURL != "" {
		if !strings.HasSuffix(BaseURL, "/") {
			BaseURL = BaseURL + "/"
		}
		viper.Set("BaseURL", BaseURL)
	}

	if !viper.GetBool("RelativeURLs") && viper.GetString("BaseURL") == "" {
		jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
	}

	if Theme != "" {
		viper.Set("theme", Theme)
	}

	if Destination != "" {
		viper.Set("PublishDir", Destination)
	}

	if Source != "" {
		viper.Set("WorkingDir", Source)
	} else {
		dir, _ := os.Getwd()
		viper.Set("WorkingDir", dir)
	}

	if hugoCmdV.PersistentFlags().Lookup("ignoreCache").Changed {
		viper.Set("IgnoreCache", IgnoreCache)
	}

	if CacheDir != "" {
		if helpers.FilePathSeparator != CacheDir[len(CacheDir)-1:] {
			CacheDir = CacheDir + helpers.FilePathSeparator
		}
		isDir, err := helpers.DirExists(CacheDir, hugofs.SourceFs)
		utils.CheckErr(err)
		if isDir == false {
			mkdir(CacheDir)
		}
		viper.Set("CacheDir", CacheDir)
	} else {
		viper.Set("CacheDir", helpers.GetTempDir("hugo_cache", hugofs.SourceFs))
	}

	if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
//.........这里部分代码省略.........
开发者ID:nicrioux,项目名称:hugo,代码行数:101,代码来源:hugo.go


示例8: InitializeConfig


//.........这里部分代码省略.........
		}

	}

	if baseURL != "" {
		if !strings.HasSuffix(baseURL, "/") {
			baseURL = baseURL + "/"
		}
		viper.Set("baseURL", baseURL)
	}

	if !viper.GetBool("relativeURLs") && viper.GetString("baseURL") == "" {
		jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
	}

	if theme != "" {
		viper.Set("theme", theme)
	}

	if destination != "" {
		viper.Set("publishDir", destination)
	}

	var dir string
	if source != "" {
		dir, _ = filepath.Abs(source)
	} else {
		dir, _ = os.Getwd()
	}
	viper.Set("workingDir", dir)

	if contentDir != "" {
		viper.Set("contentDir", contentDir)
	}

	if layoutDir != "" {
		viper.Set("layoutDir", layoutDir)
	}

	if cacheDir != "" {
		viper.Set("cacheDir", cacheDir)
	}

	cacheDir = viper.GetString("cacheDir")
	if cacheDir != "" {
		if helpers.FilePathSeparator != cacheDir[len(cacheDir)-1:] {
			cacheDir = cacheDir + helpers.FilePathSeparator
		}
		isDir, err := helpers.DirExists(cacheDir, hugofs.Source())
		utils.CheckErr(err)
		if isDir == false {
			mkdir(cacheDir)
		}
		viper.Set("cacheDir", cacheDir)
	} else {
		viper.Set("cacheDir", helpers.GetTempDir("hugo_cache", hugofs.Source()))
	}

	if verboseLog || logging || (viper.IsSet("logFile") && viper.GetString("logFile") != "") {
		if viper.IsSet("logFile") && viper.GetString("logFile") != "" {
			jww.SetLogFile(viper.GetString("logFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if quiet {
		jww.SetStdoutThreshold(jww.LevelError)
	} else if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

	if verboseLog {
		jww.SetLogThreshold(jww.LevelInfo)
	}

	jww.INFO.Println("Using config file:", viper.ConfigFileUsed())

	// Init file systems. This may be changed at a later point.
	hugofs.InitDefaultFs()

	themeDir := helpers.GetThemeDir()
	if themeDir != "" {
		if _, err := hugofs.Source().Stat(themeDir); os.IsNotExist(err) {
			return newSystemError("Unable to find theme Directory:", themeDir)
		}
	}

	themeVersionMismatch, minVersion := isThemeVsHugoVersionMismatch()

	if themeVersionMismatch {
		jww.ERROR.Printf("Current theme does not support Hugo version %s. Minimum version required is %s\n",
			helpers.HugoReleaseVersion(), minVersion)
	}

	return nil

}
开发者ID:tubo028,项目名称:hugo,代码行数:101,代码来源:hugo.go


示例9: InitializeConfig


//.........这里部分代码省略.........

	if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
		viper.Set("BuildDrafts", Draft)
	}

	if hugoCmdV.PersistentFlags().Lookup("buildFuture").Changed {
		viper.Set("BuildFuture", Future)
	}

	if hugoCmdV.PersistentFlags().Lookup("uglyUrls").Changed {
		viper.Set("UglyURLs", UglyURLs)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableRSS").Changed {
		viper.Set("DisableRSS", DisableRSS)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableSitemap").Changed {
		viper.Set("DisableSitemap", DisableSitemap)
	}

	if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}

	if hugoCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
		viper.Set("PluralizeListTitles", PluralizeListTitles)
	}

	if hugoCmdV.PersistentFlags().Lookup("editor").Changed {
		viper.Set("NewContentEditor", Editor)
	}

	if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
		viper.Set("LogFile", LogFile)
	}
	if BaseURL != "" {
		if !strings.HasSuffix(BaseURL, "/") {
			BaseURL = BaseURL + "/"
		}
		viper.Set("BaseURL", BaseURL)
	}

	if viper.GetString("BaseURL") == "" {
		jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
	}

	if Theme != "" {
		viper.Set("theme", Theme)
	}

	if Destination != "" {
		viper.Set("PublishDir", Destination)
	}

	if Source != "" {
		viper.Set("WorkingDir", Source)
	} else {
		dir, _ := os.Getwd()
		viper.Set("WorkingDir", dir)
	}

	if hugoCmdV.PersistentFlags().Lookup("ignoreCache").Changed {
		viper.Set("IgnoreCache", IgnoreCache)
	}

	if CacheDir != "" {
		if helpers.FilePathSeparator != CacheDir[len(CacheDir)-1:] {
			CacheDir = CacheDir + helpers.FilePathSeparator
		}
		isDir, err := helpers.DirExists(CacheDir, hugofs.SourceFs)
		utils.CheckErr(err)
		if isDir == false {
			mkdir(CacheDir)
		}
		viper.Set("CacheDir", CacheDir)
	} else {
		viper.Set("CacheDir", helpers.GetTempDir("hugo_cache", hugofs.SourceFs))
	}

	if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

	if VerboseLog {
		jww.SetLogThreshold(jww.LevelInfo)
	}

	jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
}
开发者ID:sun-friderick,项目名称:hugo,代码行数:101,代码来源:hugo.go


示例10: InitializeConfig

func InitializeConfig() {
	viper.SetConfigName(CfgFile)
	viper.AddConfigPath(Source)
	viper.ReadInConfig()

	viper.SetDefault("ContentDir", "content")
	viper.SetDefault("LayoutDir", "layouts")
	viper.SetDefault("StaticDir", "static")
	viper.SetDefault("PublishDir", "public")
	viper.SetDefault("DefaultLayout", "post")
	viper.SetDefault("BuildDrafts", false)
	viper.SetDefault("UglyUrls", false)
	viper.SetDefault("Verbose", false)
	viper.SetDefault("CanonifyUrls", false)
	viper.SetDefault("Indexes", map[string]string{"tag": "tags", "category": "categories"})
	viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0))

	if hugoCmdV.PersistentFlags().Lookup("build-drafts").Changed {
		viper.Set("BuildDrafts", Draft)
	}

	if hugoCmdV.PersistentFlags().Lookup("uglyurls").Changed {
		viper.Set("UglyUrls", UglyUrls)
	}

	if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}

	if hugoCmdV.PersistentFlags().Lookup("logfile").Changed {
		viper.Set("LogFile", LogFile)
	}

	if BaseUrl != "" {
		if !strings.HasSuffix(BaseUrl, "/") {
			BaseUrl = BaseUrl + "/"
		}
		viper.Set("BaseUrl", BaseUrl)
	}
	if Destination != "" {
		viper.Set("PublishDir", Destination)
	}

	if Source != "" {
		viper.Set("WorkingDir", Source)
	} else {
		dir, _ := helpers.FindCWD()
		viper.Set("WorkingDir", dir)
	}

	if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelDebug)
	}

	if VerboseLog {
		jww.SetLogThreshold(jww.LevelDebug)
	}

	jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
}
开发者ID:h0wn0w,项目名称:hugo,代码行数:70,代码来源:hugo.go


示例11: InitializeConfig


//.........这里部分代码省略.........
	viper.SetDefault("ArchetypeDir", "archetypes")
	viper.SetDefault("PublishDir", "public")
	viper.SetDefault("DefaultLayout", "post")
	viper.SetDefault("BuildDrafts", false)
	viper.SetDefault("BuildFuture", false)
	viper.SetDefault("UglyUrls", false)
	viper.SetDefault("Verbose", false)
	viper.SetDefault("CanonifyUrls", false)
	viper.SetDefault("Indexes", map[string]string{"tag": "tags", "category": "categories"})
	viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0))
	viper.SetDefault("Sitemap", hugolib.Sitemap{Priority: -1})
	viper.SetDefault("PygmentsStyle", "monokai")
	viper.SetDefault("DefaultExtension", "html")
	viper.SetDefault("PygmentsUseClasses", false)
	viper.SetDefault("DisableLiveReload", false)
	viper.SetDefault("PluralizeListTitles", true)
	viper.SetDefault("FootnoteAnchorPrefix", "")
	viper.SetDefault("FootnoteReturnLinkContents", "")
	viper.SetDefault("NewContentEditor", "")
	viper.SetDefault("Paginate", 10)
	viper.SetDefault("PaginatePath", "page")
	viper.SetDefault("Blackfriday", new(helpers.Blackfriday))

	if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
		viper.Set("BuildDrafts", Draft)
	}

	if hugoCmdV.PersistentFlags().Lookup("buildFuture").Changed {
		viper.Set("BuildFuture", Future)
	}

	if hugoCmdV.PersistentFlags().Lookup("uglyUrls").Changed {
		viper.Set("UglyUrls", UglyUrls)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableRSS").Changed {
		viper.Set("DisableRSS", DisableRSS)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableSitemap").Changed {
		viper.Set("DisableSitemap", DisableSitemap)
	}

	if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}

	if hugoCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
		viper.Set("PluralizeListTitles", PluralizeListTitles)
	}

	if hugoCmdV.PersistentFlags().Lookup("editor").Changed {
		viper.Set("NewContentEditor", Editor)
	}

	if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
		viper.Set("LogFile", LogFile)
	}
	if BaseUrl != "" {
		if !strings.HasSuffix(BaseUrl, "/") {
			BaseUrl = BaseUrl + "/"
		}
		viper.Set("BaseUrl", BaseUrl)
	}

	if Theme != "" {
		viper.Set("theme", Theme)
	}

	if Destination != "" {
		viper.Set("PublishDir", Destination)
	}

	if Source != "" {
		viper.Set("WorkingDir", Source)
	} else {
		dir, _ := os.Getwd()
		viper.Set("WorkingDir", dir)
	}

	if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

	if VerboseLog {
		jww.SetLogThreshold(jww.LevelInfo)
	}

	jww.INFO.Println("Using config file:", viper.ConfigFileUsed())
}
开发者ID:jaden,项目名称:hugo,代码行数:101,代码来源:hugo.go


示例12:

import (
	"fmt"
	"github.com/howeyc/gopass"
	"github.com/spf13/cobra"
	jww "github.com/spf13/jwalterweatherman"
	"github.com/spf13/viper"
	"os"
)

var mcCmd = &cobra.Command{
	Use: "minecontrol",
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		// This will set up the app

		// Note at this point only WARN or above is actually logged to file, and ERROR or above to console.
		jww.SetLogFile("minecontrol.log")

		if viper.GetBool("verbose") {
			fmt.Println("Enabling verbose output...")
			jww.SetLogThreshold(jww.LevelTrace)
			jww.SetStdoutThreshold(jww.LevelInfo)
		}

		if fvVersion {
			// TODO: Get version numbers dynamically
			fmt.Println(" ")
			fmt.Println("Minecontrol version 0.0.1")
			os.Exit(0)
		}

		if viper.GetString("rcon.password") == "" { // Should detect if we have a password via config or flag, and only execute this if NOT
开发者ID:joshproehl,项目名称:minecontrol,代码行数:31,代码来源:default.go


示例13: InitializeConfig

func InitializeConfig() {
	viper.SetConfigFile(CfgFile)
	viper.AddConfigPath(Source)
	err := viper.ReadInConfig()
	if err != nil {
		jww.ERROR.Println("Config not found... using only defaults, stuff may not work")
	}

	viper.RegisterAlias("taxonomies", "indexes")

	viper.SetDefault("Watch", false)
	viper.SetDefault("MetaDataFormat", "toml")
	viper.SetDefault("DisableRSS", false)
	viper.SetDefault("DisableSitemap", false)
	viper.SetDefault("ContentDir", "content")
	viper.SetDefault("LayoutDir", "layouts")
	viper.SetDefault("StaticDir", "static")
	viper.SetDefault("ArchetypeDir", "archetypes")
	viper.SetDefault("PublishDir", "public")
	viper.SetDefault("DefaultLayout", "post")
	viper.SetDefault("BuildDrafts", false)
	viper.SetDefault("BuildFuture", false)
	viper.SetDefault("UglyUrls", false)
	viper.SetDefault("Verbose", false)
	viper.SetDefault("CanonifyUrls", false)
	viper.SetDefault("Indexes", map[string]string{"tag": "tags", "category": "categories"})
	viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0))
	viper.SetDefault("Sitemap", hugolib.Sitemap{Priority: -1})
	viper.SetDefault("PygmentsStyle", "monokai")
	viper.SetDefault("PygmentsUseClasses", false)
	viper.SetDefault("DisableLiveReload", false)
	viper.SetDefault("PluralizeListTitles", true)

	if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
		viper.Set("BuildDrafts", Draft)
	}

	if hugoCmdV.PersistentFlags().Lookup("buildFuture").Changed {
		viper.Set("BuildFuture", Future)
	}

	if hugoCmdV.PersistentFlags().Lookup("uglyUrls").Changed {
		viper.Set("UglyUrls", UglyUrls)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableRSS").Changed {
		viper.Set("DisableRSS", DisableRSS)
	}

	if hugoCmdV.PersistentFlags().Lookup("disableSitemap").Changed {
		viper.Set("DisableSitemap", DisableSitemap)
	}

	if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}

	if hugoCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
		viper.Set("PluralizeListTitles", PluralizeListTitles)
	}

	if hugoCmdV.PersistentFlags().Lookup("logFile").Changed {
		viper.Set("LogFile", LogFile)
	}
	if BaseUrl != "" {
		if !strings.HasSuffix(BaseUrl, "/") {
			BaseUrl = BaseUrl + "/"
		}
		viper.Set("BaseUrl", BaseUrl)
	}

	if Theme != "" {
		viper.Set("theme", Theme)
	}

	if Destination != "" {
		viper.Set("PublishDir", Destination)
	}

	if Source != "" {
		viper.Set("WorkingDir", Source)
	} else {
		dir, _ := helpers.FindCWD()
		viper.Set("WorkingDir", dir)
	}

	if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

//.........这里部分代码省略.........
开发者ID:juicelink,项目名称:hugo,代码行数:101,代码来源:hugo.go


示例14: main

func main() {
	flgVerbose := flag.Bool("verbose", false, "Output additional debugging information to both STDOUT and the log file")
	flgWriteConf := flag.Bool("writeconf", false, "Write out configuration file to be imported into app_rpt.conf and exit")
	flag.Parse()

	// Note at this point only WARN or above is actually logged to file, and ERROR or above to console.
	jww.SetLogFile("allstarhelper.log")

	if *flgVerbose {
		jww.SetLogThreshold(jww.LevelDebug)
		jww.SetStdoutThreshold(jww.LevelInfo)
	} else {
		// Set default logging verbosity.
		jww.SetLogThreshold(jww.LevelWarn)
		jww.SetStdoutThreshold(jww.LevelError)
	}

	jww.INFO.Println("Starting run at", time.Now().Format("2006-01-02 15:04:05"))

	// Read config file
	appconf, err := getConfigFromFile()
	if err != nil {
		jww.FATAL.Println("Configuration Error:", err)
		os.Exit(0)
	}

	// Before we do anything make sure output directory exists
	err = os.MkdirAll(appconf.Settings.RelativeOutputDir, 0711)
	if err != nil {
		jww.FATAL.Println("could not create output directory. Permissions issue?")
		os.Exit(0)
	}

	if *flgWriteConf {
		// write out the allstarhelper_cmdTree.conf file
		writeOutputConfFileForConfiguration(appconf)
		return
	}

	// Dispatch a thread to handle each of the gauges from the conf file
	gaugeDone := make(chan bool)
	for _, gaugeConf := range appconf.USGSRiver.Gauges {
		jww.DEBUG.Println("Dispatching Handler gauge for conf:", gaugeConf)
		go func(curConf USGSGaugeConf) {
			gaugeId := strconv.Itoa(curConf.Id)
			gaugeRes := getTextForGauge(&curConf, &appconf) // Not copying appConf as we never change it... TODO: Make actually thread safe.
			writeOutputTextFile(appconf.Settings.RelativeOutputDir, gaugeId, gaugeRes)

			// We wrote the txt file for reference, but we're going to go ahead and just output directly to wave now.
			writeOutputAudioFile(appconf.Settings.RelativeOutputDir, gaugeId, gaugeRes, "slt")

			// Now we have to convert the file. Because Asterisk.
			convertOutputAudioFileForAsterisk(appconf.Settings.RelativeOutputDir, gaugeId)

			// Let function that spun up the goroutine know that one of the threads is done
			gaugeDone <- true
		}(gaugeConf)
	}

	// Dispatch a thread to handle each of the wxunderground stations from the conf file
	wxunderStationDone := make(chan bool)
	for _, wxunderStationConf := range appconf.WXUnderground.Stations {
		jww.DEBUG.Println("Dispatching Handler for WXUnderground station for conf:", wxunderStationConf)
		go func(curConf WXUndergroundStationConf) {
			stationRes := getTextForWXUnderStation(&curConf, &appconf) // Not copying appConf as we never change it... TODO: Make actually thread safe.
			writeOutputTextFile(appconf.Settings.RelativeOutputDir, curConf.Id, stationRes)

			// We wrote the txt file for reference, but we're going to go ahead and just output directly to wave now.
			writeOutputAudioFile(appconf.Settings.RelativeOutputDir, curConf.Id, stationRes, "slt")

			// Now we have to convert the file. Because Asterisk.
			convertOutputAudioFileForAsterisk(appconf.Settings.RelativeOutputDir, curConf.Id)

			// Let function that spun up the goroutine know that one of the threads is done
			wxunderStationDone <- true
		}(wxunderStationConf)
	}

	// wait until all gauges and stations are done processing before we exit
	for _ = range appconf.USGSRiver.Gauges {
		<-gaugeDone
	}
	for _ = range appconf.WXUnderground.Stations {
		<-wxunderStationDone
	}

	jww.INFO.Println("Done creating all files, exiting at", time.Now().Format("2006-01-02 15:04:05"))
}
开发者ID:ValleyCamp,项目名称:AllStarHelper,代码行数:88,代码来源:allstarhelper.go


示例15: InitializeConfig

// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() {
	viper.SetConfigFile(CfgFile)
	if Source == "" {
		viper.AddConfigPath(".")
	} else {
		viper.AddConfigPath(Source)
	}
	err := viper.ReadInConfig()
	if err != nil {
		jww.ERROR.Println("Unable to locate Config file.")
	}
	LoadDefaultSettings()

	if hugoCMSCmdV.PersistentFlags().Lookup("disableRSS").Changed {
		viper.Set("DisableRSS", DisableRSS)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("disableSitemap").Changed {
		viper.Set("DisableSitemap", DisableSitemap)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("verbose").Changed {
		viper.Set("Verbose", Verbose)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("pluralizeListTitles").Changed {
		viper.Set("PluralizeListTitles", PluralizeListTitles)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("preserveTaxonomyNames").Changed {
		viper.Set("PreserveTaxonomyNames", PreserveTaxonomyNames)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("editor").Changed {
		viper.Set("NewContentEditor", Editor)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("logFile").Changed {
		viper.Set("LogFile", LogFile)
	}
	if BaseURL != "" {
		if !strings.HasSuffix(BaseURL, "/") {
			BaseURL = BaseURL + "/"
		}
		viper.Set("BaseURL", BaseURL)
	}

	if !viper.GetBool("RelativeURLs") && viper.GetString("BaseURL") == "" {
		jww.ERROR.Println("No 'baseurl' set in configuration or as a flag. Features like page menus will not work without one.")
	}

	if Theme != "" {
		viper.Set("theme", Theme)
	}

	if Destination != "" {
		viper.Set("PublishDir", Destination)
	}

	if Source != "" {
		viper.Set("WorkingDir", Source)
	} else {
		dir, _ := os.Getwd()
		viper.Set("WorkingDir", dir)
	}

	if hugoCMSCmdV.PersistentFlags().Lookup("ignoreCache").Changed {
		viper.Set("IgnoreCache", IgnoreCache)
	}

	if CacheDir != "" {
		if helpers.FilePathSeparator != CacheDir[len(CacheDir)-1:] {
			CacheDir = CacheDir + helpers.FilePathSeparator
		}
		isDir, err := helpers.DirExists(CacheDir, hugofs.SourceFs)
		utils.CheckErr(err)
		if isDir == false {
			mkdir(CacheDir)
		}
		viper.Set("CacheDir", CacheDir)
	} else {
		viper.Set("CacheDir", helpers.GetTempDir("hugo_cache", hugofs.SourceFs))
	}

	if VerboseLog || Logging || (viper.IsSet("LogFile") && viper.GetString("LogFile") != "") {
		if viper.IsSet("LogFile") && viper.GetString("LogFile") != "" {
			jww.SetLogFile(viper.GetString("LogFile"))
		} else {
			jww.UseTempLogFile("hugo")
		}
	} else {
		jww.DiscardLogging()
	}

	if viper.GetBool("verbose") {
		jww.SetStdoutThreshold(jww.LevelInfo)
	}

	if VerboseLog {
//.........这里部分代码省略.........
开发者ID:kiskovacs,项目名称:hugo-cms,代码行数:101,代码来源:theinterface.go


示例16: main

func main() {
	flgVerbose := flag.Bool("verbose", false, "Output additional debugging information to both STDOUT and the log file")
	flgPortNum := flag.Int("port", 8777, "The port to run the HTTP server on.") // 8777 = "WM"
	flgConfigPath := flag.String("conf", "weathermoss-conf.json", "Path to the config JSON file")
	flgVersion := flag.Bool("version", false, "Show version information and quit.")
	flag.Parse()

	if *flgVersion {
		fmt.Println("Weathermoss version", version)
		os.Exit(0)
	}

	// Note at this point only WARN or above is actually logged to file, and ERROR or above to console.
	jww.SetLogFile("weathermoss.log")

	// Set extra logging if the command line flag was set
	if *flgVerbose {
		jww.SetLogThreshold(jww.LevelDebug)
		jww.SetStdoutThreshold(jww.LevelInfo)
		jww.INFO.Println("Verbose debug level set.")
	} else {
		// Set custom default logging verbosity.
		jww.SetLogThreshold(jww.LevelWarn)
		jww.SetStdoutThreshold(jww.LevelError)
	}

	// Read config file
	appconf, err := getConfigFromFile(*flgConfigPath)
	if err != nil {
		jww.FATAL.Println("Configuration Error:", err)
		os.Exit(1)
	}

	// Set up something to handle ctrl-c/kill cleanup!
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		<-c
		fmt.Println("")
		// TODO: Graceful cleanup http's listenAndServe runner?
		// TODO: Any other cleanup needed?
		fmt.Println("Cleaned up and shut down.")
		os.Exit(0)
	}()

	jww.DEBUG.Println(fmt.Sprintf("Connecting to db: %s:%[email protected](%s:%s)/%s?parseTime=true", appconf.DB.Username, appconf.DB.Password, appconf.DB.Host, appconf.DB.Port, appconf.DB.Database))
	db, err := sql.Open("mysql", fmt.Sprintf("%s:%[email protected](%s:%s)/%s?parseTime=true", appconf.DB.Username, appconf.DB.Password, appconf.DB.Host, appconf.DB.Port, appconf.DB.Database))
	if err != nil {
		jww.FATAL.Println("Failed to open database. Error was:", err)
		os.Exit(1)
	}

	if err := db.Ping(); err != nil {
		jww.FATAL.Println("Failed to open database. Error was:", err)
		os.Exit(1)
	}

	// Somewhat arbitrary. TODO: Tune as necessary.
	db.SetMaxIdleConns(500)
	db.SetMaxOpenConns(1000)

	// Set up the HTTP router, followed by all the routes
	router := bone.New()

	// Redirect static resources, and then handle the static resources (/gui/) routes with the static asset file
	router.Handle("/", http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
		http.Redirect(response, request, "gui/", 302)
	}))
	router.Get("/gui/", http.StripPrefix("/gui/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: ""})))

	router.GetFunc("/api", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Welcome to Weathermoss"))
	})

	// Define the API (JSON) routes
	api := api.NewApiHandlers(db)
	router.GetFunc("/api/current", api.Current)
	router.GetFunc("/api/ws", api.WsCombinedHandler)
	router.GetFunc("/api/ws/10min", api.WsTenMinuteHandler)
	router.GetFunc("/api/ws/15sec", api.WsFifteenSecHandler)

	// Start the HTTP server
	fmt.Println("Starting API server on port", *flgPortNum, ". Press Ctrl-C to quit.")
	http.ListenAndServe(fmt.Sprintf(":%d", *flgPortNum), router)
}
开发者ID:ValleyCamp,项目名称:WeatherMoss,代码行数:86,代码来源:weathermoss.go



注:本文中的github.com/spf13/jwalterweatherman.SetLogFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang jwalterweatherman.SetLogThreshold函数代码示例发布时间:2022-05-28
下一篇:
Golang jwalterweatherman.DiscardLogging函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap