mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 04:51:56 +00:00
Update to 8.1.0 - a new logger implemented as a solution for https://github.com/kataras/iris/issues/680
Former-commit-id: 765b43602655fad7f525ca7a5f7f297a6167d075
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
stdContext "context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -14,7 +13,7 @@ import (
|
||||
func logger(app *iris.Application) *bytes.Buffer {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
app.Logger().Out = buf
|
||||
app.Logger().SetOutput(buf)
|
||||
|
||||
// disable the "Now running at...." in order to have a clean log of the error.
|
||||
// we could attach that on `Run` but better to keep things simple here.
|
||||
@@ -41,20 +40,12 @@ func TestListenAddr(t *testing.T) {
|
||||
t.Fatalf("expecting err to be `iris.ErrServerClosed` but got: %v", err)
|
||||
}
|
||||
|
||||
// println(log.Bytes())
|
||||
// println(len(log.Bytes()))
|
||||
expectedMessage := iris.ErrServerClosed.Error()
|
||||
|
||||
expected := fmt.Sprintln("\"" + iris.ErrServerClosed.Error() + "\" ")
|
||||
expected = strings.TrimSpace(expected)
|
||||
// println([]byte(expected))
|
||||
// println(len([]byte(expected)))
|
||||
|
||||
got := log.String()
|
||||
got = strings.Split(got, "msg=")[1]
|
||||
got = strings.TrimSpace(got)
|
||||
if expected != got {
|
||||
t.Fatalf("expecting to log the:\n'%s'\ninstead of:\n'%s'", expected, got)
|
||||
if got := log.String(); !strings.Contains(got, expectedMessage) {
|
||||
t.Fatalf("expecting to log to contains the:\n'%s'\ninstead of:\n'%s'", expectedMessage, got)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestListenAddrWithoutServerErr(t *testing.T) {
|
||||
|
||||
@@ -18,7 +18,8 @@ func main() {
|
||||
Method: true,
|
||||
// Path displays the request path
|
||||
Path: true,
|
||||
// Columns: true,
|
||||
|
||||
//Columns: true,
|
||||
|
||||
// if !empty then its contents derives from `ctx.Values().Get("logger_message")
|
||||
// will be added to the logs.
|
||||
@@ -57,6 +58,6 @@ func main() {
|
||||
// http://localhost:8080/2
|
||||
// http://lcoalhost:8080/notfoundhere
|
||||
// see the output on the console.
|
||||
app.Run(iris.Addr(":8080"))
|
||||
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func main() {
|
||||
// http://localhost:8080/1
|
||||
// http://localhost:8080/2
|
||||
// http://lcoalhost:8080/notfoundhere
|
||||
app.Run(iris.Addr(":8080"))
|
||||
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
|
||||
}
|
||||
|
||||
// get a filename based on the date, file logs works that way the most times
|
||||
|
||||
@@ -32,11 +32,11 @@ func main() {
|
||||
|
||||
app := iris.New()
|
||||
// attach the file as logger, remember, iris' app logger is just an io.Writer.
|
||||
app.Logger().Out = newLogFile()
|
||||
app.Logger().SetOutput(newLogFile())
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
// for the sake of simplicity, in order see the logs at the ./_today_.txt
|
||||
ctx.Application().Logger().Infoln("Request path: " + ctx.Path())
|
||||
ctx.Application().Logger().Info("Request path: " + ctx.Path())
|
||||
ctx.Writef("hello")
|
||||
})
|
||||
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
// and open the ./logs.txt file
|
||||
if err := app.Run(iris.Addr(":8080"), iris.WithoutBanner); err != nil {
|
||||
if err != iris.ErrServerClosed {
|
||||
app.Logger().Warnln("Shutdown with error: " + err.Error())
|
||||
app.Logger().Warn("Shutdown with error: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func main() {
|
||||
// using the go v1.8's HTTP/2 Push.
|
||||
// Note that you have to listen using ListenTLS in order this to work.
|
||||
if err := ctx.ResponseWriter().Push("/js/chat.js", nil); err != nil {
|
||||
ctx.Application().Logger().Warnln(err.Error())
|
||||
ctx.Application().Logger().Warn(err.Error())
|
||||
}
|
||||
ctx.ViewData("", clientPage{"Client Page", ctx.Host()})
|
||||
ctx.View("client.html")
|
||||
|
||||
Reference in New Issue
Block a user