Closed marcortw closed 4 years ago
The replacer function is utilized when logging to the console as well, so implementing the replacer function will work without you manually having to call .toJSON();
. Given that, you would be able to utilize the replacer function to mask values within any passed in metadata. For example:
log.options.replacer = function(key, value) {
if(key === 'mySecretKey') {
return 'XXXXXX';
}
return value;
};
log.error('My message', { mySecretKey: 'mySecretValue' });
//=> { "_logLevel": "error", "msg": "My message", "mySecretKey": "XXXXXX", "_tags": ["log", "error"] }
I hope this helps!
This definitely helps, thanks a lot for the quick response! I did set contradicting log.options in two different files during my tests, but it seems like only the first options got applied (which didn't have the replacer function set).
Is it possible to apply the replacer function to the meta object? I sometimes log whole objects using the meta object and it would be nice if I could mask
mySecretValue
with something else using the replacer function.From the docs, I understand that the replacer is only applied if I would call it like this:
Thanks for this neat little module, Marco