Пример #1
0
func recordFromAPI(apiRec params.LogStreamRecord, controllerUUID string) (logfwd.Record, error) {
	rec := logfwd.Record{
		ID:        apiRec.ID,
		Timestamp: apiRec.Timestamp,
		Message:   apiRec.Message,
	}

	origin, err := originFromAPI(apiRec, controllerUUID)
	if err != nil {
		return rec, errors.Trace(err)
	}
	rec.Origin = origin

	loc, err := logfwd.ParseLocation(apiRec.Module, apiRec.Location)
	if err != nil {
		return rec, errors.Trace(err)
	}
	rec.Location = loc

	level, ok := loggo.ParseLevel(apiRec.Level)
	if !ok {
		return rec, errors.Errorf("unrecognized log level %q", apiRec.Level)
	}
	rec.Level = level

	if err := rec.Validate(); err != nil {
		return rec, errors.Trace(err)
	}

	return rec, nil
}
Пример #2
0
func (s *LocationSuite) TestParseLocationTooLegitToQuit(c *gc.C) {
	expected := validLocation

	loc, err := logfwd.ParseLocation(expected.Module, expected.String())
	c.Assert(err, jc.ErrorIsNil)

	c.Check(loc, jc.DeepEquals, expected)
}
Пример #3
0
func (s *LocationSuite) TestParseLocationMissingFilename(c *gc.C) {
	expected := validLocation
	expected.Filename = ""

	loc, err := logfwd.ParseLocation(expected.Module, ":42")
	c.Assert(err, jc.ErrorIsNil)

	c.Check(loc, jc.DeepEquals, expected)
}
Пример #4
0
func (s *LocationSuite) TestParseLocationIsValid(c *gc.C) {
	expected := validLocation
	loc, err := logfwd.ParseLocation(expected.Module, expected.String())
	c.Assert(err, jc.ErrorIsNil)

	err = loc.Validate()

	c.Check(err, jc.ErrorIsNil)
}
Пример #5
0
func (s *LocationSuite) TestParseLocationFilenameOnly(c *gc.C) {
	expected := validLocation
	expected.Line = -1

	loc, err := logfwd.ParseLocation(expected.Module, expected.Filename)
	c.Assert(err, jc.ErrorIsNil)

	c.Check(loc, jc.DeepEquals, expected)
}
Пример #6
0
func (s *LocationSuite) TestParseLocationBogusLine(c *gc.C) {
	_, err := logfwd.ParseLocation(validLocation.Module, "spam.go:xxx")

	c.Check(err, gc.ErrorMatches, `failed to parse sourceLine: line number must be non-negative integer: strconv.ParseInt: parsing "xxx": invalid syntax`)
}
Пример #7
0
func (s *LocationSuite) TestParseLocationMissingLine(c *gc.C) {
	_, err := logfwd.ParseLocation(validLocation.Module, "spam.go:")

	c.Check(err, gc.ErrorMatches, `failed to parse sourceLine: missing line number after ":"`)
}