Log

Log

A log is a named collection of entries, each entry representing a timestamped event. Logs can be produced by Google Cloud Platform services, by third-party services, or by your applications. For example, the log apache-access is produced by the Apache Web Server, but the log compute.googleapis.com/activity_log is produced by Google Compute Engine.

See Introduction to Logs

Constructor

new Log(logging, name, optionsopt)

Parameters:
Name Type Attributes Description
logging Logging

Logging instance.

name string

Name of the log.

options object <optional>

Configuration object.

Properties
Name Type Attributes Description
removeCircular boolean <optional>

Replace circular references in logged objects with a string value, [Circular]. (Default: false)

maxEntrySize number <optional>

A max entry size

jsonFieldsToTruncate Array.<string> <optional>

A list of JSON properties at the given full path to be truncated. Received values will be prepended to predefined list in the order received and duplicates discarded.

defaultWriteDeleteCallback ApiResponseCallback <optional>

A default global callback to be used for Log#write and Log#delete APIs when ApiResponseCallback callback was not supplied by caller in function parameters. Note that LogOptions#defaultWriteDeleteCallback is useful when Log#write and Log#delete APIs are called without await and without callback added explicitly to every call - this way LogOptions#defaultWriteDeleteCallback can serve as global callback handler, which for example could be used to catch all errors and eliminate crashes.

partialSuccess boolean <optional>

Global flag indicating Whether a batch's valid entries should be written even if some other entry failed due to errors. Default is true. See partialSuccess for more info.

Example
```
import {Logging} from '@google-cloud/logging';
import {LogOptions} from '@google-cloud/logging/build/src/log';
const options: LogOptions = {
  maxEntrySize: 256,
  jsonFieldsToTruncate: [
    'jsonPayload.fields.metadata.structValue.fields.custom.stringValue',
  ],
  defaultWriteDeleteCallback: (err: any) => {
    if (err) {
      console.log('Error: ' + err);
    }
  },
};
const logging = new Logging();
const log = logging.log('syslog', options);
```

Members

defaultWriteDeleteCallback

The default callback for Log#write and Log#delete APIs is going to be used only when LogOptions#defaultWriteDeleteCallback was set by user and only for APIs which does not accept a callback as parameter

name

name

partialSuccess

Turning partialSuccess by default to be true if not provided in options. This should improve overall logging reliability since only oversized entries will be dropped from request. See https://cloud.google.com/logging/quotas#log-limits for more info

Methods

getEntriesStream(queryopt) → {ReadableStream}

This method is a wrapper around {module:logging#getEntriesStream}, but with a filter specified to only return {module:logging/entry} objects from this log.

Parameters:
Name Type Attributes Description
query GetEntriesRequest <optional>

Query object for listing entries.

Returns:
Type Description
ReadableStream

A readable stream that emits Entry instances.

Example
```
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const log = logging.log('my-log');

log.getEntriesStream()
  .on('error', console.error)
  .on('data', entry => {
    // `entry` is a Cloud Logging entry object.
    // See the `data` property to read the data from the entry.
  })
  .on('end', function() {
    // All entries retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
log.getEntriesStream()
  .on('data', function(entry) {
    this.end();
  });
```

tailEntries(queryopt) → {DuplexStream}

This method is a wrapper around {module:logging#tailEntries}, but with a filter specified to only return {module:logging/entry} objects from this log.

Parameters:
Name Type Attributes Description
query TailEntriesRequest <optional>

Query object for tailing entries.

Returns:
Type Description
DuplexStream

A duplex stream that emits TailEntriesResponses containing an array of Entry instances.

Example
```
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const log = logging.log('my-log');

log.tailEntries()
  .on('error', console.error)
  .on('data', resp => {
    console.log(resp.entries);
    console.log(resp.suppressionInfo);
  })
  .on('end', function() {
    // All entries retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
log.tailEntries()
  .on('data', function(entry) {
    this.end();
  });
```