UNPKG

7.96 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 };
9type 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 Cloud 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 * Boolean flag indicating if "message" field should be used to store structured,
66 * non-text data inside jsonPayload field. This flag applies only when {@link Options#redirectToStdout} is set.
67 * By default this value is true
68 */
69 useMessageField?: boolean;
70}
71/**
72 * This module provides support for streaming your winston logs to
73 * [Cloud Logging](https://cloud.google.com/logging).
74 *
75 * @class
76 *
77 * @param {object} [options]
78 * @param {object} [options.level] The default log level. Winston will filter
79 * messages with a severity lower than this.
80 * @param {object} [options.levels] Custom logging levels as supported by
81 * winston. This list is used to translate your log level to the Cloud
82 * Logging level. Each property should have an integer value between 0 (most
83 * severe) and 7 (least severe). If you are passing a list of levels to your
84 * winston logger, you should provide the same list here.
85 * @param {boolean} [options.inspectMetadata=false] Serialize winston-provided log
86 * metadata using `util.inspect`.
87 * @param {string} [options.logName=winston_log] The name of the log that will receive
88 * messages written to this transport.
89 * @param {object} [options.resource] The monitored resource that the transport
90 * corresponds to. On Google Cloud Platform, this is detected automatically,
91 * but you may optionally specify a specific monitored resource. For more
92 * information see the
93 * [official documentation]{@link
94 * https://cloud.google.com/logging/docs/api/reference/rest/v2/MonitoredResource}.
95 * @param {object} [options.serviceContext] For logged errors, we provide this
96 * as the service context. For more information see
97 * [this guide]{@link
98 * https://cloud.google.com/error-reporting/docs/formatting-error-messages} and
99 * the [official documentation]{@link
100 * https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext}.
101 * @param {string} [options.serviceContext.service] An identifier of the
102 * service, such as the name of the executable, job, or Google App Engine
103 * service name.
104 * @param {string} [options.serviceContext.version] Represents the version of
105 * the service.
106 * @param {string} [options.projectId] The project ID from the Google Cloud
107 * Console, e.g. 'grape-spaceship-123'. We will also check the environment
108 * variable `GCLOUD_PROJECT` for your project ID. If your app is running in
109 * an environment which supports {@link
110 * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
111 * Application Default Credentials}, your project ID will be detected
112 * automatically.
113 * @param {string} [options.keyFilename] Full path to the a .json, .pem, or .p12
114 * key downloaded from the Google Cloud Console. If you provide a path
115 * to a JSON file, the `projectId` option above is not necessary. NOTE: .pem
116 * and .p12 require you to specify the `email` option as well.
117 * @param {string} [options.email] Account email address. Required when using a
118 * .pem or .p12 keyFilename.
119 * @param {object} [options.credentials] Credentials object.
120 * @param {string} [options.credentials.client_email]
121 * @param {string} [options.credentials.private_key]
122 * @param {boolean} [options.autoRetry=true] Automatically retry requests if the
123 * response is related to rate limits or certain intermittent server errors.
124 * We will exponentially backoff subsequent requests by default.
125 * @param {number} [options.maxRetries=3] Maximum number of automatic retries
126 * attempted before returning the error.
127 * @param {constructor} [options.promise] Custom promise module to use instead
128 * of native Promises.
129 *
130 * @example <caption>Import the client library</caption>
131 * const {LoggingWinston} = require('@google-cloud/logging-winston');
132 *
133 * @example <caption>Create a client that uses <a
134 * href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
135 * Default Credentials (ADC)</a>:</caption> const loggingWinston = new
136 * LoggingWinston();
137 *
138 * @example <caption>Create a client with <a
139 * href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
140 * credentials</a>:</caption> const loggingWinston = new LoggingWinston({
141 * projectId: 'your-project-id',
142 * keyFilename: '/path/to/keyfile.json'
143 * });
144 *
145 * @example <caption>include:samples/quickstart.js</caption>
146 * region_tag:logging_winston_quickstart
147 * Full quickstart example:
148 */
149export declare class LoggingWinston extends TransportStream {
150 static readonly LOGGING_TRACE_KEY = "logging.googleapis.com/trace";
151 static readonly LOGGING_SPAN_KEY = "logging.googleapis.com/spanId";
152 static readonly LOGGING_SAMPLED_KEY = "logging.googleapis.com/trace_sampled";
153 common: LoggingCommon;
154 constructor(options?: Options);
155 log(info: any, callback: Callback): void;
156}
157export declare const LOGGING_TRACE_KEY = "logging.googleapis.com/trace";
158export declare const LOGGING_SPAN_KEY = "logging.googleapis.com/spanId";
159export declare const LOGGING_SAMPLED_KEY = "logging.googleapis.com/trace_sampled";