diff --git a/src/index.ts b/src/index.ts index 72d18d29..e4139f44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -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 */ @@ -932,6 +951,8 @@ export {Entry}; * @type {Constructor} */ export {Log}; +export {Severity}; +export {SeverityNames}; /** * {@link Sink} class. @@ -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. diff --git a/src/log.ts b/src/log.ts index b007815c..e42ed73f 100644 --- a/src/log.ts +++ b/src/log.ts @@ -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 @@ -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;