1 | /*!
|
2 | * Copyright 2015 Google Inc. All Rights Reserved.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | /// <reference types="node" />
|
17 | import * as gax from 'google-gax';
|
18 | import * as middleware from './middleware';
|
19 | import { detectServiceContext } from './utils/metadata';
|
20 | import { CloudLoggingHttpRequest as HttpRequest } from './utils/http-request';
|
21 | export { middleware };
|
22 | export { HttpRequest };
|
23 | export { detectServiceContext };
|
24 | declare const v2: any;
|
25 | import { Entry, LogEntry } from './entry';
|
26 | import { MonitoredResource, Severity, SeverityNames, formatLogName, assignSeverityToEntries } from './utils/log-common';
|
27 | import { Log, GetEntriesRequest, TailEntriesRequest, LogOptions } from './log';
|
28 | import { LogSync } from './log-sync';
|
29 | import { Sink } from './sink';
|
30 | import { Duplex, Writable } from 'stream';
|
31 | import { google } from '../protos/protos';
|
32 | export interface LoggingOptions extends gax.GrpcClientOptions {
|
33 | autoRetry?: boolean;
|
34 | maxRetries?: number;
|
35 | apiEndpoint?: string;
|
36 | }
|
37 | export interface DeleteCallback {
|
38 | (error?: Error | null, response?: google.protobuf.Empty): void;
|
39 | }
|
40 | export declare type DeleteResponse = google.protobuf.Empty;
|
41 | export declare type LogSink = google.logging.v2.ILogSink;
|
42 | export interface AbortableDuplex extends Duplex {
|
43 | abort(): void;
|
44 | }
|
45 | export interface CreateSinkRequest {
|
46 | destination: any;
|
47 | filter?: string;
|
48 | includeChildren?: boolean;
|
49 | name?: string;
|
50 | outputVersionFormat?: google.logging.v2.LogSink.VersionFormat;
|
51 | uniqueWriterIdentity?: string | boolean;
|
52 | gaxOptions?: gax.CallOptions;
|
53 | }
|
54 | export interface CreateSinkCallback {
|
55 | (err: Error | null, sink?: Sink | null, resp?: LogSink): void;
|
56 | }
|
57 | export declare type GetEntriesResponse = [Entry[], google.logging.v2.IListLogEntriesRequest, google.logging.v2.IListLogEntriesResponse];
|
58 | export interface GetEntriesCallback {
|
59 | (err: Error | null, entries?: Entry[], request?: google.logging.v2.IListLogEntriesRequest, apiResponse?: google.logging.v2.IListLogEntriesResponse): void;
|
60 | }
|
61 | export interface TailEntriesResponse {
|
62 | entries: Entry[];
|
63 | suppressionInfo: google.logging.v2.TailLogEntriesResponse.SuppressionInfo;
|
64 | }
|
65 | export interface GetLogsRequest {
|
66 | autoPaginate?: boolean;
|
67 | gaxOptions?: gax.CallOptions;
|
68 | maxApiCalls?: number;
|
69 | maxResults?: number;
|
70 | pageSize?: number;
|
71 | pageToken?: string;
|
72 | }
|
73 | export declare type GetLogsResponse = [Sink[], google.logging.v2.IListLogsRequest, google.logging.v2.IListLogsResponse];
|
74 | export interface GetLogsCallback {
|
75 | (err: Error | null, entries?: Sink[], request?: google.logging.v2.IListLogsRequest, apiResponse?: google.logging.v2.IListLogsResponse): void;
|
76 | }
|
77 | export interface GetSinksRequest {
|
78 | autoPaginate?: boolean;
|
79 | gaxOptions?: gax.CallOptions;
|
80 | maxApiCalls?: number;
|
81 | maxResults?: number;
|
82 | pageSize?: number;
|
83 | pageToken?: string;
|
84 | }
|
85 | export declare type GetSinksResponse = [Sink[], google.logging.v2.IListSinksRequest, google.logging.v2.IListSinksResponse];
|
86 | export interface GetSinksCallback {
|
87 | (err: Error | null, entries?: Sink[], request?: google.logging.v2.IListSinksRequest, apiResponse?: google.logging.v2.IListSinksResponse): void;
|
88 | }
|
89 | export declare type Client = string;
|
90 | export interface RequestConfig {
|
91 | client: Client;
|
92 | method: string;
|
93 | reqOpts?: object;
|
94 | gaxOpts?: gax.CallOptions;
|
95 | }
|
96 | export interface RequestCallback<TResponse> {
|
97 | (err: Error | null, res?: TResponse): void;
|
98 | }
|
99 | /**
|
100 | * For logged errors, one can provide a the service context. For more
|
101 | * information see [this guide]{@link
|
102 | * https://cloud.google.com/error-reporting/docs/formatting-error-messages}
|
103 | * and the [official documentation]{@link
|
104 | * https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext}.
|
105 | */
|
106 | export interface ServiceContext {
|
107 | /**
|
108 | * An identifier of the service, such as the name of the executable, job, or
|
109 | * Google App Engine service name.
|
110 | */
|
111 | service?: string;
|
112 | /**
|
113 | * Represents the version of the service.
|
114 | */
|
115 | version?: string;
|
116 | }
|
117 | /**
|
118 | * @typedef {object} ClientConfig
|
119 | * @property {string} [projectId] The project ID from the Google Developer's
|
120 | * Console, e.g. 'grape-spaceship-123'. We will also check the environment
|
121 | * variable `GCLOUD_PROJECT` for your project ID. If your app is running in
|
122 | * an environment which supports {@link
|
123 | * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
|
124 | * Application Default Credentials}, your project ID will be detected
|
125 | * automatically.
|
126 | * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key
|
127 | * downloaded from the Google Developers Console. If you provide a path to a
|
128 | * JSON file, the `projectId` option above is not necessary. NOTE: .pem and
|
129 | * .p12 require you to specify the `email` option as well.
|
130 | * @property {string} [email] Account email address. Required when using a .pem
|
131 | * or .p12 keyFilename.
|
132 | * @property {object} [credentials] Credentials object.
|
133 | * @property {string} [credentials.client_email]
|
134 | * @property {string} [credentials.private_key]
|
135 | * @property {boolean} [autoRetry=true] Automatically retry requests if the
|
136 | * response is related to rate limits or certain intermittent server errors.
|
137 | * We will exponentially backoff subsequent requests by default.
|
138 | * @property {number} [maxRetries=3] Maximum number of automatic retries
|
139 | * attempted before returning the error.
|
140 | * @property {Constructor} [promise] Custom promise module to use instead of
|
141 | * native Promises.
|
142 | */
|
143 | /**
|
144 | * {@link https://cloud.google.com/logging/docs| Cloud Logging} allows you to
|
145 | * store, search, analyze, monitor, and alert on log data and events from Google
|
146 | * Cloud Platform and Amazon Web Services (AWS).
|
147 | *
|
148 | * @class
|
149 | *
|
150 | * See {@link https://cloud.google.com/logging/docs| What is Cloud Logging?}
|
151 | *
|
152 | * See {@link https://cloud.google.com/logging/docs/api| Introduction to the Cloud Logging API}
|
153 | *
|
154 | * See {@link https://www.npmjs.com/package/@google-cloud/logging-bunyan| Logging to Google Cloud from Bunyan}
|
155 | *
|
156 | * See {@link https://www.npmjs.com/package/@google-cloud/logging-winston| Logging to Google Cloud from Winston}
|
157 | *
|
158 | * @param {ClientConfig} [options] Configuration options.
|
159 | *
|
160 | * @example Import the client library
|
161 | * ```
|
162 | * const {Logging} = require('@google-cloud/logging');
|
163 | *
|
164 | * ```
|
165 | * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
|
166 | * ```
|
167 | * const logging = new Logging();
|
168 | *
|
169 | * ```
|
170 | * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicitcredentials</a>:
|
171 | * ```
|
172 | * const logging = new Logging({ projectId:
|
173 | * 'your-project-id', keyFilename: '/path/to/keyfile.json'
|
174 | * });
|
175 | *
|
176 | * ```
|
177 | * @example <caption>include:samples/quickstart.js</caption>
|
178 | * region_tag:logging_quickstart
|
179 | * Full quickstart example:
|
180 | */
|
181 | declare class Logging {
|
182 | api: {
|
183 | [key: string]: gax.ClientStub;
|
184 | };
|
185 | auth: gax.GoogleAuth;
|
186 | options: LoggingOptions;
|
187 | projectId: string;
|
188 | detectedResource?: object;
|
189 | configService?: typeof v2.ConfigServiceV2Client;
|
190 | loggingService?: typeof v2.LoggingServiceV2Client;
|
191 | constructor(options?: LoggingOptions);
|
192 | /**
|
193 | * Config to set for the sink. Not all available options are listed here, see
|
194 | * the [Sink
|
195 | * resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks#LogSink)
|
196 | * definition for full details.
|
197 | *
|
198 | * {object} CreateSinkRequest
|
199 | * {object} [gaxOptions] Request configuration options, outlined
|
200 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
201 | * {Bucket|Dataset|Topic} [destination] The destination. The proper ACL
|
202 | * scopes will be granted to the provided destination. Can be one of:
|
203 | * {//googleapis.dev/nodejs/storage/latest/ Bucket},
https: |
204 | * {//googleapis.dev/nodejs/bigquery/latest/ Dataset}, or
https: |
205 | * {//googleapis.dev/nodejs/pubsub/latest/ Topic}
https: |
206 | * string} [filter] An advanced logs filter. Only log entries
{ |
207 | * matching the filter are written.
|
208 | * string|boolean} [uniqueWriterIdentity] Determines the kind of IAM
{ |
209 | * identity returned as `writerIdentity` in the new sink. See { https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/create#query-parameters}.
|
210 | */
|
211 | /**
|
212 | * @typedef {array} CreateSinkResponse
|
213 | * @property {Sink} 0 The new {@link Sink}.
|
214 | * @property {object} 1 The full API response.
|
215 | */
|
216 | /**
|
217 | * @callback CreateSinkCallback
|
218 | * @param {?Error} err Request error, if any.
|
219 | * @param {Sink} sink The new {@link Sink}.
|
220 | * @param {object} apiResponse The full API response.
|
221 | */
|
222 | createSink(name: string, config: CreateSinkRequest): Promise<[Sink, LogSink]>;
|
223 | createSink(name: string, config: CreateSinkRequest, callback: CreateSinkCallback): void;
|
224 | /**
|
225 | * Create an entry object.
|
226 | *
|
227 | * Using this method will not itself make any API requests. You will use
|
228 | * the object returned in other API calls, such as
|
229 | * {@link Log#write}.
|
230 | *
|
231 | * Note, {@link https://cloud.google.com/logging/quotas|Cloud Logging Quotas and limits}
|
232 | * dictates that the maximum log entry size, including all
|
233 | * [LogEntry Resource properties]{@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry},
|
234 | * cannot exceed _approximately_ 256 KB.
|
235 | *
|
236 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry|LogEntry JSON representation}
|
237 | *
|
238 | * @param {?object|?string} [resource] See a
|
239 | * [Monitored
|
240 | * Resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/MonitoredResource).
|
241 | * @param {object|string} data The data to use as the value for this log
|
242 | * entry.
|
243 | * @returns {Entry}
|
244 | *
|
245 | * @example
|
246 | * ```
|
247 | * const {Logging} = require('@google-cloud/logging');
|
248 | * const logging = new Logging();
|
249 | *
|
250 | * const resource = {
|
251 | * type: 'gce_instance',
|
252 | * labels: {
|
253 | * zone: 'global',
|
254 | * instance_id: '3'
|
255 | * }
|
256 | * };
|
257 | *
|
258 | * const entry = logging.entry(resource, {
|
259 | * delegate: 'my_username'
|
260 | * });
|
261 | *
|
262 | * entry.toJSON();
|
263 | * // {
|
264 | * // resource: {
|
265 | * // type: 'gce_instance',
|
266 | * // labels: {
|
267 | * // zone: 'global',
|
268 | * // instance_id: '3'
|
269 | * // }
|
270 | * // },
|
271 | * // jsonPayload: {
|
272 | * // delegate: 'my_username'
|
273 | * // }
|
274 | * // }
|
275 | * ```
|
276 | */
|
277 | entry(resource?: LogEntry, data?: {} | string): Entry;
|
278 | /**
|
279 | * Query object for listing entries.
|
280 | *
|
281 | * @typedef {object} GetEntriesRequest
|
282 | * @property {boolean} [autoPaginate=true] Have pagination handled
|
283 | * automatically.
|
284 | * @property {string} [filter] An
|
285 | * [advanced logs
|
286 | * filter](https://cloud.google.com/logging/docs/view/advanced_filters). An
|
287 | * empty filter matches all log entries.
|
288 | * @property {object} [gaxOptions] Request configuration options, outlined
|
289 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
290 | * @property {string} [log] A name of the log specifying to pnly return
|
291 | * entries from this log.
|
292 | * @property {number} [maxApiCalls] Maximum number of API calls to make.
|
293 | * @property {number} [maxResults] Maximum number of items plus prefixes to
|
294 | * return.
|
295 | * @property {string} [orderBy] How the results should be sorted,
|
296 | * `timestamp asc` (oldest first) and `timestamp desc` (newest first,
|
297 | * **default**).
|
298 | * @property {number} [pageSize] Maximum number of logs to return.
|
299 | * @property {string} [pageToken] A previously-returned page token
|
300 | * representing part of the larger set of results to view.
|
301 | */
|
302 | /**
|
303 | * @typedef {array} GetEntriesResponse
|
304 | * @property {Entry[]} 0 Array of {@link Entry} instances.
|
305 | * @property {object} 1 The full API request.
|
306 | * @property {object} 2 The full API response.
|
307 | */
|
308 | /**
|
309 | * @callback GetEntriesCallback
|
310 | * @param {?Error} err Request error, if any.
|
311 | * @param {Entry[]} entries Array of {@link Entry} instances.
|
312 | * @param {object} apiResponse The full API response.
|
313 | */
|
314 | /**
|
315 | * List the entries in your logs.
|
316 | *
|
317 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list|entries.list API Documentation}
|
318 | *
|
319 | * @param {GetEntriesRequest} [query] Query object for listing entries.
|
320 | * @param {GetEntriesCallback} [callback] Callback function.
|
321 | * @returns {Promise<GetEntriesResponse>}
|
322 | *
|
323 | * @example
|
324 | * ```
|
325 | * const {Logging} = require('@google-cloud/logging');
|
326 | * const logging = new Logging();
|
327 | *
|
328 | * logging.getEntries((err, entries) => {
|
329 | * // `entries` is an array of Cloud Logging entry objects.
|
330 | * // See the `data` property to read the data from the entry.
|
331 | * });
|
332 | *
|
333 | * //-
|
334 | * // To control how many API requests are made and page through the results
|
335 | * // manually, set `autoPaginate` to `false`.
|
336 | * //-
|
337 | * function callback(err, entries, nextQuery, apiResponse) {
|
338 | * if (nextQuery) {
|
339 | * // More results exist.
|
340 | * logging.getEntries(nextQuery, callback);
|
341 | * }
|
342 | * }
|
343 | *
|
344 | * logging.getEntries({
|
345 | * autoPaginate: false
|
346 | * }, callback);
|
347 | *
|
348 | * //-
|
349 | * // If the callback is omitted, we'll return a Promise.
|
350 | * //-
|
351 | * logging.getEntries().then(data => {
|
352 | * const entries = data[0];
|
353 | * });
|
354 | *
|
355 | * ```
|
356 | * @example <caption>include:samples/logs.js</caption>
|
357 | * region_tag:logging_list_log_entries
|
358 | * Another example:
|
359 | *
|
360 | * @example <caption>include:samples/logs.js</caption>
|
361 | * region_tag:logging_list_log_entries_advanced
|
362 | * Another example:
|
363 | */
|
364 | getEntries(options?: GetEntriesRequest): Promise<GetEntriesResponse>;
|
365 | getEntries(callback: GetEntriesCallback): void;
|
366 | getEntries(options: GetEntriesRequest, callback: GetEntriesCallback): void;
|
367 | /**
|
368 | * List the {@link Entry} objects in your logs as a readable object
|
369 | * stream.
|
370 | *
|
371 | * @method Logging#getEntriesStream
|
372 | * @param {GetEntriesRequest} [query] Query object for listing entries.
|
373 | * @returns {ReadableStream} A readable stream that emits {@link Entry}
|
374 | * instances.
|
375 | *
|
376 | * @example
|
377 | * ```
|
378 | * const {Logging} = require('@google-cloud/logging');
|
379 | * const logging = new Logging();
|
380 | *
|
381 | * logging.getEntriesStream()
|
382 | * .on('error', console.error)
|
383 | * .on('data', entry => {
|
384 | * // `entry` is a Cloud Logging entry object.
|
385 | * // See the `data` property to read the data from the entry.
|
386 | * })
|
387 | * .on('end', function() {
|
388 | * // All entries retrieved.
|
389 | * });
|
390 | *
|
391 | * //-
|
392 | * // If you anticipate many results, you can end a stream early to prevent
|
393 | * // unnecessary processing and API requests.
|
394 | * //-
|
395 | * logging.getEntriesStream()
|
396 | * .on('data', function(entry) {
|
397 | * this.end();
|
398 | * });
|
399 | * ```
|
400 | */
|
401 | getEntriesStream(options?: GetEntriesRequest): Duplex;
|
402 | /**
|
403 | * Query object for streaming entries.
|
404 | *
|
405 | * @typedef {object} TailEntriesRequest
|
406 | * @property {Array.<string>|string} [resourceNames] Names of project
|
407 | * resources to stream logs out of.
|
408 | * @property {string} [filter] An
|
409 | * [advanced logs
|
410 | * filter](https://cloud.google.com/logging/docs/view/advanced_filters). An
|
411 | * empty filter matches all log entries.
|
412 | * @property {number} [bufferWindow=2] A setting to balance the tradeoff
|
413 | * between viewing the log entries as they are being written and viewing
|
414 | * them in ascending order.
|
415 | * @property {string} [log] A name of the log specifying to only return
|
416 | * entries from this log.
|
417 | * @property {object} [gaxOptions] Request configuration options, outlined
|
418 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
419 | */
|
420 | /**
|
421 | * Streaming read of live logs as log entries are ingested. Until the stream
|
422 | * is terminated, it will continue reading logs.
|
423 | *
|
424 | * @method Logging#tailEntries
|
425 | * @param {TailEntriesRequest} [query] Query object for tailing entries.
|
426 | * @returns {DuplexStream} A duplex stream that emits TailEntriesResponses
|
427 | * containing an array of {@link Entry} instances.
|
428 | *
|
429 | * @example
|
430 | * ```
|
431 | * const {Logging} = require('@google-cloud/logging');
|
432 | * const logging = new Logging();
|
433 | *
|
434 | * logging.tailEntries()
|
435 | * .on('error', console.error)
|
436 | * .on('data', resp => {
|
437 | * console.log(resp.entries);
|
438 | * console.log(resp.suppressionInfo);
|
439 | * })
|
440 | * .on('end', function() {
|
441 | * // All entries retrieved.
|
442 | * });
|
443 | *
|
444 | * //-
|
445 | * // If you anticipate many results, you can end a stream early to prevent
|
446 | * // unnecessary processing and API requests.
|
447 | * //-
|
448 | * logging.getEntriesStream()
|
449 | * .on('data', function(entry) {
|
450 | * this.end();
|
451 | * });
|
452 | * ```
|
453 | */
|
454 | tailEntries(options?: TailEntriesRequest): Duplex;
|
455 | /**
|
456 | * Query object for listing entries.
|
457 | *
|
458 | * @typedef {object} GetLogsRequest
|
459 | * @property {boolean} [autoPaginate=true] Have pagination handled
|
460 | * automatically.
|
461 | * @property {object} [gaxOptions] Request configuration options, outlined
|
462 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
463 | * @property {number} [maxApiCalls] Maximum number of API calls to make.
|
464 | * @property {number} [maxResults] Maximum number of items plus prefixes to
|
465 | * return.
|
466 | * @property {number} [pageSize] Maximum number of logs to return.
|
467 | * @property {string} [pageToken] A previously-returned page token
|
468 | * representing part of the larger set of results to view.
|
469 | */
|
470 | /**
|
471 | * @typedef {array} GetLogsResponse
|
472 | * @property {Log[]} 0 Array of {@link Log} instances.
|
473 | * @property {object} 1 The full API request.
|
474 | * @property {object} 2 The full API response.
|
475 | */
|
476 | /**
|
477 | * @callback GetLogsCallback
|
478 | * @param {?Error} err Request error, if any.
|
479 | * @param {Log[]} logs Array of {@link Log} instances.
|
480 | * @param {object} apiResponse The full API response.
|
481 | */
|
482 | /**
|
483 | * List the entries in your logs.
|
484 | *
|
485 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/logs/list|logs.list API Documentation}
|
486 | *
|
487 | * @param {GetLogsRequest} [query] Query object for listing entries.
|
488 | * @param {GetLogsCallback} [callback] Callback function.
|
489 | * @returns {Promise<GetLogsResponse>}
|
490 | *
|
491 | * @example
|
492 | * ```
|
493 | * const {Logging} = require('@google-cloud/logging');
|
494 | * const logging = new Logging();
|
495 | *
|
496 | * logging.getLogs((err, logs) => {
|
497 | * // `logs` is an array of Cloud Logging log objects.
|
498 | * });
|
499 | *
|
500 | * //-
|
501 | * // To control how many API requests are made and page through the results
|
502 | * // manually, set `autoPaginate` to `false`.
|
503 | * //-
|
504 | * function callback(err, entries, nextQuery, apiResponse) {
|
505 | * if (nextQuery) {
|
506 | * // More results exist.
|
507 | * logging.getLogs(nextQuery, callback);
|
508 | * }
|
509 | * }
|
510 | *
|
511 | * logging.getLogs({
|
512 | * autoPaginate: false
|
513 | * }, callback);
|
514 | *
|
515 | * //-
|
516 | * // If the callback is omitted, we'll return a Promise.
|
517 | * //-
|
518 | * logging.getLogs().then(data => {
|
519 | * const entries = data[0];
|
520 | * });
|
521 | *
|
522 | * ```
|
523 | * @example <caption>include:samples/logs.js</caption>
|
524 | * region_tag:logging_list_logs
|
525 | * Another example:
|
526 | */
|
527 | getLogs(options?: GetLogsRequest): Promise<GetLogsResponse>;
|
528 | getLogs(callback: GetLogsCallback): void;
|
529 | getLogs(options: GetLogsRequest, callback: GetLogsCallback): void;
|
530 | /**
|
531 | * List the {@link Log} objects in your project as a readable object stream.
|
532 | *
|
533 | * @method Logging#getLogsStream
|
534 | * @param {GetLogsRequest} [query] Query object for listing entries.
|
535 | * @returns {ReadableStream} A readable stream that emits {@link Log}
|
536 | * instances.
|
537 | *
|
538 | * @example
|
539 | * ```
|
540 | * const {Logging} = require('@google-cloud/logging');
|
541 | * const logging = new Logging();
|
542 | *
|
543 | * logging.getLogsStream()
|
544 | * .on('error', console.error)
|
545 | * .on('data', log => {
|
546 | * // `log` is a Cloud Logging log object.
|
547 | * })
|
548 | * .on('end', function() {
|
549 | * // All logs retrieved.
|
550 | * });
|
551 | *
|
552 | * //-
|
553 | * // If you anticipate many results, you can end a stream early to prevent
|
554 | * // unnecessary processing and API requests.
|
555 | * //-
|
556 | * logging.getLogsStream()
|
557 | * .on('data', log => {
|
558 | * this.end();
|
559 | * });
|
560 | * ```
|
561 | */
|
562 | getLogsStream(options?: GetLogsRequest): Duplex;
|
563 | /**
|
564 | * Query object for listing sinks.
|
565 | *
|
566 | * @typedef {object} GetSinksRequest
|
567 | * @property {boolean} [autoPaginate=true] Have pagination handled
|
568 | * automatically.
|
569 | * @property {object} [gaxOptions] Request configuration options, outlined
|
570 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
571 | * @property {number} [maxApiCalls] Maximum number of API calls to make.
|
572 | * @property {number} [maxResults] Maximum number of items plus prefixes to
|
573 | * return.
|
574 | * @property {number} [pageSize] Maximum number of logs to return.
|
575 | * @property {string} [pageToken] A previously-returned page token
|
576 | * representing part of the larger set of results to view.
|
577 | */
|
578 | /**
|
579 | * @typedef {array} GetSinksResponse
|
580 | * @property {Sink[]} 0 Array of {@link Sink} instances.
|
581 | * @property {object} 1 The full API response.
|
582 | */
|
583 | /**
|
584 | * @callback GetSinksCallback
|
585 | * @param {?Error} err Request error, if any.
|
586 | * @param {Sink[]} sinks Array of {@link Sink} instances.
|
587 | * @param {object} apiResponse The full API response.
|
588 | */
|
589 | /**
|
590 | * Get the sinks associated with this project.
|
591 | *
|
592 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/list|projects.sinks.list API Documentation}
|
593 | *
|
594 | * @param {GetSinksRequest} [query] Query object for listing sinks.
|
595 | * @param {GetSinksCallback} [callback] Callback function.
|
596 | * @returns {Promise<GetSinksResponse>}
|
597 | *
|
598 | * @example
|
599 | * ```
|
600 | * const {Logging} = require('@google-cloud/logging');
|
601 | * const logging = new Logging();
|
602 | *
|
603 | * logging.getSinks((err, sinks) => {
|
604 | * // sinks is an array of Sink objects.
|
605 | * });
|
606 | *
|
607 | * //-
|
608 | * // If the callback is omitted, we'll return a Promise.
|
609 | * //-
|
610 | * logging.getSinks().then(data => {
|
611 | * const sinks = data[0];
|
612 | * });
|
613 | *
|
614 | * ```
|
615 | * @example <caption>include:samples/sinks.js</caption>
|
616 | * region_tag:logging_list_sinks
|
617 | * Another example:
|
618 | */
|
619 | getSinks(options?: GetSinksRequest): Promise<GetSinksResponse>;
|
620 | getSinks(callback: GetSinksCallback): void;
|
621 | getSinks(options: GetSinksRequest, callback: GetSinksCallback): void;
|
622 | /**
|
623 | * Get the {@link Sink} objects associated with this project as a
|
624 | * readable object stream.
|
625 | *
|
626 | * @method Logging#getSinksStream
|
627 | * @param {GetSinksRequest} [query] Query object for listing sinks.
|
628 | * @returns {ReadableStream} A readable stream that emits {@link Sink}
|
629 | * instances.
|
630 | *
|
631 | * @example
|
632 | * ```
|
633 | * const {Logging} = require('@google-cloud/logging');
|
634 | * const logging = new Logging();
|
635 | *
|
636 | * logging.getSinksStream()
|
637 | * .on('error', console.error)
|
638 | * .on('data', sink => {
|
639 | * // `sink` is a Sink object.
|
640 | * })
|
641 | * .on('end', function() {
|
642 | * // All sinks retrieved.
|
643 | * });
|
644 | *
|
645 | * //-
|
646 | * // If you anticipate many results, you can end a stream early to prevent
|
647 | * // unnecessary processing and API requests.
|
648 | * //-
|
649 | * logging.getSinksStream()
|
650 | * .on('data', function(sink) {
|
651 | * this.end();
|
652 | * });
|
653 | * ```
|
654 | */
|
655 | getSinksStream(options: GetSinksRequest): Duplex;
|
656 | /**
|
657 | * Get a reference to a Cloud Logging log.
|
658 | *
|
659 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.logs|Log Overview}
|
660 | *
|
661 | * @param {string} name Name of the existing log.
|
662 | * @param {object} [options] Configuration object.
|
663 | * @param {boolean} [options.removeCircular] Replace circular references in
|
664 | * logged objects with a string value, `[Circular]`. (Default: false)
|
665 | * @returns {Log}
|
666 | *
|
667 | * @example
|
668 | * ```
|
669 | * const {Logging} = require('@google-cloud/logging');
|
670 | * const logging = new Logging();
|
671 | * const log = logging.log('my-log');
|
672 | * ```
|
673 | */
|
674 | log(name: string, options?: LogOptions): Log;
|
675 | /**
|
676 | * Get a reference to a Cloud Logging logSync.
|
677 | *
|
678 | * @param {string} name Name of the existing log.
|
679 | * @param {object} transport An optional write stream.
|
680 | * @returns {LogSync}
|
681 | *
|
682 | * @example
|
683 | * ```
|
684 | * const {Logging} = require('@google-cloud/logging');
|
685 | * const logging = new Logging();
|
686 | *
|
687 | * // Optional: enrich logs with additional context
|
688 | * await logging.setProjectId();
|
689 | * await logging.setDetectedResource();
|
690 | *
|
691 | * // Default transport writes to process.stdout
|
692 | * const log = logging.logSync('my-log');
|
693 | * ```
|
694 | */
|
695 | logSync(name: string, transport?: Writable): LogSync;
|
696 | /**
|
697 | * Get a reference to a Cloud Logging sink.
|
698 | *
|
699 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks|Sink Overview}
|
700 | *
|
701 | * @param {string} name Name of the existing sink.
|
702 | * @returns {Sink}
|
703 | *
|
704 | * @example
|
705 | * ```
|
706 | * const {Logging} = require('@google-cloud/logging');
|
707 | * const logging = new Logging();
|
708 | * const sink = logging.sink('my-sink');
|
709 | * ```
|
710 | */
|
711 | sink(name: string): Sink;
|
712 | /**
|
713 | * Funnel all API requests through this method, to be sure we have a project
|
714 | * ID.
|
715 | *
|
716 | * @param {object} config Configuration object.
|
717 | * @param {object} config.gaxOpts GAX options.
|
718 | * @param {function} config.method The gax method to call.
|
719 | * @param {object} config.reqOpts Request options.
|
720 | * @param {function} [callback] Callback function.
|
721 | */
|
722 | request<TResponse = any>(config: RequestConfig, callback?: RequestCallback<TResponse>): Duplex;
|
723 | /**
|
724 | * This method is called when creating a sink with a Bucket destination. The
|
725 | * bucket must first grant proper ACL access to the Cloud Logging
|
726 | * account.
|
727 | *
|
728 | * The parameters are the same as what {@link Logging#createSink} accepts.
|
729 | *
|
730 | * @private
|
731 | */
|
732 | setAclForBucket_(config: CreateSinkRequest): Promise<void>;
|
733 | /**
|
734 | * This method is called when creating a sink with a Dataset destination. The
|
735 | * dataset must first grant proper ACL access to the Cloud Logging
|
736 | * account.
|
737 | *
|
738 | * The parameters are the same as what {@link Logging#createSink} accepts.
|
739 | *
|
740 | * @private
|
741 | */
|
742 | setAclForDataset_(config: CreateSinkRequest): Promise<void>;
|
743 | /**
|
744 | * This method is called when creating a sink with a Topic destination. The
|
745 | * topic must first grant proper ACL access to the Cloud Logging
|
746 | * account.
|
747 | *
|
748 | * The parameters are the same as what {@link Logging#createSink} accepts.
|
749 | *
|
750 | * @private
|
751 | */
|
752 | setAclForTopic_(config: CreateSinkRequest): Promise<void>;
|
753 | /**
|
754 | * setProjectId detects and sets a projectId string on the Logging instance.
|
755 | * It can be invoked once to ensure ensuing LogSync entries have a projectID.
|
756 | * @param reqOpts
|
757 | */
|
758 | setProjectId(reqOpts?: {}): Promise<void>;
|
759 | /**
|
760 | * setResource detects and sets a detectedresource object on the Logging
|
761 | * instance. It can be invoked once to ensure ensuing LogSync entries contain
|
762 | * resource context.
|
763 | */
|
764 | setDetectedResource(): Promise<void>;
|
765 | }
|
766 | /**
|
767 | * {@link Entry} class.
|
768 | *
|
769 | * @name Logging.Entry
|
770 | * @see Entry
|
771 | * @type {Constructor}
|
772 | */
|
773 | export { Entry };
|
774 | /**
|
775 | * {@link Log} class.
|
776 | *
|
777 | * @name Logging.Log
|
778 | * @see Log
|
779 | * @type {Constructor}
|
780 | */
|
781 | export { Log };
|
782 | /**
|
783 | * {@link Severity} enum.
|
784 | */
|
785 | export { Severity };
|
786 | export { SeverityNames };
|
787 | export { assignSeverityToEntries };
|
788 | export { formatLogName };
|
789 | /**
|
790 | * {@link MonitoredResource} class.
|
791 | *
|
792 | * @name Logging.MonitoredResource
|
793 | * @see MonitoredResource
|
794 | * @type {Interface}
|
795 | */
|
796 | export { MonitoredResource };
|
797 | /**
|
798 | * {@link LogSync} class.
|
799 | *
|
800 | * @name Logging.LogSync
|
801 | * @see LogSync
|
802 | * @type {Constructor}
|
803 | */
|
804 | export { LogSync };
|
805 | /**
|
806 | * {@link Sink} class.
|
807 | *
|
808 | * @name Logging.Sink
|
809 | * @see Sink
|
810 | * @type {Constructor}
|
811 | */
|
812 | export { Sink };
|
813 | /**
|
814 | * The default export of the `@google-cloud/logging` package is the
|
815 | * {@link Logging} class.
|
816 | *
|
817 | * See {@link Logging} and {@link ClientConfig} for client methods and
|
818 | * configuration options.
|
819 | *
|
820 | * @module {Constructor} @google-cloud/logging
|
821 | * @alias nodejs-logging
|
822 | *
|
823 | * @example Install the client library with <a href="https://www.npmjs.com/">npm</a>:
|
824 | * ```
|
825 | * npm install --save @google-cloud/logging
|
826 | *
|
827 | * ```
|
828 | * @example Import the client library
|
829 | * ```
|
830 | * const {Logging} = require('@google-cloud/logging');
|
831 | *
|
832 | * ```
|
833 | * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
|
834 | * ```
|
835 | * const logging = new Logging();
|
836 | *
|
837 | * ```
|
838 | * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
|
839 | * ```
|
840 | * const logging = new Logging({ projectId: 'your-project-id', keyFilename: '/path/to/keyfile.json'});
|
841 | *
|
842 | * ```
|
843 | * @example <caption>include:samples/quickstart.js</caption>
|
844 | * region_tag:logging_quickstart
|
845 | * Full quickstart example:
|
846 | */
|
847 | export { Logging };
|
848 | import * as protos from '../protos/protos';
|
849 | export { protos };
|
850 | export { v2 };
|
851 |
|
\ | No newline at end of file |