~mwhudson/ubuntu/xenial/juju-core/mwhudson

« back to all changes in this revision

Viewing changes to src/launchpad.net/loggo/testwriter.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-03 09:22:46 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20140203092246-e03vg402vztzo4qa
Tags: 1.17.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package loggo
2
 
 
3
 
import (
4
 
        "path"
5
 
        "time"
6
 
)
7
 
 
8
 
// TestLogValues represents a single logging call.
9
 
type TestLogValues struct {
10
 
        Level     Level
11
 
        Module    string
12
 
        Filename  string
13
 
        Line      int
14
 
        Timestamp time.Time
15
 
        Message   string
16
 
}
17
 
 
18
 
// TestWriter is a useful Writer for testing purposes.  Each component of the
19
 
// logging message is stored in the Log array.
20
 
type TestWriter struct {
21
 
        Log []TestLogValues
22
 
}
23
 
 
24
 
// Write saves the params as members in the TestLogValues struct appended to the Log array.
25
 
func (writer *TestWriter) Write(level Level, module, filename string, line int, timestamp time.Time, message string) {
26
 
        if writer.Log == nil {
27
 
                writer.Log = []TestLogValues{}
28
 
        }
29
 
        writer.Log = append(writer.Log,
30
 
                TestLogValues{level, module, path.Base(filename), line, timestamp, message})
31
 
}
32
 
 
33
 
// Clear removes any saved log messages.
34
 
func (writer *TestWriter) Clear() {
35
 
        writer.Log = []TestLogValues{}
36
 
}