Skip to content

Commit 0d016f4

Browse files
Fix issue with log destroyed error message on mount and extra logs on unmount
1 parent 7b09f6a commit 0d016f4

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

cmd/unmount.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"strings"
3535

3636
"github.com/Seagate/cloudfuse/common"
37-
"github.com/Seagate/cloudfuse/common/log"
3837

3938
"github.com/spf13/cobra"
4039
)
@@ -137,7 +136,6 @@ func unmountCloudfuse(mntPath string, lazy bool, silent bool) error {
137136
_, err = cliOut.Output()
138137

139138
if err == nil {
140-
log.Info("unmountCloudfuse : successfully unmounted %s", mntPath)
141139
if !silent {
142140
fmt.Println("Successfully unmounted", mntPath)
143141
}

common/log/base_logger.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ type LogFileConfig struct {
5151
}
5252

5353
type BaseLogger struct {
54-
channel chan (string)
55-
workerDone sync.WaitGroup
54+
channel chan (string)
55+
workerDone sync.WaitGroup
56+
destroyOnce sync.Once
5657

5758
logger *log.Logger
5859
logFileHandle io.WriteCloser
@@ -202,18 +203,27 @@ func (l *BaseLogger) init() error {
202203
}
203204

204205
func (l *BaseLogger) Destroy() error {
205-
close(l.channel)
206-
l.workerDone.Wait()
206+
var destroyErr error
207+
l.destroyOnce.Do(func() {
208+
if l.channel != nil {
209+
close(l.channel)
210+
l.channel = nil
211+
}
212+
l.workerDone.Wait()
207213

208-
// Never close stdout/stderr
209-
if l.logFileHandle == os.Stdout || l.logFileHandle == os.Stderr {
210-
return nil
211-
}
214+
// Never close stdout/stderr
215+
if l.logFileHandle == os.Stdout || l.logFileHandle == os.Stderr {
216+
return
217+
}
218+
if l.logFileHandle == nil {
219+
return
220+
}
221+
if err := l.logFileHandle.Close(); err != nil {
222+
destroyErr = err
223+
}
224+
})
212225

213-
if err := l.logFileHandle.Close(); err != nil {
214-
return err
215-
}
216-
return nil
226+
return destroyErr
217227
}
218228

219229
// logEvent : Enqueue the log to the channel

0 commit comments

Comments
 (0)