forked from sirupsen/logrus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sirupsen#1017 from freeformz/ffz/docWriter
some minimal documentation for Logger.Writer{,Level}
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package logrus_test | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func ExampleLogger_Writer_httpServer() { | ||
logger := logrus.New() | ||
w := logger.Writer() | ||
defer w.Close() | ||
|
||
srv := http.Server{ | ||
// create a stdlib log.Logger that writes to | ||
// logrus.Logger. | ||
ErrorLog: log.New(w, "", 0), | ||
} | ||
|
||
if err := srv.ListenAndServe(); err != nil { | ||
logger.Fatal(err) | ||
} | ||
} | ||
|
||
func ExampleLogger_Writer_stdlib() { | ||
logger := logrus.New() | ||
logger.Formatter = &logrus.JSONFormatter{} | ||
|
||
// Use logrus for standard log output | ||
// Note that `log` here references stdlib's log | ||
// Not logrus imported under the name `log`. | ||
log.SetOutput(logger.Writer()) | ||
} |