func (s *bufferedLogWriterSuite) TestBuffering(c *gc.C) { // Write several log message before attempting to read them out. const numMessages = 5 now := time.Now() for i := 0; i < numMessages; i++ { s.writer.Write( loggo.Level(i), fmt.Sprintf("module%d", i), fmt.Sprintf("filename%d", i), i, // line number now.Add(time.Duration(i)), fmt.Sprintf("message%d", i), ) } for i := 0; i < numMessages; i++ { c.Assert(*s.receiveOne(c), gc.DeepEquals, logsender.LogRecord{ Time: now.Add(time.Duration(i)), Module: fmt.Sprintf("module%d", i), Location: fmt.Sprintf("filename%d:%d", i, i), Level: loggo.Level(i), Message: fmt.Sprintf("message%d", i), }) } }
func (s *LoggingSuite) TestLogDoesntLogWeirdLevels(c *gc.C) { s.logger.Logf(loggo.UNSPECIFIED, "message") c.Assert(s.writer.Log(), gc.HasLen, 0) s.logger.Logf(loggo.Level(42), "message") c.Assert(s.writer.Log(), gc.HasLen, 0) s.logger.Logf(loggo.CRITICAL+loggo.Level(1), "message") c.Assert(s.writer.Log(), gc.HasLen, 0) }
func logDocToRecord(doc *logDoc) (*LogRecord, error) { var ver version.Number if doc.Version != "" { parsed, err := version.Parse(doc.Version) if err != nil { return nil, errors.Annotatef(err, "invalid version %q", doc.Version) } ver = parsed } level := loggo.Level(doc.Level) if level > loggo.CRITICAL { return nil, errors.Errorf("unrecognized log level %q", doc.Level) } entity, err := names.ParseTag(doc.Entity) if err != nil { return nil, errors.Annotate(err, "while parsing entity tag") } rec := &LogRecord{ ID: doc.Time, Time: time.Unix(0, doc.Time).UTC(), // not worth preserving TZ ModelUUID: doc.ModelUUID, Entity: entity, Version: ver, Level: level, Module: doc.Module, Location: doc.Location, Message: doc.Message, } return rec, nil }
func (*ContextSuite) TestNewContextRootLevel(c *gc.C) { for i, test := range []struct { level loggo.Level expected loggo.Level }{{ level: loggo.UNSPECIFIED, expected: loggo.WARNING, }, { level: loggo.DEBUG, expected: loggo.DEBUG, }, { level: loggo.INFO, expected: loggo.INFO, }, { level: loggo.WARNING, expected: loggo.WARNING, }, { level: loggo.ERROR, expected: loggo.ERROR, }, { level: loggo.CRITICAL, expected: loggo.CRITICAL, }, { level: loggo.Level(42), expected: loggo.WARNING, }} { c.Log("%d: %s", i, test.level) context := loggo.NewContext(test.level) cfg := context.Config() c.Check(cfg, gc.HasLen, 1) value, found := cfg[""] c.Check(found, gc.Equals, true) c.Check(value, gc.Equals, test.expected) } }
fail: true, }, { str: "", fail: true, }} func (s *LevelSuite) TestParseLevel(c *gc.C) { for _, test := range parseLevelTests { level, ok := loggo.ParseLevel(test.str) c.Assert(level, gc.Equals, test.level) c.Assert(ok, gc.Equals, !test.fail) } } var levelStringValueTests = map[loggo.Level]string{ loggo.UNSPECIFIED: "UNSPECIFIED", loggo.DEBUG: "DEBUG", loggo.TRACE: "TRACE", loggo.INFO: "INFO", loggo.WARNING: "WARNING", loggo.ERROR: "ERROR", loggo.CRITICAL: "CRITICAL", loggo.Level(42): "<unknown>", // other values are unknown } func (s *LevelSuite) TestLevelStringValue(c *gc.C) { for level, str := range levelStringValueTests { c.Assert(level.String(), gc.Equals, str) } }