Skip to content

Commit

Permalink
add some useful methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed Aug 20, 2023
1 parent 80ad29d commit 0828a28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions default_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package mlog

import (
"fmt"
"io"
"os"
)

// DefaultLogger is the default package level Logger
var DefaultLogger = New(os.Stderr, Lstd)

func SetOutput(writer io.Writer) {
DefaultLogger.SetOutput(writer)
}

// SetEmitter sets the Emitter for the degault logger. See
// Logger.SetEmitter.
func SetEmitter(e Emitter) {
Expand Down
7 changes: 7 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ type Logger struct {
flags uint64
}

func (l *Logger) SetOutput(writer io.Writer) {
// lock writing to serialize log output (no scrambled log lines)
l.mu.Lock()
defer l.mu.Unlock()
l.out = writer
}

func (l *Logger) Write(b []byte) (int, error) {
// lock writing to serialize log output (no scrambled log lines)
l.mu.Lock()
Expand Down

0 comments on commit 0828a28

Please sign in to comment.