Comments (10)
@Mr-Dai Can you provide an example to debug?
from gommon.
Test file main.go
:
package main
import (
"github.com/labstack/echo"
"github.com/labstack/gommon/log"
)
func main() {
e := echo.New()
e.Logger.SetLevel(log.INFO)
e.Logger.Infof("Hello, World!")
}
Run it with go run main.go
, got:
{"time":"2018-03-12T10:57:54.8390043+08:00","level":"INFO","prefix":"echo","file":"proc.go","line":"185","message":"Hello, World!"}
This is proc.go
, basically it's where the go runtime invokes the main
function.
from gommon.
Thanks for the information, I have reverted the changed.
from gommon.
@vishr I have the issuse with caller level 2, because I use the log command:
import (
"github.com/labstack/gommon/log"
)
func main() {
log.Info("Hello, World!")
}
With caller level 3 all is fine again. All my projects where I used the logger show the wrong file and line now
This code in log.go could fix it:
_, file, line,_ := runtime.Caller(2)
if strings.Contains(file, "github.com/labstack/gommon/log/log.go") {
_, file, line,_ = runtime.Caller(3)
}
from gommon.
@alexandrestein Can you please help me with it?
from gommon.
I have the same problem in my project.
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
//correct line etc
e.Logger.Info("Testlog")
//wrong line etc
log.Info("Wrong log")
}
e.Logger.Info produces correct line number:
{"time":"...","level":"INFO","prefix":"echo","file":"main.go","line":"20","message":"Testlog"}
log.Info produces wrong file and line number:
{"time":"...","level":"INFO","prefix":"-","file":"log.go","line":"285","message":"Wrong log"}
baba2k`s change fixes it locally.
from gommon.
@baba2k I think the better way to fix this is to store an extraLevel
field in logger
struct, which defaults to 0
, and change the runtime.Caller
invocation in log.go
to
_, file, line, _ := runtime.Caller(2 + l.extraLevel)
Another way to do this is to add a calldepth
parameter to the log
method, like the log.Output
method from the standard library.
Point is, this should become a generic parameter/configuration, instead of just adding special processing just for invocations from github.com/labstack/gommon/log/log.go
.
from gommon.
@vishr I made a pull request about this issue #21.
The problem is that when you use the default logger you add an other layer.
So you need to switch between level 3
and 2
if it's default logger or not.
Look at the pull request and check the test file I call the default logger directly.
I think that merging the pull request would solve the issue.
from gommon.
Hey @vishr.
It does fix the issue of the caller level.
But same kind of issue could be reintroduce in the future.
In the test, you are not checking that the give response display the correct file or line.
I think this must be check to prevent any future bug related to this.
from gommon.
@alexaandru thanks for pointing that out, I will put the test back soon.
from gommon.
Related Issues (18)
- Bad JSON for messages with newlines or quotes HOT 1
- [Bytes] Format and Parse are not always reversible HOT 1
- Why doesn't email_test.go have no test ?
- Redirect stdout affects stderr HOT 6
- Log crashes in ConEmu in Windows but not in mintty HOT 5
- Remove space between units for bytes e.g. 10KB > 10 KB
- Provide another format/parse for bytes HOT 2
- Logger is slow in OFF level
- bytes package is not ISO/IEC 80000 and IEEE 1541 complient HOT 1
- No color is produced HOT 1
- Recent changes broke something? HOT 2
- module requires Go 1.13 HOT 2
- bytes package tests test implementation defined behaviour
- Add possibility to set skip parameter
- color.SetOutput() panics on go 1.17
- CVE: update testify/yaml dependencies HOT 1
- No colorized output when using docker with `tty: true` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gommon.