Class Logging (9.3.1)

[Cloud Logging](https://cloud.google.com/logging/docs) allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS).

[What is Cloud Logging?](https://cloud.google.com/logging/docs) [Introduction to the Cloud Logging API](https://cloud.google.com/logging/docs/api) [Logging to Google Cloud from Bunyan](https://www.npmjs.com/package/@google-cloud/logging-bunyan) [Logging to Google Cloud from Winston](https://www.npmjs.com/package/@google-cloud/logging-winston)

Package

@google-cloud/logging!

Constructors

(constructor)(options)

constructor(options?: LoggingOptions);

Constructs a new instance of the Logging class

Parameter
Name Description
options LoggingOptions

Properties

api

api: {
        [key: string]: gax.ClientStub;
    };
Property Value
Type Description
{ [key: string]: gax.ClientStub; }

auth

auth: gax.GoogleAuth;
Property Value
Type Description
gax.GoogleAuth

configService

configService?: typeof v2.ConfigServiceV2Client;
Property Value
Type Description
typeof v2.ConfigServiceV2Client

detectedResource

detectedResource?: object;
Property Value
Type Description
object

loggingService

loggingService?: typeof v2.LoggingServiceV2Client;
Property Value
Type Description
typeof v2.LoggingServiceV2Client

options

options: LoggingOptions;
Property Value
Type Description
LoggingOptions

projectId

projectId: string;
Property Value
Type Description
string

Methods

createSink(name, config)

createSink(name: string, config: CreateSinkRequest): Promise<[Sink, LogSink]>;
Parameters
Name Description
name string
config CreateSinkRequest
Returns
Type Description
Promise<[Sink, LogSink]>

createSink(name, config, callback)

createSink(name: string, config: CreateSinkRequest, callback: CreateSinkCallback): void;
Parameters
Name Description
name string
config CreateSinkRequest
callback CreateSinkCallback
Returns
Type Description
void

entry(resource, data)

entry(resource?: LogEntry, data?: {} | string): Entry;

Create an entry object.

Using this method will not itself make any API requests. You will use the object returned in other API calls, such as .

Note, [Cloud Logging Quotas and limits]https://cloud.google.com/logging/quotas dictates that the maximum log entry size, including all [LogEntry Resource properties]https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry, cannot exceed _approximately_ 256 KB.

[LogEntry JSON representation]https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry

Parameters
Name Description
resource LogEntry

See a [Monitored Resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/MonitoredResource).

data {} | string

The data to use as the value for this log entry.

Returns
Type Description
Entry

{Entry}

getEntries(options)

getEntries(options?: GetEntriesRequest): Promise<GetEntriesResponse>;
Parameter
Name Description
options GetEntriesRequest
Returns
Type Description
Promise<GetEntriesResponse>

getEntries(callback)

getEntries(callback: GetEntriesCallback): void;
Parameter
Name Description
callback GetEntriesCallback
Returns
Type Description
void

getEntries(options, callback)

getEntries(options: GetEntriesRequest, callback: GetEntriesCallback): void;
Parameters
Name Description
options GetEntriesRequest
callback GetEntriesCallback
Returns
Type Description
void

getEntriesStream(options)

getEntriesStream(options?: GetEntriesRequest): Duplex;

List the Entry objects in your logs as a readable object stream.

Logging#getEntriesStream

Parameter
Name Description
options GetEntriesRequest
Returns
Type Description
Duplex

{ReadableStream} A readable stream that emits Entry instances.

getLogs(options)

getLogs(options?: GetLogsRequest): Promise<GetLogsResponse>;
Parameter
Name Description
options GetLogsRequest
Returns
Type Description
Promise<GetLogsResponse>

getLogs(callback)

getLogs(callback: GetLogsCallback): void;
Parameter
Name Description
callback GetLogsCallback
Returns
Type Description
void

getLogs(options, callback)

getLogs(options: GetLogsRequest, callback: GetLogsCallback): void;
Parameters
Name Description
options GetLogsRequest
callback GetLogsCallback
Returns
Type Description
void

getLogsStream(options)

getLogsStream(options?: GetLogsRequest): Duplex;

List the Log objects in your project as a readable object stream.

Logging#getLogsStream

Parameter
Name Description
options GetLogsRequest
Returns
Type Description
Duplex

{ReadableStream} A readable stream that emits Log instances.

getSinks(options)

getSinks(options?: GetSinksRequest): Promise<GetSinksResponse>;
Parameter
Name Description
options GetSinksRequest
Returns
Type Description
Promise<GetSinksResponse>

getSinks(callback)

getSinks(callback: GetSinksCallback): void;
Parameter
Name Description
callback GetSinksCallback
Returns
Type Description
void

getSinks(options, callback)

getSinks(options: GetSinksRequest, callback: GetSinksCallback): void;
Parameters
Name Description
options GetSinksRequest
callback GetSinksCallback
Returns
Type Description
void

getSinksStream(options)

getSinksStream(options: GetSinksRequest): Duplex;

Get the Sink objects associated with this project as a readable object stream.

Logging#getSinksStream

Parameter
Name Description
options GetSinksRequest
Returns
Type Description
Duplex

{ReadableStream} A readable stream that emits Sink instances.

log(name, options)

log(name: string, options?: LogOptions): Log;

Get a reference to a Cloud Logging log.

[Log Overview]https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.logs

Parameters
Name Description
name string

Name of the existing log.

options LogOptions

Configuration object.

Returns
Type Description
Log

{Log}

request(config, callback)

request<TResponse = any>(config: RequestConfig, callback?: RequestCallback<TResponse>): Duplex;

Funnel all API requests through this method, to be sure we have a project ID.

Parameters
Name Description
config RequestConfig

Configuration object.

callback RequestCallback<TResponse>

Callback function.

Returns
Type Description
Duplex
Type Parameter
Name Description
TResponse

setAclForBucket_(config)

setAclForBucket_(config: CreateSinkRequest): Promise<void>;

This method is called when creating a sink with a Bucket destination. The bucket must first grant proper ACL access to the Cloud Logging account.

The parameters are the same as what accepts.

Parameter
Name Description
config CreateSinkRequest
Returns
Type Description
Promise<void>

setAclForDataset_(config)

setAclForDataset_(config: CreateSinkRequest): Promise<void>;

This method is called when creating a sink with a Dataset destination. The dataset must first grant proper ACL access to the Cloud Logging account.

The parameters are the same as what accepts.

Parameter
Name Description
config CreateSinkRequest
Returns
Type Description
Promise<void>

setAclForTopic_(config)

setAclForTopic_(config: CreateSinkRequest): Promise<void>;

This method is called when creating a sink with a Topic destination. The topic must first grant proper ACL access to the Cloud Logging account.

The parameters are the same as what accepts.

Parameter
Name Description
config CreateSinkRequest
Returns
Type Description
Promise<void>

setProjectId(reqOpts)

setProjectId(reqOpts: {}): Promise<void>;
Parameter
Name Description
reqOpts {}
Returns
Type Description
Promise<void>

sink(name)

sink(name: string): Sink;

Get a reference to a Cloud Logging sink.

[Sink Overview]https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks

Parameter
Name Description
name string

Name of the existing sink.

Returns
Type Description
Sink

{Sink}

tailEntries(options)

tailEntries(options?: TailEntriesRequest): Duplex;

Streaming read of live logs as log entries are ingested. Until the stream is terminated, it will continue reading logs.

Logging#tailEntries

Parameter
Name Description
options TailEntriesRequest
Returns
Type Description
Duplex

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