例如,我具有异步功能getObjects
。该函数带有一些我想传递到日志中的参数,但我不希望它们出现在外部作用域的日志中。
import logger from '~/utils/logger';
const getObjects = async (data) => {
logger.log('info', 'Getting objects');
logger.log('debug', 'I want to have `data` fields in my logs');
...
logger.log('info', "And there's much more logs to be written");
}
const main = async () => {
logger.log('info', "No, I don't want additional fields here");
await getObjects({ someData: 'here' });
logger.log('info', "Also, don't want them here");
}
main();
logger
是Winston的一个实例,具有配置的到Elasticsearch和控制台的传输。
这里有什么简单的方法可以做我想要的吗?