Open ce-ankur opened 1 year ago
Hello @ce-ankur did you try?
func myHandler(ctx iris.Context) {
logger := ctx.Application().Logger()
// work with "logger" instance...
}
HI @kataras
This is the easiest approach and I am already using this in my handlers/where-ever the ctx
object is available.
I question was regarding how can I get logger instance where I don't have context object. I don't think passing either logger or ctx instance is a good idea.
@ce-ankur If you use the default Iris logger you can get the logger instance through golog.Default/golog.Debug/Info...
so you don't have dependency cycle.
Env Details:
I am trying to setup my new Iris application as follows:
The bootstrap.go looks like below:
I want to understand once I have setup the logger I want to use it in other parts of the code, like Handlers, service layers, models etc. For this reason I exported a function
GetLoggerInstance()
in hope that I can use same logger instance in whole code. But I land up in cyclic dependency. Moreover, when I am to use logging methods the correct context of the log must be picked up.I understand the access logs and different from application logs, but how can I achieve the parity between both of them using iris logger. Unfortunately I was not able to understand this from Docs. Any help is much appreciated. @kataras