How to add @google-cloud/logging for React native

650 Views Asked by At

I want to implement @google-cloud/logging for React native. I tried it in firebase functions side and Node.js.

I tried above one and followed this link Google cloud log demo its working in node.js and running it google cloud gets all logs but when I install this google cloud logg package into react native its not working or I don't know where to implemente it

I found same tag in this link Same issues in this link

Same below methods are followed in this link Same issues in this link

My app.js:

// Imports the Google Cloud client library
const {Logging} = require('@google-cloud/logging');
const projectId = 'vendoradminapp';
const logName = 'my-log';
// Creates a client
const logging = new Logging({projectId});
// Selects the log to write to
const log = logging.log(logName);
// The data to write to the log
const text_entry = log.entry('Google Cloud log Entry.....!!! 2');
const message = {
  errorType: 'INFO',
  errorMessage: 'Your setup is not completed fully 2',
};
// The metadata associated with the entry
const metadata = {
  resource: {type: 'global'},
  // See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity
  severity: 'INFO',
};
const json_entry = log.entry(metadata, message);
async function writeLogs() {
  // Asynchronously write the log entry
  await log.write(text_entry);

  // Or let the logging library dispatch the logs
  log.write(json_entry);
}
writeLogs();

my loggin-key.json:

{
  "type": "service_account",
  "project_id": "vendoradminapp",
  "private_key_id": "58175#########f00",
  "private_key": "#####-----BEGIN PRIVATE KEY-----########",
  "client_email": "logging- 
   [email protected]",
  "client_id": "#########",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": 
  "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/logging-quickstart%40vendoradminapp.iam.gserviceaccount.com"
}

I am getting this error Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information

0

There are 0 best solutions below