Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/grumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOla Bini <ola@autonomia.digital>2020-03-26 17:04:14 +0300
committerOla Bini <ola@autonomia.digital>2020-03-26 17:04:14 +0300
commitdd6f383d3e57dd3fcd589e289a23ec5d3b292d5f (patch)
treeb7f5b7e949a10ced606140d22824222254ff4217
parent8d351aedb06a96bc27093b2d75cc91788bebb067 (diff)
Rename the default logtarget to not stutter. Also hide the default file log target implementation
-rw-r--r--cmd/grumble/grumble.go4
-rw-r--r--cmd/grumble/server.go2
-rw-r--r--cmd/grumble/signal_unix.go2
-rw-r--r--pkg/logtarget/logtarget.go20
4 files changed, 14 insertions, 14 deletions
diff --git a/cmd/grumble/grumble.go b/cmd/grumble/grumble.go
index c47e2de..6d2c93a 100644
--- a/cmd/grumble/grumble.go
+++ b/cmd/grumble/grumble.go
@@ -37,14 +37,14 @@ func main() {
dataDir.Close()
// Set up logging
- err = logtarget.Target.OpenFile(Args.LogPath)
+ err = logtarget.Default.OpenFile(Args.LogPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to open log file (%v): %v", Args.LogPath, err)
return
}
log.SetPrefix("[G] ")
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
- log.SetOutput(logtarget.Target)
+ log.SetOutput(logtarget.Default)
log.Printf("Grumble")
log.Printf("Using data directory: %s", Args.DataDir)
diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go
index 7877830..4f2bb4d 100644
--- a/cmd/grumble/server.go
+++ b/cmd/grumble/server.go
@@ -156,7 +156,7 @@ func NewServer(id int64) (s *Server, err error) {
s.Channels[0] = NewChannel(0, "Root")
s.nextChanId = 1
- s.Logger = log.New(logtarget.Target, fmt.Sprintf("[%v] ", s.Id), log.LstdFlags|log.Lmicroseconds)
+ s.Logger = log.New(logtarget.Default, fmt.Sprintf("[%v] ", s.Id), log.LstdFlags|log.Lmicroseconds)
return
}
diff --git a/cmd/grumble/signal_unix.go b/cmd/grumble/signal_unix.go
index 7127f24..9066b49 100644
--- a/cmd/grumble/signal_unix.go
+++ b/cmd/grumble/signal_unix.go
@@ -20,7 +20,7 @@ func SignalHandler() {
signal.Notify(sigchan, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
for sig := range sigchan {
if sig == syscall.SIGUSR2 {
- err := logtarget.Target.Rotate()
+ err := logtarget.Default.Rotate()
if err != nil {
fmt.Fprintf(os.Stderr, "unable to rotate log file: %v", err)
}
diff --git a/pkg/logtarget/logtarget.go b/pkg/logtarget/logtarget.go
index 144654c..6ad43f5 100644
--- a/pkg/logtarget/logtarget.go
+++ b/pkg/logtarget/logtarget.go
@@ -12,6 +12,10 @@ import (
"sync"
)
+// LogTarget implements the io.Writer interface, allowing
+// LogTarget to be registered with the regular Go log package.
+// LogTarget multiplexes its incoming writes to multiple optional
+// output writers, and one main output writer (the log file).
type LogTarget interface {
io.Writer
@@ -19,25 +23,21 @@ type LogTarget interface {
Rotate() error
}
-// LogTarget implements the io.Writer interface, allowing
-// LogTarget to be registered with the regular Go log package.
-// LogTarget multiplexes its incoming writes to multiple optional
-// output writers, and one main output writer (the log file).
-type FileLogTarget struct {
+type fileLogTarget struct {
mu sync.Mutex
logfn string
file *os.File
memLog *bytes.Buffer
}
-var Target LogTarget
+var Default LogTarget
func init() {
- Target = &FileLogTarget{}
+ Default = &fileLogTarget{}
}
// Write writes a log message to all registered io.Writers
-func (target *FileLogTarget) Write(in []byte) (int, error) {
+func (target *fileLogTarget) Write(in []byte) (int, error) {
target.mu.Lock()
defer target.mu.Unlock()
@@ -60,7 +60,7 @@ func (target *FileLogTarget) Write(in []byte) (int, error) {
// OpenFile opens the main log file for writing.
// This method will open the file in append-only mode.
-func (target *FileLogTarget) OpenFile(fn string) (err error) {
+func (target *fileLogTarget) OpenFile(fn string) (err error) {
target.logfn = fn
target.file, err = os.OpenFile(target.logfn, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0650)
if err != nil {
@@ -73,7 +73,7 @@ func (target *FileLogTarget) OpenFile(fn string) (err error) {
// This method holds a lock while rotating the log file,
// and all log writes will be held back until the rotation
// is complete.
-func (target *FileLogTarget) Rotate() error {
+func (target *fileLogTarget) Rotate() error {
target.mu.Lock()
defer target.mu.Unlock()