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

Golang loggo.ConfigureLoggers函数代码示例

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

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



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

示例1: newContext

func newContext(fset *flag.FlagSet, args []string) (*context, *params, error) {
	p, err := parseArgs(fset, args)
	if err != nil {
		return nil, nil, err
	}
	if p.debug {
		loggo.ConfigureLoggers("DEBUG")
	}
	ctxt := &context{
		url:       p.url,
		method:    p.method,
		header:    make(http.Header),
		urlValues: make(url.Values),
		form:      make(url.Values),
		jsonObj:   make(map[string]interface{}),
	}
	for _, kv := range p.keyVals {
		if err := ctxt.addKeyVal(p, kv); err != nil {
			return nil, nil, err
		}
	}
	if p.useStdin && (len(ctxt.form) > 0 || len(ctxt.jsonObj) > 0) {
		return nil, nil, errors.New("cannot read body from stdin when form or JSON body is specified")
	}
	if p.basicAuth != "" {
		ctxt.header.Set("Authorization",
			"Basic "+base64.StdEncoding.EncodeToString([]byte(p.basicAuth)))
	}
	if p.json {
		ctxt.header.Set("Content-Type", "application/json")
	}
	return ctxt, p, nil
}
开发者ID:nathj07,项目名称:http,代码行数:33,代码来源:http.go


示例2: setUp

func (t *LoggingSuite) setUp(c *gc.C) {
	if _, ok := loggo.ParseLevel(*logConfig); ok {
		*logConfig = "<root>=" + *logConfig
	}
	err := loggo.ConfigureLoggers(*logConfig)
	c.Assert(err, gc.IsNil)
}
开发者ID:jameinel,项目名称:core,代码行数:7,代码来源:log.go


示例3: main

func main() {
	args := os.Args
	if len(args) > 1 {
		loggo.ConfigureLoggers(args[1])
	} else {
		fmt.Println("Add a parameter to configure the logging:")
		fmt.Println("E.g. \"<root>=INFO;first=TRACE\"")
	}
	fmt.Println("\nCurrent logging levels:")
	fmt.Println(loggo.LoggerInfo())
	fmt.Println("")

	rootLogger.Infof("Start of test.")

	FirstCritical("first critical")
	FirstError("first error")
	FirstWarning("first warning")
	FirstInfo("first info")
	FirstDebug("first debug")
	FirstTrace("first trace")

	loggo.ReplaceDefaultWriter(loggo.NewSimpleWriter(os.Stderr, &loggo.ColorFormatter{}))

	SecondCritical("second critical")
	SecondError("second error")
	SecondWarning("second warning")
	SecondInfo("second info")
	SecondDebug("second debug")
	SecondTrace("second trace")

}
开发者ID:njpatel,项目名称:loggo,代码行数:31,代码来源:main.go


示例4: TestConfigureLoggers

func (s *GlobalSuite) TestConfigureLoggers(c *gc.C) {
	err := loggo.ConfigureLoggers("testing.module=debug")
	c.Assert(err, gc.IsNil)
	expected := "<root>=WARNING;testing.module=DEBUG"
	c.Assert(loggo.DefaultContext().Config().String(), gc.Equals, expected)
	c.Assert(loggo.LoggerInfo(), gc.Equals, expected)
}
开发者ID:juju,项目名称:loggo,代码行数:7,代码来源:global_test.go


示例5: setUp

func (s *LoggingSuite) setUp(c *gc.C) {
	loggo.ResetWriters()
	loggo.ReplaceDefaultWriter(&gocheckWriter{c})
	loggo.ResetLoggers()
	err := loggo.ConfigureLoggers(logConfig)
	c.Assert(err, gc.IsNil)
}
开发者ID:jimmiebtlr,项目名称:testing,代码行数:7,代码来源:log.go


示例6: main

func main() {
	args := os.Args
	if len(args) > 1 {
		loggo.ConfigureLoggers(args[1])
	} else {
		fmt.Println("Add a parameter to configure the logging:")
		fmt.Println("E.g. \"<root>=INFO;first=TRACE\"")
	}
	fmt.Println("\nCurrent logging levels:")
	fmt.Println(loggo.LoggerInfo())
	fmt.Println("")

	rootLogger.Infof("Start of test.")

	FirstCritical("first critical")
	FirstError("first error")
	FirstWarning("first warning")
	FirstInfo("first info")
	FirstTrace("first trace")

	SecondCritical("first critical")
	SecondError("first error")
	SecondWarning("first warning")
	SecondInfo("first info")
	SecondTrace("first trace")

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


示例7: setupLogging

// setupLogging initializes the global logging parameters.
// Log levels can be overriden using the LEMONCRYPT_LOGGING environment variable.
func setupLogging() {
	config := os.Getenv("LEMONCRYPT_LOGGING")
	if config == "" {
		config = "<root>=DEBUG"
	}
	loggo.ConfigureLoggers(config)
	logger.Tracef("logging set up")
}
开发者ID:hoffie,项目名称:lemoncrypt,代码行数:10,代码来源:main.go


示例8: init

func init() {
	// If the environment key is empty, ConfigureLoggers returns nil and does
	// nothing.
	err := loggo.ConfigureLoggers(os.Getenv(osenv.JujuStartupLoggingConfigEnvKey))
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR parsing %s: %s\n\n", osenv.JujuStartupLoggingConfigEnvKey, err)
	}
}
开发者ID:exekias,项目名称:juju,代码行数:8,代码来源:supercommand.go


示例9: setLogging

func (logger *Logger) setLogging() {
	loggingConfig, err := logger.api.LoggingConfig(logger.agentConfig.Tag())
	if err != nil {
		log.Errorf("%v", err)
	} else {
		if loggingConfig != logger.lastConfig {
			log.Debugf("reconfiguring logging from %q to %q", logger.lastConfig, loggingConfig)
			loggo.ResetLoggers()
			if err := loggo.ConfigureLoggers(loggingConfig); err != nil {
				// This shouldn't occur as the loggingConfig should be
				// validated by the original Config before it gets here.
				log.Warningf("configure loggers failed: %v", err)
				// Try to reset to what we had before
				loggo.ConfigureLoggers(logger.lastConfig)
			}
			logger.lastConfig = loggingConfig
		}
	}
}
开发者ID:exekias,项目名称:juju,代码行数:19,代码来源:logger.go


示例10: setUp

func (s *LoggingSuite) setUp(c *gc.C) {
	loggo.ResetLogging()
	// Don't use the default writer for the test logging, which
	// means we can still get logging output from tests that
	// replace the default writer.
	loggo.RegisterWriter(loggo.DefaultWriterName, discardWriter{})
	loggo.RegisterWriter("loggingsuite", &gocheckWriter{c})
	err := loggo.ConfigureLoggers(logConfig)
	c.Assert(err, gc.IsNil)
}
开发者ID:juju,项目名称:testing,代码行数:10,代码来源:log.go


示例11: Start

// Start starts logging using the given Context.
func (log *Log) Start(ctx *Context) error {
	if log.Verbose && log.Quiet {
		return fmt.Errorf(`"verbose" and "quiet" flags clash, please use one or the other, not both`)
	}
	ctx.quiet = log.Quiet
	ctx.verbose = log.Verbose
	if log.Path != "" {
		path := ctx.AbsPath(log.Path)
		target, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			return err
		}
		writer := log.GetLogWriter(target)
		err = loggo.RegisterWriter("logfile", writer)
		if err != nil {
			return err
		}
	}
	level := loggo.WARNING
	if log.ShowLog {
		level = loggo.INFO
	}
	if log.Debug {
		log.ShowLog = true
		level = loggo.DEBUG
		// override quiet or verbose if set, this way all the information goes
		// to the log file.
		ctx.quiet = true
		ctx.verbose = false
	}

	if log.ShowLog {
		// We replace the default writer to use ctx.Stderr rather than os.Stderr.
		writer := log.GetLogWriter(ctx.Stderr)
		_, err := loggo.ReplaceDefaultWriter(writer)
		if err != nil {
			return err
		}
	} else {
		loggo.RemoveWriter("default")
		// Create a simple writer that doesn't show filenames, or timestamps,
		// and only shows warning or above.
		writer := NewWarningWriter(ctx.Stderr)
		err := loggo.RegisterWriter("warning", writer)
		if err != nil {
			return err
		}
	}
	// Set the level on the root logger.
	root := loggo.GetLogger("")
	root.SetLogLevel(level)
	// Override the logging config with specified logging config.
	loggo.ConfigureLoggers(log.Config)
	return nil
}
开发者ID:juju,项目名称:cmd,代码行数:56,代码来源:logging.go


示例12: TestConfigureLoggers

func (*loggerSuite) TestConfigureLoggers(c *gc.C) {
	for i, test := range configureLoggersTests {
		c.Logf("test %d: %q", i, test.spec)
		loggo.ResetLoggers()
		err := loggo.ConfigureLoggers(test.spec)
		c.Check(loggo.LoggerInfo(), gc.Equals, test.info)
		if test.err != "" {
			c.Assert(err, gc.ErrorMatches, test.err)
			continue
		}
		c.Assert(err, gc.IsNil)

		// Test that it's idempotent.
		err = loggo.ConfigureLoggers(test.spec)
		c.Assert(err, gc.IsNil)
		c.Assert(loggo.LoggerInfo(), gc.Equals, test.info)

		// Test that calling ConfigureLoggers with the
		// output of LoggerInfo works too.
		err = loggo.ConfigureLoggers(test.info)
		c.Assert(err, gc.IsNil)
		c.Assert(loggo.LoggerInfo(), gc.Equals, test.info)
	}
}
开发者ID:njpatel,项目名称:loggo,代码行数:24,代码来源:logger_test.go


示例13: TestInitialState

func (s *LoggerSuite) TestInitialState(c *gc.C) {
	config, err := s.State.EnvironConfig()
	c.Assert(err, jc.ErrorIsNil)
	expected := config.LoggingConfig()

	initial := "<root>=DEBUG;wibble=ERROR"
	c.Assert(expected, gc.Not(gc.Equals), initial)

	loggo.ResetLoggers()
	err = loggo.ConfigureLoggers(initial)
	c.Assert(err, jc.ErrorIsNil)

	loggingWorker, _ := s.makeLogger(c)
	defer worker.Stop(loggingWorker)

	s.waitLoggingInfo(c, expected)
}
开发者ID:felicianotech,项目名称:juju,代码行数:17,代码来源:logger_test.go


示例14: setupLogger

func setupLogger() {
	fmt.Println("Setting up logger")
	loggo.ConfigureLoggers("<root>=TRACE")
	oldWriter, _, err := loggo.RemoveWriter("default")
	// err is non-nil if and only if the name isn't found.
	loggo.RegisterWriter("default", oldWriter, loggo.TRACE)
	fmt.Println("Log file: " + viper.GetString("Filename"))

	writer := &lumberjack.Logger{
		Filename:   viper.GetString("Filename"),
		MaxSize:    viper.GetInt("MaxSize"), // megabytes
		MaxBackups: viper.GetInt("MaxBackups"),
		MaxAge:     viper.GetInt("MaxAge"), // days
	}

	newWriter := loggo.NewSimpleWriter(writer, &ClientLogFormatter{})
	err = loggo.RegisterWriter("testfile", newWriter, loggo.TRACE)

	if err != nil {
		fmt.Println("Error registering logger")
	}
}
开发者ID:ritzalam,项目名称:webapi,代码行数:22,代码来源:server.go


示例15: SetUpTest

func (*auditSuite) SetUpTest(c *gc.C) {
	loggo.ResetLoggers()
	loggo.ResetWriters()
	err := loggo.ConfigureLoggers(`<root>=ERROR; audit=INFO`)
	c.Assert(err, jc.ErrorIsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:6,代码来源:audit_test.go


示例16: main

func main() {
	args := os.Args
	if len(args) > 1 {
		loggo.ConfigureLoggers(args[1])
	} else {
		fmt.Println("Add a parameter to configure the logging:")
		fmt.Println("E.g. \"<root>=INFO;first=TRACE\"")
	}
	fmt.Println("\nCurrent logging levels:")
	fmt.Println(loggo.LoggerInfo())
	fmt.Println("")

	rootLogger.Infof("Start of test.")

	FirstCritical("first critical")
	FirstError("first error")
	FirstWarning("first warning")
	FirstInfo("first info")
	FirstTrace("first trace")

	SecondCritical("first critical")
	SecondError("first error")
	SecondWarning("first warning")
	SecondInfo("first info")
	SecondTrace("first trace")

	writer, err := rfw.Open("./myprogram", 0644)
	if err != nil {
		log.Fatalln("Could not open '/var/log/myprogram': ", err)
	}

	log := log.New(writer, "[myprogram] ", log.LstdFlags)
	log.Println("Logging as normal")

	//defaultWriter, _, err := loggo.RemoveWriter("default")

	// err is non-nil if and only if the name isn't found.
	//loggo.RegisterWriter("default", writer, loggo.TRACE)
	newWriter := loggo.NewSimpleWriter(writer, &loggo.DefaultFormatter{})
	err = loggo.RegisterWriter("testfile", newWriter, loggo.TRACE)

	now := time.Now().Nanosecond()
	fmt.Printf("CurrentTime: %d\n", now)
	FirstCritical("first critical")
	FirstError("first error")
	FirstWarning("first warning")
	FirstInfo("first info")
	FirstTrace("first trace")

	SecondCritical("first critical")
	SecondError("first error")
	SecondWarning("first warning")
	SecondInfo("first info")
	SecondTrace("first trace")

	viper.SetConfigName("config")        // name of config file (without extension)
	viper.AddConfigPath("/etc/appname/") // path to look for the config file in
	viper.AddConfigPath("$HOME/")        // call multiple times to add many search paths
	viper.ReadInConfig()                 // Find and read the config file

	title := viper.GetString("title")
	fmt.Printf("TITLE=%s\n", title)
}
开发者ID:ritzalam,项目名称:voiceconfmanager,代码行数:63,代码来源:logging.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang loggo.GetLogger函数代码示例发布时间:2022-05-23
下一篇:
Golang wrench.IsActive函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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