How do we pass a protopayload union label using google-cloud/logging package in NodeJS?
So far i am able to write textPayload and jsonPayload in the logs.
Tried creating a protocol buffer using google-protobuf and also protobufjs and even tried protocol-buffer packages, but the payload is not seen in the logs when i do log.entry and log.write.
This is the code for writing logs
//writelogs.js
function writeLogEntryAdvanced (logName, options, callback) {
var logging = Logging();
var log = logging.log(logName);
var protobuf = require('protocol-buffers');
var fs = require('file-system');
// pass a proto file as a buffer/string or pass a parsed protobuf-schema object
var messages = protobuf(fs.readFileSync('test.proto'));
var buf = messages.Test.encode({
num: 42,
payload: 'hello world'
});
console.log(buf);
var entry = log.entry({ resource: options.resource }, buf);
// See https://googlecloudplatform.github.io/google-cloud-node/#/docs/logging/latest/logging/log?method=write
log.write(entry, function (err, apiResponse) {
if (err) {
return callback(err);
}
console.log('Wrote entry to log: %s', logName);
return callback(null, apiResponse);
});
}
//test.proto
message Test {
required float num = 1;
required string payload = 2;
}
the writing code is copied from nodejs-doc-samples from github with few changes of my own for protopayload. The sample logs writing was only for jsonPayload and textPayload.
via Rajat
No comments:
Post a Comment