Package @google-cloud/logging



Create an entry object to define new data to insert into a meta.

Note, Cloud Logging Quotas and limits dictates that the maximum log entry size, including all LogEntry Resource properties, cannot exceed approximately 256 KB.

See LogEntry JSON representation


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 is produced by Google Compute Engine.

See Introduction to Logs


Cloud Logging allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS).

See What is Cloud Logging?

See Introduction to the Cloud Logging API

See Logging to Google Cloud from Bunyan

See Logging to Google Cloud from Winston


A logSync is a named collection of entries in structured log format. In Cloud Logging, structured logs refer to log entries that use the jsonPayload field to add structure to their payloads. In most GCP environments, like GKE and Cloud Functions, structured logs written to process.stdout are automatically picked up and formatted by logging agents.

Recommended for Serverless environment logging, especially where async log calls made by the Log class can be dropped by the CPU.

See Structured Logging

Represents a CustomHttpPattern.

Represents a Distribution.

Represents a BucketOptions.

Represents an Explicit.

Represents an Exponential.

Represents a Linear.

Represents an Exemplar.

Represents a Range.

Represents a Http.

Represents a HttpRule.

Represents a LabelDescriptor.

Represents a Metric.

Represents a MetricDescriptor.

Represents a MetricDescriptorMetadata.

Represents a MonitoredResource.

Represents a MonitoredResourceDescriptor.

Represents a MonitoredResourceMetadata.

Represents a ResourceDescriptor.

Represents a ResourceReference.

Represents a HttpRequest.

Represents a BigQueryOptions.

Represents a CmekSettings.

Represents a ConfigServiceV2

Represents a CreateBucketRequest.

Represents a CreateExclusionRequest.

Represents a CreateLogMetricRequest.

Represents a CreateSinkRequest.

Represents a CreateViewRequest.

Represents a DeleteBucketRequest.

Represents a DeleteExclusionRequest.

Represents a DeleteLogMetricRequest.

Represents a DeleteLogRequest.

Represents a DeleteSinkRequest.

Represents a DeleteViewRequest.

Represents a GetBucketRequest.

Represents a GetCmekSettingsRequest.

Represents a GetExclusionRequest.

Represents a GetLogMetricRequest.

Represents a GetSinkRequest.

Represents a GetViewRequest.

Represents a ListBucketsRequest.

Represents a ListBucketsResponse.

Represents a ListExclusionsRequest.

Represents a ListExclusionsResponse.

Represents a ListLogEntriesRequest.

Represents a ListLogEntriesResponse.

Represents a ListLogMetricsRequest.

Represents a ListLogMetricsResponse.

Represents a ListLogsRequest.

Represents a ListLogsResponse.

Represents a ListMonitoredResourceDescriptorsRequest.

Represents a ListMonitoredResourceDescriptorsResponse.

Represents a ListSinksRequest.

Represents a ListSinksResponse.

Represents a ListViewsRequest.

Represents a ListViewsResponse.

Represents a LogBucket.

Represents a LogEntry.

Represents a LogEntryOperation.

Represents a LogEntrySourceLocation.

Represents a LogExclusion.

Represents a LoggingServiceV2

Represents a LogMetric.

Represents a LogSink.

Represents a LogView.

Represents a MetricsServiceV2

Represents a TailLogEntriesRequest.

Represents a TailLogEntriesResponse.

Represents a SuppressionInfo.

Represents an UndeleteBucketRequest.

Represents an UpdateBucketRequest.

Represents an UpdateCmekSettingsRequest.

Represents an UpdateExclusionRequest.

Represents an UpdateLogMetricRequest.

Represents an UpdateSinkRequest.

Represents an UpdateViewRequest.

Represents a WriteLogEntriesPartialErrors.

Represents a WriteLogEntriesRequest.

Represents a WriteLogEntriesResponse.

Represents an Any.

Represents a DescriptorProto.

Represents an ExtensionRange.

Represents a ReservedRange.

Represents a Duration.

Represents an Empty.

Represents an EnumDescriptorProto.

Represents an EnumReservedRange.

Represents an EnumOptions.

Represents an EnumValueDescriptorProto.

Represents an EnumValueOptions.

Represents an ExtensionRangeOptions.

Represents a FieldDescriptorProto.

Represents a FieldMask.

Represents a FieldOptions.

Represents a FileDescriptorProto.

Represents a FileDescriptorSet.

Represents a FileOptions.

Represents a GeneratedCodeInfo.

Represents an Annotation.

Represents a ListValue.

Represents a MessageOptions.

Represents a MethodDescriptorProto.

Represents a MethodOptions.

Represents an OneofDescriptorProto.

Represents an OneofOptions.

Represents a ServiceDescriptorProto.

Represents a ServiceOptions.

Represents a SourceCodeInfo.

Represents a Location.

Represents a Struct.

Represents a Timestamp.

Represents an UninterpretedOption.

Represents a NamePart.

Represents a Value.

Represents a Status.


A sink is an object that lets you to specify a set of log entries to export to a particular destination. Cloud Logging lets you export log entries to destinations including Cloud Storage buckets (for long term log storage), Google BigQuery datasets (for log analysis), Google Pub/Sub (for streaming to other applications).

See Introduction to Sinks













Properties of an Explicit.

Properties of an Exponential.

Properties of a Linear.

Properties of a BucketOptions.

Properties of an Exemplar.

Properties of a Range.

Properties of a CustomHttpPattern.

Properties of a Distribution.

Properties of a Http.

Properties of a HttpRule.

Properties of a LabelDescriptor.

Properties of a Metric.

Properties of a MetricDescriptor.

Properties of a MonitoredResource.

Properties of a MonitoredResourceDescriptor.

Properties of a MonitoredResourceMetadata.

Properties of a ResourceDescriptor.

Properties of a ResourceReference.

Properties of a MetricDescriptorMetadata.

Properties of a HttpRequest.

Properties of a BigQueryOptions.

Properties of a CmekSettings.

Properties of a CreateBucketRequest.

Properties of a CreateExclusionRequest.

Properties of a CreateLogMetricRequest.

Properties of a CreateSinkRequest.

Properties of a CreateViewRequest.

Properties of a DeleteBucketRequest.

Properties of a DeleteExclusionRequest.

Properties of a DeleteLogMetricRequest.

Properties of a DeleteLogRequest.

Properties of a DeleteSinkRequest.

Properties of a DeleteViewRequest.

Properties of a GetBucketRequest.

Properties of a GetCmekSettingsRequest.

Properties of a GetExclusionRequest.

Properties of a GetLogMetricRequest.

Properties of a GetSinkRequest.

Properties of a GetViewRequest.

Properties of a ListBucketsRequest.

Properties of a ListBucketsResponse.

Properties of a ListExclusionsRequest.

Properties of a ListExclusionsResponse.

Properties of a ListLogEntriesRequest.

Properties of a ListLogEntriesResponse.

Properties of a ListLogMetricsRequest.

Properties of a ListLogMetricsResponse.

Properties of a ListLogsRequest.

Properties of a ListLogsResponse.

Properties of a ListMonitoredResourceDescriptorsRequest.

Properties of a ListMonitoredResourceDescriptorsResponse.

Properties of a ListSinksRequest.

Properties of a ListSinksResponse.

Properties of a ListViewsRequest.

Properties of a ListViewsResponse.

Properties of a LogBucket.

Properties of a LogEntry.

Properties of a LogEntryOperation.

Properties of a LogEntrySourceLocation.

Properties of a LogExclusion.

Properties of a LogMetric.

Properties of a LogSink.

Properties of a LogView.

Properties of a TailLogEntriesRequest.

Properties of a TailLogEntriesResponse.

Properties of an UndeleteBucketRequest.

Properties of an UpdateBucketRequest.

Properties of an UpdateCmekSettingsRequest.

Properties of an UpdateExclusionRequest.

Properties of an UpdateLogMetricRequest.

Properties of an UpdateSinkRequest.

Properties of an UpdateViewRequest.

Properties of a WriteLogEntriesPartialErrors.

Properties of a WriteLogEntriesRequest.

Properties of a WriteLogEntriesResponse.

Properties of a SuppressionInfo.

Properties of an ExtensionRange.

Properties of a ReservedRange.

Properties of an EnumReservedRange.

Properties of an Annotation.

Properties of an Any.

Properties of a DescriptorProto.

Properties of a Duration.

Properties of an Empty.

Properties of an EnumDescriptorProto.

Properties of an EnumOptions.

Properties of an EnumValueDescriptorProto.

Properties of an EnumValueOptions.

Properties of an ExtensionRangeOptions.

Properties of a FieldDescriptorProto.

Properties of a FieldMask.

Properties of a FieldOptions.

Properties of a FileDescriptorProto.

Properties of a FileDescriptorSet.

Properties of a FileOptions.

Properties of a GeneratedCodeInfo.

Properties of a ListValue.

Properties of a MessageOptions.

Properties of a MethodDescriptorProto.

Properties of a MethodOptions.

Properties of an OneofDescriptorProto.

Properties of an OneofOptions.

Properties of a ServiceDescriptorProto.

Properties of a ServiceOptions.

Properties of a SourceCodeInfo.

Properties of a Struct.

Properties of a Timestamp.

Properties of an UninterpretedOption.

Properties of a Value.

Properties of a Location.

Properties of a NamePart.

Properties of a Status.




For logged errors, one can provide a the service context. For more information see [this guide] and the [official documentation]



FieldBehavior enum.

ValueType enum.

LaunchStage enum.

MetricKind enum.

ValueType enum.

History enum.

Style enum.

LogSeverity enum.

LifecycleState enum.

ApiVersion enum.

VersionFormat enum.

Reason enum.

Label enum.

Type enum.

CType enum.

JSType enum.

OptimizeMode enum.

IdempotencyLevel enum.

NullValue enum.




v2: any


assignSeverityToEntries(entries, severity)

export declare function assignSeverityToEntries(entries: Entry | Entry[], severity: string): Entry[];

Return an array of log entries with the desired severity assigned.

entriesEntry | Entry[]

Log entries.


The desired severity level.



export declare function detectServiceContext(auth: GoogleAuth): Promise

For logged errors, users can provide a service context. This enables errors to be picked up Cloud Error Reporting. For more information see [this guide] and the [official documentation]

Promise<ServiceContext | null>

formatLogName(projectId, name)

export declare function formatLogName(projectId: string, name: string): string;

Format the name of a log. A log's full name is in the format of 'projects/{projectId}/logs/{logName}'.

string, makeChildLogger, emitRequestLog)

export declare function makeMiddleware

Generates an express middleware that installs a request-specific logger on the request object. It optionally can do HttpRequest timing that can be used for generating request logs. This can be used to integrate with logging libraries such as winston and bunyan.


Generated traceIds will be associated with this project.

makeChildLogger(trace: string, span?: string, traceSampled?: boolean) => LoggerType

A function that generates logger instances that will be installed onto req as req.log. The logger should include the trace in each log entry's metadata (associated with the LOGGING_TRACE_KEY property.

emitRequestLog(httpRequest: CloudLoggingHttpRequest, trace: string, span?: string, traceSampled?: boolean) => void

Optional. A function that will emit a parent request log. While some environments like GAE and GCF emit parent request logs automatically, other environments do not. When provided this function will be called with a populated CloudLoggingHttpRequest which can be emitted as request log.

(req: ServerRequest, res: "\"http\"".ServerResponse, next: Function) => void
Type Parameter

Type Aliases


export declare type Client = string;


export declare type DeleteResponse = google.protobuf.Empty;


export declare type GetEntriesResponse = [Entry[], google.logging.v2.IListLogEntriesRequest, google.logging.v2.IListLogEntriesResponse];


export declare type GetLogsResponse = [Sink[], google.logging.v2.IListLogsRequest, google.logging.v2.IListLogsResponse];


export declare type GetSinksResponse = [Sink[], google.logging.v2.IListSinksRequest, google.logging.v2.IListSinksResponse];


export declare type LogSink = google.logging.v2.ILogSink;


export declare type MonitoredResource = google.api.IMonitoredResource;

type CreateBucketCallback = (error: (Error|null), response?: google.logging.v2.LogBucket) => void;

Callback as used by .

type CreateExclusionCallback = (error: (Error|null), response?: google.logging.v2.LogExclusion) => void;

Callback as used by .

type CreateSinkCallback = (error: (Error|null), response?: google.logging.v2.LogSink) => void;

Callback as used by .

type CreateViewCallback = (error: (Error|null), response?: google.logging.v2.LogView) => void;

Callback as used by .

type DeleteBucketCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type DeleteExclusionCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type DeleteSinkCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type DeleteViewCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type GetBucketCallback = (error: (Error|null), response?: google.logging.v2.LogBucket) => void;

Callback as used by .

type GetCmekSettingsCallback = (error: (Error|null), response?: google.logging.v2.CmekSettings) => void;

Callback as used by .

type GetExclusionCallback = (error: (Error|null), response?: google.logging.v2.LogExclusion) => void;

Callback as used by .

type GetSinkCallback = (error: (Error|null), response?: google.logging.v2.LogSink) => void;

Callback as used by .

type GetViewCallback = (error: (Error|null), response?: google.logging.v2.LogView) => void;

Callback as used by .

type ListBucketsCallback = (error: (Error|null), response?: google.logging.v2.ListBucketsResponse) => void;

Callback as used by .

type ListExclusionsCallback = (error: (Error|null), response?: google.logging.v2.ListExclusionsResponse) => void;

Callback as used by .

type ListSinksCallback = (error: (Error|null), response?: google.logging.v2.ListSinksResponse) => void;

Callback as used by .

type ListViewsCallback = (error: (Error|null), response?: google.logging.v2.ListViewsResponse) => void;

Callback as used by .

type UndeleteBucketCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type UpdateBucketCallback = (error: (Error|null), response?: google.logging.v2.LogBucket) => void;

Callback as used by .

type UpdateCmekSettingsCallback = (error: (Error|null), response?: google.logging.v2.CmekSettings) => void;

Callback as used by .

type UpdateExclusionCallback = (error: (Error|null), response?: google.logging.v2.LogExclusion) => void;

Callback as used by .

type UpdateSinkCallback = (error: (Error|null), response?: google.logging.v2.LogSink) => void;

Callback as used by .

type UpdateViewCallback = (error: (Error|null), response?: google.logging.v2.LogView) => void;

Callback as used by .

type DeleteLogCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type ListLogEntriesCallback = (error: (Error|null), response?: google.logging.v2.ListLogEntriesResponse) => void;

Callback as used by .

type ListLogsCallback = (error: (Error|null), response?: google.logging.v2.ListLogsResponse) => void;

Callback as used by .

type ListMonitoredResourceDescriptorsCallback = (error: (Error|null), response?: google.logging.v2.ListMonitoredResourceDescriptorsResponse) => void;

Callback as used by .

type TailLogEntriesCallback = (error: (Error|null), response?: google.logging.v2.TailLogEntriesResponse) => void;

Callback as used by .

type WriteLogEntriesCallback = (error: (Error|null), response?: google.logging.v2.WriteLogEntriesResponse) => void;

Callback as used by .

type CreateLogMetricCallback = (error: (Error|null), response?: google.logging.v2.LogMetric) => void;

Callback as used by .

type DeleteLogMetricCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type GetLogMetricCallback = (error: (Error|null), response?: google.logging.v2.LogMetric) => void;

Callback as used by .

type ListLogMetricsCallback = (error: (Error|null), response?: google.logging.v2.ListLogMetricsResponse) => void;

Callback as used by .

type UpdateLogMetricCallback = (error: (Error|null), response?: google.logging.v2.LogMetric) => void;

Callback as used by .


export declare type SeverityNames = keyof typeof Severity;