@@ -38,9 +38,9 @@ type CommonLogger interface {
3838}
3939
4040type AllLogger interface {
41- CommonLogger
42- ControlLogger
43- WithLogger
41+ CommonLogger
42+ ControlLogger
43+ WithLogger
4444}
4545```
4646
@@ -99,7 +99,7 @@ import (
9999var _ log.AllLogger = (*customLogger)(nil )
100100
101101type customLogger struct {
102- stdlog *log.Logger
102+ stdlog *log.Logger
103103}
104104
105105// ...
@@ -118,11 +118,39 @@ import "github.com/gofiber/fiber/v2/log"
118118
119119log.SetLevel (log.LevelInfo )
120120```
121+ ## Set output
122+
123+ ` log.SetOutput ` sets the output destination of the logger. The default logger types the log in the console.
124+
125+ ``` go
126+ var logger AllLogger = &defaultLogger{
127+ stdlog: log.New (os.Stderr , " " , log.LstdFlags |log.Lshortfile |log.Lmicroseconds ),
128+ depth: 4 ,
129+ }
130+ ```
121131
132+ Set the output destination to the file.
133+
134+ ``` go
135+ // Output to ./test.log file
136+ f , err := os.OpenFile (" test.log" , os.O_CREATE |os.O_WRONLY |os.O_APPEND , 0666 )
137+ if err != nil {
138+ return
139+ }
140+ log.SetOutput (f)
141+ ```
142+ Set the output destination to the console and file.
143+
144+ ``` go
145+ // Output to ./test.log file
146+ file , _ := os.OpenFile (" test.log" , os.O_CREATE |os.O_WRONLY |os.O_APPEND , 0666 )
147+ iw := io.MultiWriter (os.Stdout , file)
148+ log.SetOutput (iw)
149+ ```
122150## Bind context
123151Set the context, using the following method will return a ` CommonLogger ` instance bound to the specified context
124152``` go
125-
126153commonLogger := log.WithContext (ctx)
127154commonLogger.Info (" info" )
128155```
156+
0 commit comments