Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const PKG = require('../../package.json');
const v2 = require('./v2');

import {Entry} from './entry';
import {Log, GetEntriesRequest} from './log';
import {Log, GetEntriesRequest, MonitoredResource, Severity, SeverityNames} from './log';
import {Sink} from './sink';
import {Duplex} from 'stream';
import {AbortableDuplex} from '@google-cloud/common';
Expand All @@ -47,6 +47,25 @@ export interface LoggingOptions extends gax.GoogleAuthOptions {
maxRetries?: number;
}

/**
* For logged errors, one can provide a the service context. For more
* information see [this guide]{@link
* https://cloud.google.com/error-reporting/docs/formatting-error-messages}
* and the [official documentation]{@link
* https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext}.
*/
export interface ServiceContext {
/**
* An identifier of the service, such as the name of the executable, job, or
* Google App Engine service name.
*/
service?: string;
/**
* Represents the version of the service.
*/
version?: string;
}

/**
* @namespace google
*/
Expand Down Expand Up @@ -932,6 +951,8 @@ export {Entry};
* @type {Constructor}
*/
export {Log};
export {Severity};
export {SeverityNames};

/**
* {@link Sink} class.
Expand All @@ -942,6 +963,15 @@ export {Log};
*/
export {Sink};

/**
* {@link MonitoredResource} class.
*
* @name Logging.MonitoredResource
* @see MonitoredResource
* @type {Interface}
*/
export {MonitoredResource};

/**
* The default export of the `@google-cloud/logging` package is the
* {@link Logging} class.
Expand Down
22 changes: 21 additions & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ export interface WriteOptions {
resource?: MonitoredResource;
}

export enum Severity {
emergency,
alert,
critical,
error,
warning,
notice,
info,
debug
}

export type SeverityNames = keyof typeof Severity;

// Mapped types are only supported in type aliases and not in interfaces and
// classes.
type LogSeverityFunctions = {
// FIXME: the following can be made more precise.
[P in SeverityNames]: Function;
};

/**
* 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
Expand All @@ -79,7 +99,7 @@ export interface WriteOptions {
* const logging = new Logging();
* const log = logging.log('syslog');
*/
class Log {
class Log implements LogSeverityFunctions {
formattedName_: string;
removeCircular_: boolean;
logging: Logging;
Expand Down