当前位置: 首页>>代码示例>>Golang>>正文


Golang loggo.GetLogger函数代码示例

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


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

示例1: TestLog

func (*logSuite) TestLog(c *gc.C) {
	logger := loggo.GetLogger("test")
	jujuLogger := loggo.GetLogger("juju")
	logConfig = "<root>=DEBUG;juju=TRACE"

	c.Assert(logger.EffectiveLogLevel(), gc.Equals, loggo.WARNING)
	var suite LoggingSuite
	suite.SetUpSuite(c)

	c.Assert(logger.EffectiveLogLevel(), gc.Equals, loggo.DEBUG)
	c.Assert(jujuLogger.EffectiveLogLevel(), gc.Equals, loggo.TRACE)

	logger.Debugf("message 1")
	logger.Tracef("message 2")
	jujuLogger.Tracef("message 3")

	c.Assert(c.GetTestLog(), gc.Matches,
		".*DEBUG test message 1\n"+
			".*TRACE juju message 3\n",
	)
	suite.TearDownSuite(c)
	logger.Debugf("message 1")
	logger.Tracef("message 2")
	jujuLogger.Tracef("message 3")

	c.Assert(c.GetTestLog(), gc.Matches,
		".*DEBUG test message 1\n"+
			".*TRACE juju message 3\n",
	)
	c.Assert(logger.EffectiveLogLevel(), gc.Equals, loggo.WARNING)
	c.Assert(jujuLogger.EffectiveLogLevel(), gc.Equals, loggo.WARNING)
}
开发者ID:fabricematrat,项目名称:testing,代码行数:32,代码来源:log_test.go

示例2: TestModuleLowered

func (*GlobalSuite) TestModuleLowered(c *gc.C) {
	logger1 := loggo.GetLogger("TESTING.MODULE")
	logger2 := loggo.GetLogger("Testing")

	c.Assert(logger1.Name(), gc.Equals, "testing.module")
	c.Assert(logger2.Name(), gc.Equals, "testing")
}
开发者ID:juju,项目名称:loggo,代码行数:7,代码来源:global_test.go

示例3: readConfig

func (c *Command) readConfig() *Config {
	var cmdConfig Config
	cmdFlags := flag.NewFlagSet("agent", flag.ContinueOnError)
	cmdFlags.Usage = func() { c.Ui.Output(c.Help()) }
	cmdFlags.StringVar(&cmdConfig.LocalUrl, "localurl", "tcp://localhost:1883", "cloud url to connect to")
	cmdFlags.StringVar(&cmdConfig.SerialNo, "serial", "unknown", "the serial number of the device")
	cmdFlags.BoolVar(&cmdConfig.Debug, "debug", false, "enable debug")
	cmdFlags.BoolVar(&cmdConfig.Trace, "trace", false, "enable trace")
	cmdFlags.IntVar(&cmdConfig.StatusTimer, "status", 30, "time in seconds between status messages")

	if err := cmdFlags.Parse(c.args); err != nil {
		return nil
	}

	//if cmdFLags.
	if cmdConfig.Debug {
		loggo.GetLogger("").SetLogLevel(loggo.DEBUG)
	} else {
		loggo.GetLogger("").SetLogLevel(loggo.INFO)
	}

	if cmdConfig.Trace {
		// enable low-level tracing on mqtt library
		for _, l := range []**log.Logger{&mqtt.DEBUG, &mqtt.ERROR, &mqtt.CRITICAL, &mqtt.WARN} {
			*l = log.New(os.Stderr, "", 0)
		}
	}

	return &cmdConfig
}
开发者ID:ninjasphere,项目名称:mqtt-bridgeify,代码行数:30,代码来源:command.go

示例4: TestLevelsSharedForSameModule

func (*GlobalSuite) TestLevelsSharedForSameModule(c *gc.C) {
	logger1 := loggo.GetLogger("testing.module")
	logger2 := loggo.GetLogger("testing.module")

	logger1.SetLogLevel(loggo.INFO)
	c.Assert(logger1.IsInfoEnabled(), gc.Equals, true)
	c.Assert(logger2.IsInfoEnabled(), gc.Equals, true)
}
开发者ID:juju,项目名称:loggo,代码行数:8,代码来源:global_test.go

示例5: setupLoggo

func setupLoggo(debug bool) {
	// apply flags
	if debug {
		loggo.GetLogger(*logName).SetLogLevel(loggo.DEBUG)
	} else {
		loggo.GetLogger(*logName).SetLogLevel(loggo.INFO)
	}
}
开发者ID:paulcull,项目名称:mqtt-webbrick,代码行数:8,代码来源:main.go

示例6: init

func init() {
	var level loggo.Level
	useSyslog := true

	if _, logErr := os.Stat("/dev/log"); logErr != nil {
		useSyslog = false
	}

	// snappy doesn't support syslog, so when we detect a snappy app we will disable syslog
	// and leave the default stderr logger (which works because snappy uses systemd)
	// eventually, the error case of syslog not existing should be exposed by loggo-syslog instead

	if os.Getenv("SNAPP_APP_PATH") != "" {
		useSyslog = false
	}

	debug := os.Getenv("DEBUG")
	if debug != "" {
		switch debug {
		case "INFO":
			level = loggo.INFO
		case "WARNING":
			level = loggo.WARNING
		case "ERROR":
			level = loggo.ERROR
		default:
			level = loggo.DEBUG
		}
	} else {
		// set the default level
		level = loggo.INFO

		// kill stderr
		log.SetOutput(ioutil.Discard)

		if useSyslog {
			// remove the default writer
			loggo.RemoveWriter("default")
		}
	}
	loggo.GetLogger("").SetLogLevel(level)
	if level != loggo.INFO {
		loggo.GetLogger("").Infof("Root logger initialized at level %v", level)
	}
	// setup the syslog writer
	if useSyslog {
		loggo.RegisterWriter("syslog", lsyslog.NewDefaultSyslogWriter(loggo.TRACE, path.Base(os.Args[0]), "LOCAL7"), loggo.TRACE)
	}

}
开发者ID:ninjasphere,项目名称:go-ninja,代码行数:50,代码来源:logger.go

示例7: TestLocationCapture

func (*loggerSuite) TestLocationCapture(c *gc.C) {
	writer := &loggo.TestWriter{}
	loggo.ReplaceDefaultWriter(writer)
	logger := loggo.GetLogger("test")
	logger.SetLogLevel(loggo.TRACE)

	logger.Criticalf("critical message") //tag critical-location
	logger.Errorf("error message")       //tag error-location
	logger.Warningf("warning message")   //tag warning-location
	logger.Infof("info message")         //tag info-location
	logger.Debugf("debug message")       //tag debug-location
	logger.Tracef("trace message")       //tag trace-location

	log := writer.Log()
	tags := []string{
		"critical-location",
		"error-location",
		"warning-location",
		"info-location",
		"debug-location",
		"trace-location",
	}
	c.Assert(log, gc.HasLen, len(tags))
	for x := range tags {
		assertLocation(c, log[x], tags[x])
	}

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

示例8: TestBadCall

func (*rpcSuite) TestBadCall(c *gc.C) {
	loggo.GetLogger("juju.rpc").SetLogLevel(loggo.TRACE)
	root := &Root{
		simple: make(map[string]*SimpleMethods),
	}
	a0 := &SimpleMethods{root: root, id: "a0"}
	root.simple["a0"] = a0
	client, srvDone, serverNotifier := newRPCClientServer(c, root, nil, false)
	defer closeClient(c, client, srvDone)

	testBadCall(c, client, serverNotifier,
		rpc.Request{"BadSomething", 0, "a0", "No"},
		`unknown object type "BadSomething"`,
		rpc.CodeNotImplemented,
		false,
	)
	testBadCall(c, client, serverNotifier,
		rpc.Request{"SimpleMethods", 0, "xx", "No"},
		"no such request - method SimpleMethods.No is not implemented",
		rpc.CodeNotImplemented,
		false,
	)
	testBadCall(c, client, serverNotifier,
		rpc.Request{"SimpleMethods", 0, "xx", "Call0r0"},
		`unknown SimpleMethods id`,
		"",
		true,
	)
}
开发者ID:bac,项目名称:juju,代码行数:29,代码来源:rpc_test.go

示例9: TestConfiguringCustomLogger

func TestConfiguringCustomLogger(t *testing.T) {

	l1 := log.New(os.Stdout, "", log.Lshortfile)

	l2 := &LoggoWrapper{loggo.GetLogger("test")}

	var testCases = []struct {
		config Configuration
		notify bool
		msg    string
	}{
		{
			config: Configuration{ReleaseStage: "production", NotifyReleaseStages: []string{"development", "production"}, Logger: l1},
			notify: true,
			msg:    "Failed to assign log.Logger",
		},
		{
			config: Configuration{ReleaseStage: "production", NotifyReleaseStages: []string{"development", "production"}, Logger: l2},
			notify: true,
			msg:    "Failed to assign LoggoWrapper",
		},
	}

	for _, testCase := range testCases {
		Configure(testCase.config)

		// call printf just to illustrate it is present as the compiler does most of the hard work
		testCase.config.Logger.Printf("hello %s", "bugsnag")

	}
}
开发者ID:bfloriang,项目名称:dock2box,代码行数:31,代码来源:configuration_test.go

示例10: SetUpTest

func (s *modelManagerStateSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	s.authoriser = apiservertesting.FakeAuthorizer{
		Tag: s.AdminUserTag(c),
	}
	loggo.GetLogger("juju.apiserver.modelmanager").SetLogLevel(loggo.TRACE)
}
开发者ID:kat-co,项目名称:juju,代码行数:7,代码来源:modelmanager_test.go

示例11: SetUpTest

func (s *writerSuite) SetUpTest(c *gc.C) {
	loggo.ResetLoggers()
	loggo.RemoveWriter("default")
	s.logger = loggo.GetLogger("test.writer")
	// Make it so the logger itself writes all messages.
	s.logger.SetLogLevel(loggo.TRACE)
}
开发者ID:njpatel,项目名称:loggo,代码行数:7,代码来源:writer_test.go

示例12: SetUpTest

func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) {
	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
	s.AddCleanup(dummy.Reset)
	cfg, err := config.New(config.UseDefaults, map[string]interface{}{
		"name":            "erewhemos",
		"type":            "dummy",
		"uuid":            coretesting.ModelTag.Id(),
		"controller-uuid": coretesting.ControllerTag.Id(),
		"conroller":       true,
	})
	c.Assert(err, jc.ErrorIsNil)
	env, err := bootstrap.Prepare(
		modelcmd.BootstrapContextNoVerify(coretesting.Context(c)),
		jujuclienttesting.NewMemStore(),
		bootstrap.PrepareParams{
			ControllerConfig: coretesting.FakeControllerConfig(),
			ControllerName:   cfg.Name(),
			ModelConfig:      cfg.AllAttrs(),
			Cloud:            dummy.SampleCloudSpec(),
			AdminSecret:      "admin-secret",
		},
	)
	c.Assert(err, jc.ErrorIsNil)
	s.env = env
	loggo.GetLogger("").SetLogLevel(loggo.INFO)

	// Switch the default tools location.
	s.publicStorageDir = c.MkDir()
	s.PatchValue(&tools.DefaultBaseURL, s.publicStorageDir)
}
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:toolsmetadata_test.go

示例13: SetUpTest

func (s *BenchmarksSuite) SetUpTest(c *gc.C) {
	loggo.ResetLogging()
	s.logger = loggo.GetLogger("test.writer")
	s.writer = &writer{}
	err := loggo.RegisterWriter("test", s.writer)
	c.Assert(err, gc.IsNil)
}
开发者ID:juju,项目名称:loggo,代码行数:7,代码来源:benchmarks_test.go

示例14: Run

func (c *MigrateCommand) Run(ctx *cmd.Context) (err error) {

	defer func() {
		if err != nil {
			fmt.Fprintf(ctx.Stdout, "error stack:\n"+errors.ErrorStack(err))
		}
	}()

	loggo.GetLogger("juju").SetLogLevel(loggo.DEBUG)
	conf, err := agent.ReadConfig(agent.ConfigPath(c.dataDir, c.machineTag))
	if err != nil {
		return err
	}

	info, ok := conf.MongoInfo()
	if !ok {
		return errors.Errorf("no state info available")
	}
	st, err := state.Open(conf.Model(), info, mongo.DefaultDialOpts(), environs.NewStatePolicy())
	if err != nil {
		return err
	}
	defer st.Close()

	if c.operation == "export" {
		return c.exportModel(ctx, st)
	}

	return c.importModel(ctx, st)

}
开发者ID:howbazaar,项目名称:migration-test,代码行数:31,代码来源:main.go

示例15: TestWriteMessageLogsRequests

func (*suite) TestWriteMessageLogsRequests(c *gc.C) {
	codecLogger := loggo.GetLogger("juju.rpc.jsoncodec")
	defer codecLogger.SetLogLevel(codecLogger.LogLevel())
	codecLogger.SetLogLevel(loggo.TRACE)
	codec := jsoncodec.New(&testConn{})
	h := rpc.Header{
		RequestId: 1,
		Request: rpc.Request{
			Type:   "foo",
			Id:     "id",
			Action: "frob",
		},
	}

	// Check that logging is off by default
	err := codec.WriteMessage(&h, value{X: "param"})
	c.Assert(err, gc.IsNil)
	c.Assert(c.GetTestLog(), gc.Matches, "")

	// Check that we see a log message when we switch logging on.
	codec.SetLogging(true)
	err = codec.WriteMessage(&h, value{X: "param"})
	c.Assert(err, gc.IsNil)
	msg := `{"RequestId":1,"Type":"foo","Id":"id","Request":"frob","Params":{"X":"param"}}`
	c.Assert(c.GetTestLog(), gc.Matches, `.*TRACE juju.rpc.jsoncodec -> `+regexp.QuoteMeta(msg)+`\n`)

	// Check that we can switch it off again
	codec.SetLogging(false)
	err = codec.WriteMessage(&h, value{X: "param"})
	c.Assert(err, gc.IsNil)
	c.Assert(c.GetTestLog(), gc.Matches, `.*TRACE juju.rpc.jsoncodec -> `+regexp.QuoteMeta(msg)+`\n`)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:32,代码来源:codec_test.go


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