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

Golang loggo.GetLogger函数代码示例

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

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



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


示例16: New

// New returns a Worker backed by Config. The caller is responsible for
// Kill()ing the Worker and handling any errors returned from Wait();
// but as it happens it's designed to be an apiserver/common.Resource,
// and never to exit unless Kill()ed, so in practice Stop(), which will
// call Kill() and Wait() internally, is Good Enough.
func New(config Config) (*Worker, error) {
	if err := config.Validate(); err != nil {
		return nil, errors.Trace(err)
	}
	name := fmt.Sprintf("juju.apiserver.presence.%s", config.Identity)
	w := &Worker{
		config: config,
		logger: loggo.GetLogger(name),
	}
	ready := make(chan struct{})
	err := catacomb.Invoke(catacomb.Plan{
		Site: &w.catacomb,
		Work: func() error {
			// Run once to prime presence before diving into the loop.
			pinger := w.startPinger()
			if ready != nil {
				close(ready)
				ready = nil
			}
			if pinger != nil {
				w.waitOnPinger(pinger)
			}
			return w.loop()
		},
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	<-ready
	return w, nil
}
开发者ID:makyo,项目名称:juju,代码行数:36,代码来源:pinger.go


示例17: TestNonCompatiblePathsAre404

func (s *serverSuite) TestNonCompatiblePathsAre404(c *gc.C) {
	// we expose the API at '/' for compatibility, and at '/ENVUUID/api'
	// for the correct location, but other Paths should fail.
	loggo.GetLogger("juju.apiserver").SetLogLevel(loggo.TRACE)
	srv := newServer(c, s.State)
	defer srv.Stop()

	// We have to use 'localhost' because that is what the TLS cert says.
	addr := fmt.Sprintf("localhost:%d", srv.Addr().Port)
	// '/' should be fine
	conn, err := dialWebsocket(c, addr, "/")
	c.Assert(err, jc.ErrorIsNil)
	conn.Close()
	// '/environment/ENVIRONUUID/api' should be fine
	conn, err = dialWebsocket(c, addr, "/environment/dead-beef-123456/api")
	c.Assert(err, jc.ErrorIsNil)
	conn.Close()

	// '/randompath' is not ok
	conn, err = dialWebsocket(c, addr, "/randompath")
	// Unfortunately go.net/websocket just returns Bad Status, it doesn't
	// give us any information (whether this was a 404 Not Found, Internal
	// Server Error, 200 OK, etc.)
	c.Assert(err, gc.ErrorMatches, `websocket.Dial wss://localhost:\d+/randompath: bad status`)
	c.Assert(conn, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:26,代码来源:server_test.go


示例18: serveConn

func (srv *Server) serveConn(wsConn *websocket.Conn, reqNotifier *requestNotifier, modelUUID string) error {
	codec := jsoncodec.NewWebsocket(wsConn)
	if loggo.GetLogger("juju.rpc.jsoncodec").EffectiveLogLevel() <= loggo.TRACE {
		codec.SetLogging(true)
	}
	var notifier rpc.RequestNotifier
	if logger.EffectiveLogLevel() <= loggo.DEBUG {
		// Incur request monitoring overhead only if we
		// know we'll need it.
		notifier = reqNotifier
	}
	conn := rpc.NewConn(codec, notifier)

	h, err := srv.newAPIHandler(conn, reqNotifier, modelUUID)
	if err != nil {
		conn.ServeFinder(&errRoot{err}, serverError)
	} else {
		adminApis := make(map[int]interface{})
		for apiVersion, factory := range srv.adminApiFactories {
			adminApis[apiVersion] = factory(srv, h, reqNotifier)
		}
		conn.ServeFinder(newAnonRoot(h, adminApis), serverError)
	}
	conn.Start()
	select {
	case <-conn.Dead():
	case <-srv.tomb.Dying():
	}
	return conn.Close()
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:30,代码来源:apiserver.go


示例19: Run

func (c *Command) Run(args []string) int {
	c.Ui = &cli.PrefixedUi{
		OutputPrefix: "==> ",
		InfoPrefix:   "    ",
		ErrorPrefix:  "==> ",
		Ui:           c.Ui,
	}

	c.args = args
	config := c.readConfig()
	if config == nil {
		return 1
	}
	c.args = args

	c.Ui.Output("MQTT bridgeify agent running!")
	c.Ui.Info("Getting on the bus: " + config.Token)
	c.Ui.Info("Local url: " + config.LocalUrl)

	c.log = loggo.GetLogger("")

	c.agent = createAgent(config)

	if err := c.agent.start(); err != nil {
		c.Ui.Error(fmt.Sprintf("error starting agent %s", err))
	}

	c.bus = createBus(config, c.agent)

	c.bus.listen()

	return c.handleSignals(config)
}
开发者ID:ninjasphere,项目名称:mqtt-bridgeify,代码行数:33,代码来源:command.go


示例20: TestFindToolsFiltering

func (s *SimpleStreamsToolsSuite) TestFindToolsFiltering(c *gc.C) {
	var tw loggo.TestWriter
	c.Assert(loggo.RegisterWriter("filter-tester", &tw, loggo.TRACE), gc.IsNil)
	defer loggo.RemoveWriter("filter-tester")
	logger := loggo.GetLogger("juju.environs")
	defer logger.SetLogLevel(logger.LogLevel())
	logger.SetLogLevel(loggo.TRACE)

	_, err := envtools.FindTools(
		s.env, 1, -1, "released", coretools.Filter{Number: version.Number{Major: 1, Minor: 2, Patch: 3}})
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
	// This is slightly overly prescriptive, but feel free to change or add
	// messages. This still helps to ensure that all log messages are
	// properly formed.
	messages := []jc.SimpleMessage{
		{loggo.INFO, "reading tools with major version 1"},
		{loggo.INFO, "filtering tools by version: \\d+\\.\\d+\\.\\d+"},
		{loggo.TRACE, "no architecture specified when finding tools, looking for "},
		{loggo.TRACE, "no series specified when finding tools, looking for \\[.*\\]"},
	}
	sources, err := envtools.GetMetadataSources(s.env)
	c.Assert(err, jc.ErrorIsNil)
	for i := 0; i < 2*len(sources); i++ {
		messages = append(messages,
			jc.SimpleMessage{loggo.TRACE, `fetchData failed for .*`},
			jc.SimpleMessage{loggo.TRACE, `cannot load index .*`})
	}
	c.Check(tw.Log(), jc.LogMatches, messages)
}
开发者ID:snailwalker,项目名称:juju,代码行数:29,代码来源:tools_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang loggo.LoggerInfo函数代码示例发布时间:2022-05-23
下一篇:
Golang loggo.ConfigureLoggers函数代码示例发布时间: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