Open 210178 opened 7 years ago
@210178 did you every figure out how to do this?
I guess we need an equivalent to https://github.com/skonves/express-http-context for Koa where we can store request scoped information that can be retrieved in a Winston formatter.
@210178 @stanleegoodspeed @edevil were any of you able to get to the bottom of this? I have a koa
context being passed from my frontend application to the backend whenever there's an interaction, but I'm in need of getting it to be added to my Winston logs.
Here's the detail:
const addHeader = Winston.format((info) => {
info.headers = "Something from koa context";
return info;
});
export const Logger: Winston.Logger = Winston.createLogger({
levels: Winston.config.syslog.levels,
format: Winston.format.combine(
Winston.format.timestamp(),
addHeader()
),
transports: [
new Winston.transports.Console({
level: "info",
format: Winston.format.prettyPrint(),
}),
new Winston.transports.Console({
level: "error",
format: Winston.format.prettyPrint()
}),
]
});
I want it set up that every time something logs, it will fetch that context value from koa
and writes using the Winston logger.
@jamesliupenn I ended up using @emartech/cls-adapter
, to store request specific information and later retrieve it when logging.
What about performance issue with cls ? Aync_hooks are pretty low.
I have push the feature on my server that have 3000req/15s, and my cpu are on fire :
You can see before and after the cls feature :/
@Themandunord What exactly did you change in the app to cause that spike?
@edevil I have figured it out yesterday evening. I was create a cls namespace for each request.
With only one (and it how it is done on @emartech/cls-adapter with the singleton instance for the namespace), the CPU just increase a little and the latency.
It's better.
Do you feel the same on your side?
I am dreaming about a winston's feature to do that 🤤
@Themandunord Yes, I didn't notice such a performance degradation as you were seeing. Glad you've worked it out.
Does anyone found a solution for this issue, it will really help me in my application.
Thanks
I am using Koa 2 framework and Winston logger for my development.
Question:
Whenever UI sends any request to back end (server), I will get the following information (along with other info) as part of my http request header.
I would like to log the above information as part of my winston logger to track/analysis each of the URL request sent to my backend service. My tobe log should be,
Example log statement: info: "get Employee details", {userId: "test", correlationId: "123anbr343232"} info: "get Employee details", {userId: "dummy", correlationId: "453323anbr343232"}
FYI, this correlation id would be different for each URL request
Please let me know how can I achieve this...