UNPKG

7.7 kBTypeScriptView Raw
1import TransportStream = require('winston-transport');
2import { LoggingCommon, getCurrentTraceFromAgent } from './common';
3import * as express from './middleware/express';
4import { getDefaultMetadataForTracing } from './default-metadata';
5import { MonitoredResource, ServiceContext, LoggingOptions } from '@google-cloud/logging';
6export { express };
7export { getDefaultMetadataForTracing };
8export { getCurrentTraceFromAgent };
9declare type Callback = (err: Error | null, apiResponse?: {}) => void;
10export interface Options extends LoggingOptions {
11 /**
12 * The default log level. Winston will filter messages with a severity lower
13 * than this.
14 */
15 level?: string;
16 /**
17 * Custom logging levels as supported by winston. This list is used to
18 * translate your log level to the Stackdriver Logging level. Each property
19 * should have an integer value between 0 (most severe) and 7 (least severe).
20 * If you are passing a list of levels to your winston logger, you should
21 * provide the same list here.
22 */
23 levels?: {
24 [name: string]: number;
25 };
26 /**
27 * Serialize winston-provided log metadata using `util.inspect`.
28 */
29 inspectMetadata?: boolean;
30 /**
31 * The name of the log that will receive messages written to this transport.
32 */
33 logName?: string;
34 /**
35 * The monitored resource that the transport corresponds to. On Google Cloud
36 * Platform, this is detected automatically, but you may optionally specify a
37 * specific monitored resource. For more information see the
38 * [official documentation]{@link
39 * https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource}.
40 */
41 resource?: MonitoredResource;
42 /**
43 * For logged errors, we provide this as the service context. For more
44 * information see [this guide]{@link
45 * https://cloud.google.com/error-reporting/docs/formatting-error-messages}
46 * and the [official documentation]{@link
47 * https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext}.
48 */
49 serviceContext?: ServiceContext;
50 logname?: string;
51 prefix?: string;
52 labels?: {
53 [key: string]: string;
54 };
55 maxEntrySize?: number;
56 defaultCallback?: Callback;
57 /**
58 * Boolen flag that opts-in redirecting the output to STDOUT instead of ingesting logs to Cloud
59 * Logging using Logging API. Defaults to {@code false}. Redirecting logs can be used in
60 * Google Cloud environments with installed logging agent to delegate log ingestions to the
61 * agent. Redirected logs are formatted as one line Json string following the structured logging guidelines.
62 */
63 redirectToStdout?: boolean;
64}
65/**
66 * This module provides support for streaming your winston logs to
67 * [Stackdriver Logging](https://cloud.google.com/logging).
68 *
69 * @class
70 *
71 * @param {object} [options]
72 * @param {object} [options.level] The default log level. Winston will filter
73 * messages with a severity lower than this.
74 * @param {object} [options.levels] Custom logging levels as supported by
75 * winston. This list is used to translate your log level to the Stackdriver
76 * Logging level. Each property should have an integer value between 0 (most
77 * severe) and 7 (least severe). If you are passing a list of levels to your
78 * winston logger, you should provide the same list here.
79 * @param {boolean} [options.inspectMetadata=false] Serialize winston-provided log
80 * metadata using `util.inspect`.
81 * @param {string} [options.logName=winston_log] The name of the log that will receive
82 * messages written to this transport.
83 * @param {object} [options.resource] The monitored resource that the transport
84 * corresponds to. On Google Cloud Platform, this is detected automatically,
85 * but you may optionally specify a specific monitored resource. For more
86 * information see the
87 * [official documentation]{@link
88 * https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource}.
89 * @param {object} [options.serviceContext] For logged errors, we provide this
90 * as the service context. For more information see
91 * [this guide]{@link
92 * https://cloud.google.com/error-reporting/docs/formatting-error-messages} and
93 * the [official documentation]{@link
94 * https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext}.
95 * @param {string} [options.serviceContext.service] An identifier of the
96 * service, such as the name of the executable, job, or Google App Engine
97 * service name.
98 * @param {string} [options.serviceContext.version] Represents the version of
99 * the service.
100 * @param {string} [options.projectId] The project ID from the Google Cloud
101 * Console, e.g. 'grape-spaceship-123'. We will also check the environment
102 * variable `GCLOUD_PROJECT` for your project ID. If your app is running in
103 * an environment which supports {@link
104 * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
105 * Application Default Credentials}, your project ID will be detected
106 * automatically.
107 * @param {string} [options.keyFilename] Full path to the a .json, .pem, or .p12
108 * key downloaded from the Google Cloud Console. If you provide a path
109 * to a JSON file, the `projectId` option above is not necessary. NOTE: .pem
110 * and .p12 require you to specify the `email` option as well.
111 * @param {string} [options.email] Account email address. Required when using a
112 * .pem or .p12 keyFilename.
113 * @param {object} [options.credentials] Credentials object.
114 * @param {string} [options.credentials.client_email]
115 * @param {string} [options.credentials.private_key]
116 * @param {boolean} [options.autoRetry=true] Automatically retry requests if the
117 * response is related to rate limits or certain intermittent server errors.
118 * We will exponentially backoff subsequent requests by default.
119 * @param {number} [options.maxRetries=3] Maximum number of automatic retries
120 * attempted before returning the error.
121 * @param {constructor} [options.promise] Custom promise module to use instead
122 * of native Promises.
123 *
124 * @example <caption>Import the client library</caption>
125 * const {LoggingWinston} = require('@google-cloud/logging-winston');
126 *
127 * @example <caption>Create a client that uses <a
128 * href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
129 * Default Credentials (ADC)</a>:</caption> const loggingWinston = new
130 * LoggingWinston();
131 *
132 * @example <caption>Create a client with <a
133 * href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
134 * credentials</a>:</caption> const loggingWinston = new LoggingWinston({
135 * projectId: 'your-project-id',
136 * keyFilename: '/path/to/keyfile.json'
137 * });
138 *
139 * @example <caption>include:samples/quickstart.js</caption>
140 * region_tag:logging_winston_quickstart
141 * Full quickstart example:
142 */
143export declare class LoggingWinston extends TransportStream {
144 static readonly LOGGING_TRACE_KEY = "logging.googleapis.com/trace";
145 static readonly LOGGING_SPAN_KEY = "logging.googleapis.com/spanId";
146 static readonly LOGGING_SAMPLED_KEY = "logging.googleapis.com/trace_sampled";
147 common: LoggingCommon;
148 constructor(options?: Options);
149 log(info: any, callback: Callback): void;
150}
151export declare const LOGGING_TRACE_KEY = "logging.googleapis.com/trace";
152export declare const LOGGING_SPAN_KEY = "logging.googleapis.com/spanId";
153export declare const LOGGING_SAMPLED_KEY = "logging.googleapis.com/trace_sampled";