Class Logging (9.5.7)

[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
NameDescription
options LoggingOptions

Properties

api

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

auth

auth: gax.GoogleAuth;
Property Value
TypeDescription
gax.GoogleAuth

configService

configService?: typeof v2.ConfigServiceV2Client;
Property Value
TypeDescription
typeof v2.ConfigServiceV2Client

detectedResource

detectedResource?: object;
Property Value
TypeDescription
object

loggingService

loggingService?: typeof v2.LoggingServiceV2Client;
Property Value
TypeDescription
typeof v2.LoggingServiceV2Client

options

options: LoggingOptions;
Property Value
TypeDescription
LoggingOptions

projectId

projectId: string;
Property Value
TypeDescription
string

Methods

createSink(name, config)

createSink(name: string, config: CreateSinkRequest): Promise<[Sink, LogSink]>;
Parameters
NameDescription
name string
config CreateSinkRequest
Returns
TypeDescription
Promise<[Sink, LogSink]>

createSink(name, config, callback)

createSink(name: string, config: CreateSinkRequest, callback: CreateSinkCallback): void;
Parameters
NameDescription
name string
config CreateSinkRequest
callback CreateSinkCallback
Returns
TypeDescription
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
NameDescription
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
TypeDescription
Entry

{Entry}

getEntries(options)

getEntries(options?: GetEntriesRequest): Promise<GetEntriesResponse>;
Parameter
NameDescription
options GetEntriesRequest
Returns
TypeDescription
Promise<GetEntriesResponse>

getEntries(callback)

getEntries(callback: GetEntriesCallback): void;
Parameter
NameDescription
callback GetEntriesCallback
Returns
TypeDescription
void

getEntries(options, callback)

getEntries(options: GetEntriesRequest, callback: GetEntriesCallback): void;
Parameters
NameDescription
options GetEntriesRequest
callback GetEntriesCallback
Returns
TypeDescription
void

getEntriesStream(options)

getEntriesStream(options?: GetEntriesRequest): Duplex;

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

Logging#getEntriesStream

Parameter
NameDescription
options GetEntriesRequest
Returns
TypeDescription
Duplex

{ReadableStream} A readable stream that emits Entry instances.

getLogs(options)

getLogs(options?: GetLogsRequest): Promise<GetLogsResponse>;
Parameter
NameDescription
options GetLogsRequest
Returns
TypeDescription
Promise<GetLogsResponse>

getLogs(callback)

getLogs(callback: GetLogsCallback): void;
Parameter
NameDescription
callback GetLogsCallback
Returns
TypeDescription
void

getLogs(options, callback)

getLogs(options: GetLogsRequest, callback: GetLogsCallback): void;
Parameters
NameDescription
options GetLogsRequest
callback GetLogsCallback
Returns
TypeDescription
void

getLogsStream(options)

getLogsStream(options?: GetLogsRequest): Duplex;

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

Logging#getLogsStream

Parameter
NameDescription
options GetLogsRequest
Returns
TypeDescription
Duplex

{ReadableStream} A readable stream that emits Log instances.

getSinks(options)

getSinks(options?: GetSinksRequest): Promise<GetSinksResponse>;
Parameter
NameDescription
options GetSinksRequest
Returns
TypeDescription
Promise<GetSinksResponse>

getSinks(callback)

getSinks(callback: GetSinksCallback): void;
Parameter
NameDescription
callback GetSinksCallback
Returns
TypeDescription
void

getSinks(options, callback)

getSinks(options: GetSinksRequest, callback: GetSinksCallback): void;
Parameters
NameDescription
options GetSinksRequest
callback GetSinksCallback
Returns
TypeDescription
void

getSinksStream(options)

getSinksStream(options: GetSinksRequest): Duplex;

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

Logging#getSinksStream

Parameter
NameDescription
options GetSinksRequest
Returns
TypeDescription
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
NameDescription
name string

Name of the existing log.

options LogOptions

Configuration object.

Returns
TypeDescription
Log

{Log}

logSync(name, transport)

logSync(name: string, transport?: Writable): LogSync;

Get a reference to a Cloud Logging logSync.

Parameters
NameDescription
name string

Name of the existing log.

transport Writable

An optional write stream.

Returns
TypeDescription
LogSync

{LogSync}

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
NameDescription
config RequestConfig

Configuration object.

callback RequestCallback<TResponse>

Callback function.

Returns
TypeDescription
Duplex
Type Parameter
NameDescription
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
NameDescription
config CreateSinkRequest
Returns
TypeDescription
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
NameDescription
config CreateSinkRequest
Returns
TypeDescription
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
NameDescription
config CreateSinkRequest
Returns
TypeDescription
Promise<void>

setDetectedResource()

setDetectedResource(): Promise<void>;

setResource detects and sets a detectedresource object on the Logging instance. It can be invoked once to ensure ensuing LogSync entries contain resource context.

Returns
TypeDescription
Promise<void>

setProjectId(reqOpts)

setProjectId(reqOpts?: {}): Promise<void>;

setProjectId detects and sets a projectId string on the Logging instance. It can be invoked once to ensure ensuing LogSync entries have a projectID.

Parameter
NameDescription
reqOpts {}
Returns
TypeDescription
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
NameDescription
name string

Name of the existing sink.

Returns
TypeDescription
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
NameDescription
options TailEntriesRequest
Returns
TypeDescription
Duplex

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