Skip to content

Pass ctx to transporter #83

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Pass ctx to transporter #83

wants to merge 1 commit into from

Conversation

roark
Copy link

@roark roark commented Jan 5, 2021

Enables more verbose Transporter to log other ctx details. Fixes issues #77 and #82.

ctx is passed as the 3rd argument to transporter as to not disrupt any existing code. That said, it could easily be the first argument if desired.

app.use(logger((str, args, ctx) => {
  console.log(str, ctx.request.ip); // ctx.request.header['user-agent'], etc...
}))

Copy link
Member

@3imed-jaberi 3imed-jaberi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

@s4kr4
Copy link

s4kr4 commented Jul 22, 2021

When does it ship?

@libook
Copy link

libook commented Oct 21, 2021

Anyone who waiting for this feature may do this temporarily:

import koaLogger from "koa-logger";

app.use(async (ctx, next) => {
    const koaLoggerInstance = koaLogger(logString => {
        // Do anything with ctx
    });
    await koaLoggerInstance(ctx, next);
});

@jalada
Copy link

jalada commented Jun 12, 2025

Anyone who waiting for this feature may do this temporarily:

import koaLogger from "koa-logger";

app.use(async (ctx, next) => {
    const koaLoggerInstance = koaLogger(logString => {
        // Do anything with ctx
    });
    await koaLoggerInstance(ctx, next);
});

Doing this instantiates a brand new instance of koa-logger for every request. This might not be a problem for your use case, but could have memory & performance implications in high-throughput scenarios.

@3imed-jaberi
Copy link
Member

Thanks @roark for your contribution, could you please add test cases here!

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 this pull request may close these issues.

is there a way to log user agent? Is there a reason not to pass ctx on Custom Transporter?
5 participants