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