-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
39 lines (33 loc) · 934 Bytes
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package jsonrpc
import (
"fmt"
"io"
"os"
)
// Logger defines the interface for logging operations
type Logger interface {
// Errorf logs an error message with formatting
Errorf(format string, args ...interface{})
}
// StdLogger is a simple logger that writes to an io.Writer
type StdLogger struct {
writer io.Writer
}
// Errorf implements Logger.Errorf by writing a formatted error message to the writer
func (l *StdLogger) Errorf(format string, args ...interface{}) {
if l.writer != nil {
fmt.Fprintf(l.writer, format+"\n", args...)
}
}
// NewStdLogger creates a new StdLogger with the specified writer
// If writer is nil, os.Stderr is used as the default
func NewStdLogger(writer io.Writer) *StdLogger {
if writer == nil {
writer = os.Stderr
}
return &StdLogger{
writer: writer,
}
}
// DefaultLogger is the default logger instance that writes to os.Stderr
var DefaultLogger Logger = NewStdLogger(os.Stderr)