Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger panics after SetHeader with empty string #2295

Closed
3 tasks done
glumpo opened this issue Oct 5, 2022 · 6 comments · Fixed by #2302
Closed
3 tasks done

Logger panics after SetHeader with empty string #2295

glumpo opened this issue Oct 5, 2022 · 6 comments · Fixed by #2302

Comments

@glumpo
Copy link

glumpo commented Oct 5, 2022

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

@glumpo
Copy link
Author

glumpo commented Oct 5, 2022

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?

@aldas
Copy link
Contributor

aldas commented Oct 5, 2022

I'll bump version soon.

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

@glumpo
Copy link
Author

glumpo commented Oct 5, 2022

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.

@aldas
Copy link
Contributor

aldas commented Oct 5, 2022

@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).

@glumpo
Copy link
Author

glumpo commented Oct 6, 2022

@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.

@aldas
Copy link
Contributor

aldas commented Oct 12, 2022

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants