File: writer_test.go

package info (click to toggle)
golang-github-juju-loggo 0.0~git20170605.8232ab8-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 220 kB
  • sloc: makefile: 10
file content (37 lines) | stat: -rw-r--r-- 732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.

package loggo_test

import (
	"bytes"
	"time"

	gc "gopkg.in/check.v1"

	"github.com/juju/loggo"
)

type SimpleWriterSuite struct{}

var _ = gc.Suite(&SimpleWriterSuite{})

func (s *SimpleWriterSuite) TestNewSimpleWriter(c *gc.C) {
	now := time.Now()
	formatter := func(entry loggo.Entry) string {
		return "<< " + entry.Message + " >>"
	}
	buf := &bytes.Buffer{}

	writer := loggo.NewSimpleWriter(buf, formatter)
	writer.Write(loggo.Entry{
		Level:     loggo.INFO,
		Module:    "test",
		Filename:  "somefile.go",
		Line:      12,
		Timestamp: now,
		Message:   "a message",
	})

	c.Check(buf.String(), gc.Equals, "<< a message >>\n")
}