Access to child object in logMethod #897
Comments
|
The hook has no way of obtaining that context: Lines 30 to 35 in 95856d1 |
|
Is not |
Maybe? I think bindings are rendered to a string at child creation. |
|
Is there anywhere to obtain the "parent" binding context? I have tried pretty much every hook/method and can't find a way to access the context before the new bindings are written. It would be nice to have some way to designate that child loggers are children of other loggers, for example to append the log name: const log = logger.child({ name: 'app' });
const log2 = log.child({ name: `service` });
// via hook or formatter set log2's name to "app:service"This would also allow easy filtering of logs in function logMethod(this: any, inputArgs: any, method: pino.LogFn) {
// Check child against debug variable
const { name } = this.bindings();
if (!debug.enabled(name)) return;
return method.apply(this, inputArgs);
}I initially assumed this could be done via |
|
Best way I've found so far is to wrap the const defaultChildMethod = logger.child;
logger.child = function child(newBindings) {
const { name } = this.bindings();
const newName = newBindings.name;
if (name && newName) {
newBindings.name = `${name}:${newName}`;
}
return defaultChildMethod.apply(this, [newBindings]);
}; |
|
I think we should extend Line 157 in 185dc15 Could you send a PR? |


I was looking to access the child object, I want to make so that it prepends the message object.
Here I log what inputArgs contains inside hooks.logMethod
after having called
logger.child({"featureName":"MY FEATURE"}I am trying to make a function that will prepend that name to message, so it becomes
The text was updated successfully, but these errors were encountered: