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


Golang state.NewLogTailer函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。