-
Notifications
You must be signed in to change notification settings - Fork 15
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
Use hooks for third party logging #228
Comments
Hooks are probably your best bet: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=javascript%2Cwindows%2Cazure-cli&pivots=nodejs-model-v4#hooks I think something like this would work if you want to completely replace app insights: app.hook.preInvocation((context) => {
context.invocationContext.log = (...args) => {
// your logic here
};
}); If you want your seq stuff and app insights at the same time, it gets a little more clunky, but I think this would work: app.hook.preInvocation((context) => {
const newContext = {
...context.invocationContext,
log: (...args) => {
// your logic here
context.invocationContext.log(...args);
},
};
context.inputs.push(newContext);
}); Hooks are relatively new, so if there's anything missing please file a feature request |
I feel like this might be a common scenario, so I'll count this as its own feature request to come up with a "recommended" design for people and make sure its nice and easy |
Just merged a PR that will be the new recommended way to do this. It relies on some changes in Azure which will take a month or two to roll out, so I'll update here once that finishes. Here's what the new feature will look like: const customLogger = new CustomLogger();
app.hook.log((logContext) => {
customLogger.emit({
body: logContext.message,
severity: logContext.level,
});
}); |
Fyi this is ready to be used. You need Host v4.34+ which should be done rolling out in Azure or core tools v4.0.5801 if running locally which was just released today. Oh and v4.5.0 of this package which we also just released today |
Investigative information
We would like to hook a third party logging library (pino, winston) in context.log, so that we can send it to another sink, that isn't application insights (in our case it's seq).
Is it possible to hook this in?
In .NET we can use
ILogger
/ILoggerFactory
, but I'm unsure how to do this with nodeThe text was updated successfully, but these errors were encountered: