當前位置: 首頁>>代碼示例>>Golang>>正文


Golang TestWriter.Clear方法代碼示例

本文整理匯總了Golang中github.com/juju/loggo.TestWriter.Clear方法的典型用法代碼示例。如果您正苦於以下問題:Golang TestWriter.Clear方法的具體用法?Golang TestWriter.Clear怎麽用?Golang TestWriter.Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/juju/loggo.TestWriter的用法示例。


在下文中一共展示了TestWriter.Clear方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: assertLogs

func assertLogs(c *gc.C, ctx jujuc.Context, writer *loggo.TestWriter, unitname, badge string) {
	msg1 := "the chickens"
	msg2 := "are 110% AWESOME"
	com, err := jujuc.NewCommand(ctx, cmdString("juju-log"))
	c.Assert(err, jc.ErrorIsNil)
	for _, t := range []struct {
		args  []string
		level loggo.Level
	}{
		{
			level: loggo.INFO,
		}, {
			args:  []string{"--debug"},
			level: loggo.DEBUG,
		}, {
			args:  []string{"--log-level", "TRACE"},
			level: loggo.TRACE,
		}, {
			args:  []string{"--log-level", "info"},
			level: loggo.INFO,
		}, {
			args:  []string{"--log-level", "WaRnInG"},
			level: loggo.WARNING,
		}, {
			args:  []string{"--log-level", "error"},
			level: loggo.ERROR,
		},
	} {
		writer.Clear()
		c.Assert(err, jc.ErrorIsNil)

		args := append(t.args, msg1, msg2)
		code := cmd.Main(com, &cmd.Context{}, args)
		c.Assert(code, gc.Equals, 0)
		log := writer.Log()
		c.Assert(log, gc.HasLen, 1)
		c.Assert(log[0].Level, gc.Equals, t.level)
		c.Assert(log[0].Module, gc.Equals, fmt.Sprintf("unit.%s.juju-log", unitname))
		c.Assert(log[0].Message, gc.Equals, fmt.Sprintf("%s%s %s", badge, msg1, msg2))
	}
}
開發者ID:howbazaar,項目名稱:juju,代碼行數:41,代碼來源:juju-log_test.go

示例2: checkLastMessage

func checkLastMessage(c *gc.C, writer *loggo.TestWriter, expected string) {
	log := writer.Log()
	writer.Clear()
	obtained := log[len(log)-1].Message
	c.Check(obtained, gc.Equals, expected)
}
開發者ID:njpatel,項目名稱:loggo,代碼行數:6,代碼來源:logger_test.go


注:本文中的github.com/juju/loggo.TestWriter.Clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。