new LoggingBunyan([options])

Examples

Import the client library

const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
<caption>Create a client that uses <a
href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
Default Credentials (ADC)</a>:</caption> const loggingBunyan = new
LoggingBunyan();
<caption>Create a client with <a
href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
credentials</a>:</caption> const loggingBunyan = new LoggingBunyan({
  projectId: 'your-project-id',
  keyFilename: '/path/to/keyfile.json'
});

include:samples/quickstart.js

region_tag:logging_bunyan_quickstart
Full quickstart example:

Parameters

Name Type Optional Description

options

 

Yes

Values in options have the following properties:

Name Type Optional Description

logName

 

Yes

The name of the log that will receive messages written to this bunyan stream. Default: bunyan_Log.

resource

 

Yes

The monitored resource that the log stream corresponds to. On Google Cloud Platform, this is detected automatically, but you may optionally specify a specific monitored resource. For more information, see the official documentation

serviceContext

 

Yes

For logged errors, we provide this as the service context. For more information see this guide and the official documentation.

serviceContext.service

 

Yes

An identifier of the service, such as the name of the executable, job, or Google App Engine service name.

serviceContext.version

 

Yes

Represents the version of the service.

projectId

 

Yes

The project ID from the Google Cloud Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

keyFilename

 

Yes

Full path to the a .json, .pem, or .p12 key downloaded from the Google Cloud Console. If you provide a path to a JSON file, the projectId option above is not necessary. NOTE: .pem and .p12 require you to specify the email option as well.

email

 

Yes

Account email address. Required when using a .pem or .p12 keyFilename.

credentials

 

Yes

Credentials object.

credentials.client_email

 

Yes

credentials.private_key

 

Yes

autoRetry

 

Yes

Automatically retry requests if the response is related to rate limits or certain intermittent server errors. We will exponentially backoff subsequent requests by default.

Defaults to true.

maxRetries

 

Yes

Maximum number of automatic retries attempted before returning the error.

Defaults to 3.

promise

 

Yes

Custom promise module to use instead of native Promises.

Property

static

LOGGING_TRACE_KEY  string

Value: logging.googleapis.com/trace

Methods

_write()

Relay a log entry to the logging agent. This is called by bunyan through Writable#write.

_writev()

Relay an array of log entries to the logging agent. This is called by bunyan through Writable#write.

formatEntry_()

Format a bunyan record into a Stackdriver log entry.

stream()

Convenience method that Builds a bunyan stream object that you can put in the bunyan streams list.