summaryrefslogtreecommitdiff
path: root/internal/io/dlog/loggers/file.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-09 21:10:29 +0300
committerPaul Buetow <paul@buetow.org>2021-10-10 13:36:41 +0300
commit97747ea0f3178f7f5890512d483fdccaa82846b0 (patch)
tree9ff1335ca26afc90e55fd6de416457e252d75a35 /internal/io/dlog/loggers/file.go
parent7a7169791a64190e1002e38bc9c04ad0d5c1ce1f (diff)
vetting and linting and some code restyling
Diffstat (limited to 'internal/io/dlog/loggers/file.go')
-rw-r--r--internal/io/dlog/loggers/file.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/internal/io/dlog/loggers/file.go b/internal/io/dlog/loggers/file.go
index 87280fd..94824fe 100644
--- a/internal/io/dlog/loggers/file.go
+++ b/internal/io/dlog/loggers/file.go
@@ -12,8 +12,7 @@ import (
"github.com/mimecast/dtail/internal/config"
)
-type fileWriter struct {
-}
+type fileWriter struct{}
type fileMessageBuf struct {
now time.Time
@@ -35,7 +34,7 @@ type file struct {
}
func newFile(strategy Strategy) *file {
- f := file{
+ return &file{
bufferCh: make(chan *fileMessageBuf, runtime.NumCPU()*100),
pauseCh: make(chan struct{}),
resumeCh: make(chan struct{}),
@@ -43,16 +42,17 @@ func newFile(strategy Strategy) *file {
flushCh: make(chan struct{}),
strategy: strategy,
}
-
- return &f
}
func (f *file) Start(ctx context.Context, wg *sync.WaitGroup) {
f.mutex.Lock()
- defer f.mutex.Unlock()
+ defer func() {
+ f.started = true
+ f.mutex.Unlock()
+ }()
- // Logger already started from another Goroutine.
if f.started {
+ // Logger already started from another Goroutine.
wg.Done()
return
}
@@ -68,7 +68,6 @@ func (f *file) Start(ctx context.Context, wg *sync.WaitGroup) {
go func() {
defer wg.Done()
-
for {
select {
case m := <-f.bufferCh:
@@ -84,8 +83,6 @@ func (f *file) Start(ctx context.Context, wg *sync.WaitGroup) {
}
}
}()
-
- f.started = true
}
func (f *file) Log(now time.Time, message string) {