Closed lxdv163 closed 3 years ago
Hey, I tried the Issue you described in my test setup, and it worked as it is intended. The ideas I have are: When you try these settings locally, the logging library does not detect a cf context and then logs in the better usable cloud-logging custom field format (for more info look in the ReadMe) You can force this behaviour in your local environment with:
log.overrideCustomFieldFormat("application-logging");
Please make also sure, that you use the logging library as a middleware to have correct req handling:
app.use(log.logNetwork);
I hope the problem you faced will be resolved by one of these pointers.
I set custom fields for global logger, it works well var log = require('cf-nodejs-logging-support'); log.registerCustomFields(["field1", "field2", "field3"]); log.info("nodejs log test", { "field1": "value1", "field2": "value2" } ); the custom fields log info is correct "#cf":{"string":[{"k":"field1","v":"value1","i":0},{"k":"field2","v":"value2","i":1}]}
but if I use request logger, like this: var log = require('cf-nodejs-logging-support'); log.registerCustomFields(["field1", "field2", "field3"]); req.logger.info("nodejs log test", { "field1": "value1", "field2": "value2" } ); the custom fields log info is this: "field1":"value1","field2":"value2" so I wonder the request logger didn't output custom fields by correct format