Passed
Pull Request — master (#52)
by Stefano
02:05
created

test.*ThreadSafeBuffer.String   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
package test
2
3
import (
4
	"bytes"
5
	"sync"
6
7
	"github.com/sirupsen/logrus"
8
)
9
10
type ThreadSafeBuffer struct {
0 ignored issues
show
introduced by
exported type ThreadSafeBuffer should have comment or be unexported
Loading history...
11
	buf *bytes.Buffer
12
	rw  sync.RWMutex
13
}
14
15
func (t *ThreadSafeBuffer) String() string {
16
	t.rw.RLock()
17
	defer t.rw.RUnlock()
18
19
	return t.buf.String()
20
}
21
22
func (t *ThreadSafeBuffer) Write(p []byte) (n int, err error) {
23
	t.rw.Lock()
24
	defer t.rw.Unlock()
25
26
	return t.buf.Write(p)
27
}
28
29
func NewLogger() (*logrus.Logger, *ThreadSafeBuffer) {
0 ignored issues
show
introduced by
exported function NewLogger should have comment or be unexported
Loading history...
30
	b := &bytes.Buffer{}
31
	tsb := &ThreadSafeBuffer{buf: b}
32
33
	l := logrus.New()
34
	l.SetLevel(logrus.DebugLevel)
35
	l.SetOutput(tsb)
36
37
	return l, tsb
38
}
39