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

Golang state.NewLogTailer函数代码示例

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

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



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

示例1: TestNoTail

func (s *LogTailerSuite) TestNoTail(c *gc.C) {
	expected := logTemplate{Message: "want"}
	s.writeLogs(c, 2, expected)

	// Write a log entry that's only in the oplog.
	doc := s.logTemplateToDoc(logTemplate{Message: "dont want"}, time.Now())
	err := s.writeLogToOplog(doc)
	c.Assert(err, jc.ErrorIsNil)

	tailer, err := state.NewLogTailer(s.otherState, &state.LogTailerParams{
		NoTail: true,
	})
	c.Assert(err, jc.ErrorIsNil)
	// Not strictly necessary, just in case NoTail doesn't work in the test.
	defer tailer.Stop()

	// Logs only in the oplog shouldn't be reported and the tailer
	// should stop itself once the log collection has been read.
	s.assertTailer(c, tailer, 2, expected)
	select {
	case _, ok := <-tailer.Logs():
		if ok {
			c.Fatal("shouldn't be any further logs")
		}
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for logs channel to close")
	}

	select {
	case <-tailer.Dying():
		// Success.
	case <-time.After(coretesting.LongWait):
		c.Fatal("tailer didn't stop itself")
	}
}
开发者ID:makyo,项目名称:juju,代码行数:35,代码来源:logs_test.go


示例2: TestOplogTransition

func (s *LogTailerSuite) TestOplogTransition(c *gc.C) {
	// Ensure that logs aren't repeated as the log tailer moves from
	// reading from the logs collection to tailing the oplog.
	//
	// All logs are written out with the same timestamp to create a
	// challenging scenario for the tailer.

	for i := 0; i < 5; i++ {
		s.writeLogs(c, 1, logTemplate{Message: strconv.Itoa(i)})
	}

	tailer, err := state.NewLogTailer(s.otherState, &state.LogTailerParams{
		Oplog: s.oplogColl,
	})
	c.Assert(err, jc.ErrorIsNil)
	defer tailer.Stop()
	for i := 0; i < 5; i++ {
		s.assertTailer(c, tailer, 1, logTemplate{Message: strconv.Itoa(i)})
	}

	// Write more logs. These will be read from the the oplog.
	for i := 5; i < 10; i++ {
		lt := logTemplate{Message: strconv.Itoa(i)}
		s.writeLogs(c, 2, lt)
		s.assertTailer(c, tailer, 2, lt)
	}
}
开发者ID:makyo,项目名称:juju,代码行数:27,代码来源:logs_test.go


示例3: newTailer

func (st logStreamState) newTailer(args *state.LogTailerParams) (state.LogTailer, error) {
	tailer, err := state.NewLogTailer(st, args)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return tailer, nil
}
开发者ID:bac,项目名称:juju,代码行数:7,代码来源:logstream.go


示例4: TestTimeFiltering

func (s *LogTailerSuite) TestTimeFiltering(c *gc.C) {
	// Add 10 logs that shouldn't be returned.
	threshT := time.Now()
	s.writeLogsT(c,
		threshT.Add(-5*time.Second), threshT.Add(-time.Millisecond), 5,
		logTemplate{Message: "dont want"},
	)

	// Add 5 logs that should be returned.
	want := logTemplate{Message: "want"}
	s.writeLogsT(c, threshT, threshT.Add(5*time.Second), 5, want)
	tailer, err := state.NewLogTailer(s.otherState, &state.LogTailerParams{
		StartTime: threshT,
		Oplog:     s.oplogColl,
	})
	c.Assert(err, jc.ErrorIsNil)
	defer tailer.Stop()
	s.assertTailer(c, tailer, 5, want)

	// Write more logs. These will be read from the the oplog.
	want2 := logTemplate{Message: "want 2"}
	s.writeLogsT(c, threshT.Add(6*time.Second), threshT.Add(10*time.Second), 5, want2)
	s.assertTailer(c, tailer, 5, want2)

}
开发者ID:makyo,项目名称:juju,代码行数:25,代码来源:logs_test.go


示例5: TestInitialLinesWithNotEnoughLines

func (s *LogTailerSuite) TestInitialLinesWithNotEnoughLines(c *gc.C) {
	expected := logTemplate{Message: "want"}
	s.writeLogs(c, 2, expected)

	tailer := state.NewLogTailer(s.State, &state.LogTailerParams{
		InitialLines: 5,
	})
	defer tailer.Stop()

	// Should see just the 2 lines that existed, even though 5 were
	// asked for.
	s.assertTailer(c, tailer, 2, expected)
}
开发者ID:pmatulis,项目名称:juju,代码行数:13,代码来源:logs_test.go


示例6: TestInitialLines

func (s *LogTailerSuite) TestInitialLines(c *gc.C) {
	expected := logTemplate{Message: "want"}
	s.writeLogs(c, 3, logTemplate{Message: "dont want"})
	s.writeLogs(c, 5, expected)

	tailer := state.NewLogTailer(s.State, &state.LogTailerParams{
		InitialLines: 5,
	})
	defer tailer.Stop()

	// Should see just the last 5 lines as requested.
	s.assertTailer(c, tailer, 5, expected)
}
开发者ID:pmatulis,项目名称:juju,代码行数:13,代码来源:logs_test.go


示例7: checkLogTailerFiltering

func (s *LogTailerSuite) checkLogTailerFiltering(
	params *state.LogTailerParams,
	writeLogs func(),
	assertTailer func(state.LogTailer),
) {
	// Check the tailer does the right thing when reading from the
	// logs collection.
	writeLogs()
	params.Oplog = s.oplogColl
	tailer := state.NewLogTailer(s.State, params)
	defer tailer.Stop()
	assertTailer(tailer)

	// Now write out logs and check the tailer again. These will be
	// read from the oplog.
	writeLogs()
	assertTailer(tailer)
}
开发者ID:pmatulis,项目名称:juju,代码行数:18,代码来源:logs_test.go


示例8: dumpLogsForEnv

func (c *dumpLogsCommand) dumpLogsForEnv(ctx *cmd.Context, st0 *state.State, tag names.ModelTag) error {
	st, err := st0.ForModel(tag)
	if err != nil {
		return errors.Annotate(err, "failed open model")
	}
	defer st.Close()

	logName := ctx.AbsPath(filepath.Join(c.outDir, fmt.Sprintf("%s.log", tag.Id())))
	ctx.Infof("writing to %s", logName)

	file, err := os.Create(logName)
	if err != nil {
		return errors.Annotate(err, "failed to open output file")
	}
	defer file.Close()

	writer := bufio.NewWriter(file)
	defer writer.Flush()

	tailer, err := state.NewLogTailer(st, &state.LogTailerParams{NoTail: true})
	if err != nil {
		return errors.Annotate(err, "failed to create a log tailer")
	}
	logs := tailer.Logs()
	for {
		rec, ok := <-logs
		if !ok {
			break
		}
		writer.WriteString(c.format(
			rec.Time,
			rec.Level,
			rec.Entity.String(),
			rec.Module,
			rec.Message,
		) + "\n")
	}

	return nil
}
开发者ID:bac,项目名称:juju,代码行数:40,代码来源:dumplogs.go


示例9: _newLogTailer

func _newLogTailer(st state.LoggingState, params *state.LogTailerParams) state.LogTailer {
	return state.NewLogTailer(st, params)
}
开发者ID:imoapps,项目名称:juju,代码行数:3,代码来源:debuglog_db.go


示例10: TestTailingAllLogsFromNonController

func (s *LogTailerSuite) TestTailingAllLogsFromNonController(c *gc.C) {
	_, err := state.NewLogTailer(s.otherState, &state.LogTailerParams{AllModels: true})
	c.Assert(err, gc.ErrorMatches, "not allowed to tail logs from all models: not a controller")
}
开发者ID:makyo,项目名称:juju,代码行数:4,代码来源:logs_test.go


示例11: _newLogTailer

func _newLogTailer(st state.LogTailerState, params *state.LogTailerParams) (state.LogTailer, error) {
	return state.NewLogTailer(st, params)
}
开发者ID:bac,项目名称:juju,代码行数:3,代码来源:debuglog_db.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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