Skip to content

Logger panics after SetHeader with empty string #2295

Closed

Description

@glumpo

Issue Description

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

package main

import (
	"github.com/labstack/echo/v4"
)

func main() {
	e := echo.New()
	e.Logger.SetHeader("")
	e.Logger.Error("Hellow")
}

I expect code above to print just a message "Hellow"

Actual behaviour

Code panics.

Steps to reproduce

go run ./main.go with code above.

Version/commit

v4.9.0
Also checked on latest commit 666938e

Activity

  1. glumpo commented on Oct 5, 2022

    @glumpo
    Author

    Issue is already fixed in logger
    https://github.com/labstack/gommon/blob/6267eb7480ded0b4c030ca5e7320417281bb4cd6/log/log.go#L394

    Will you update dependency, or we are waiting for release or something?

  2. aldas commented on Oct 5, 2022

    @aldas
    Contributor

    I'll bump version soon.

    Are you trying to disable logger or why are you setting header to empty string?

  3. glumpo commented on Oct 5, 2022

    @glumpo
    Author

    Hi, thanks for reply.
    I want to provide server with my logger, but not satisfying echo.Logger interface for some reasons (mainly it looks too detailed). So I tried to set empty header and provide io.Writer (throw SetOutput), which will merge echo`s logs to my main logger.

  4. aldas commented on Oct 5, 2022

    @aldas
    Contributor

    @glumpo what are you logging? If its requests then I strongly suggest you to use newer logger middleware https://github.com/labstack/echo/blob/master/middleware/request_logger.go See examples there at the beginning. RequestLogger middleware is built to be used with 3rd party logger libraries (like Zap, Zerolog etc).

  5. glumpo commented on Oct 6, 2022

    @glumpo
    Author

    @aldas Thanks for suggestion I already use RequestLogger for requests. But as I can see Logger is used for some internal purposes in Response.WriteHeader and in Router.Add. I guess I probably will never need to see logs from Router.Add but I am not sure about WriteHeader and possible future changes, which may add more internal logging.

  6. aldas commented on Oct 12, 2022

    @aldas
    Contributor

    This is fixed in v4.9.1. I bumped gommon version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions