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 { CallOptions } from 'google-gax';
|
18 | import { GetEntriesCallback, GetEntriesResponse, Logging } from '.';
|
19 | import { Entry, LogEntry } from './entry';
|
20 | import { LogSeverityFunctions, WriteOptions as CommonOptions } from './utils/log-common';
|
21 | export interface WriteOptions extends CommonOptions {
|
22 | dryRun?: boolean;
|
23 | gaxOptions?: CallOptions;
|
24 | partialSuccess?: boolean;
|
25 | }
|
26 | export interface GetEntriesRequest {
|
27 | autoPaginate?: boolean;
|
28 | filter?: string;
|
29 | gaxOptions?: CallOptions;
|
30 | log?: string;
|
31 | maxApiCalls?: number;
|
32 | maxResults?: number;
|
33 | orderBy?: string;
|
34 | pageSize?: number;
|
35 | pageToken?: string;
|
36 | resourceNames?: string[] | string;
|
37 | }
|
38 | export interface TailEntriesRequest {
|
39 | resourceNames?: string[] | string;
|
40 | filter?: string;
|
41 | bufferWindow?: number;
|
42 | log?: string;
|
43 | gaxOptions?: CallOptions;
|
44 | }
|
45 | export interface LogOptions {
|
46 | removeCircular?: boolean;
|
47 | maxEntrySize?: number;
|
48 | jsonFieldsToTruncate?: string[];
|
49 | defaultWriteDeleteCallback?: ApiResponseCallback;
|
50 | }
|
51 | export declare type Metadata = any;
|
52 | export declare type ApiResponse = [Metadata];
|
53 | export interface ApiResponseCallback {
|
54 | (err: Error | null, apiResponse?: Metadata): void;
|
55 | }
|
56 | export declare type DeleteCallback = ApiResponseCallback;
|
57 | /**
|
58 | * A log is a named collection of entries, each entry representing a timestamped
|
59 | * event. Logs can be produced by Google Cloud Platform services, by third-party
|
60 | * services, or by your applications. For example, the log `apache-access` is
|
61 | * produced by the Apache Web Server, but the log
|
62 | * `compute.googleapis.com/activity_log` is produced by Google Compute Engine.
|
63 | *
|
64 | * See {@link https://cloud.google.com/logging/docs/basic-concepts#logs|Introduction to Logs}
|
65 | *
|
66 | * @class
|
67 | *
|
68 | * @param {Logging} logging {@link Logging} instance.
|
69 | * @param {string} name Name of the log.
|
70 | * @param {object} [options] Configuration object.
|
71 | * @param {boolean} [options.removeCircular] Replace circular references in
|
72 | * logged objects with a string value, `[Circular]`. (Default: false)
|
73 | * @param {number} [options.maxEntrySize] A max entry size
|
74 | * @param {string[]} [options.jsonFieldsToTruncate] A list of JSON properties at the given full path to be truncated.
|
75 | * Received values will be prepended to predefined list in the order received and duplicates discarded.
|
76 | * @param {ApiResponseCallback} [options.defaultWriteDeleteCallback] A default global callback to be used for {@link Log#write}
|
77 | * and {@link Log#delete} APIs when {@link ApiResponseCallback} callback was not supplied by caller in function parameters.
|
78 | * Note that {@link LogOptions#defaultWriteDeleteCallback} is useful when {@link Log#write} and {@link Log#delete} APIs are called
|
79 | * without `await` and without callback added explicitly to every call - this way {@link LogOptions#defaultWriteDeleteCallback}
|
80 | * can serve as global callback handler, which for example could be used to catch all errors and eliminate crashes.
|
81 | * @example
|
82 | * ```
|
83 | * import {Logging} from '@google-cloud/logging';
|
84 | * import {LogOptions} from '@google-cloud/logging/build/src/log';
|
85 | * const options: LogOptions = {
|
86 | * maxEntrySize: 256,
|
87 | * jsonFieldsToTruncate: [
|
88 | * 'jsonPayload.fields.metadata.structValue.fields.custom.stringValue',
|
89 | * ],
|
90 | * defaultWriteDeleteCallback: (err: any) => {
|
91 | * if (err) {
|
92 | * console.log('Error: ' + err);
|
93 | * }
|
94 | * },
|
95 | * };
|
96 | * const logging = new Logging();
|
97 | * const log = logging.log('syslog', options);
|
98 | * ```
|
99 | */
|
100 | declare class Log implements LogSeverityFunctions {
|
101 | formattedName_: string;
|
102 | removeCircular_: boolean;
|
103 | maxEntrySize?: number;
|
104 | logging: Logging;
|
105 | name: string;
|
106 | jsonFieldsToTruncate: string[];
|
107 | defaultWriteDeleteCallback?: ApiResponseCallback;
|
108 | constructor(logging: Logging, name: string, options?: LogOptions);
|
109 | /**
|
110 | * Write a log entry with a severity of "ALERT".
|
111 | *
|
112 | * This is a simple wrapper around {arguments are
Log.write|Log.write}. All |
113 | * the same as documented there.
|
114 | *
|
115 | * {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
116 | * {?WriteOptions} [options] Write options
|
117 | * function.
{LogWriteCallback} [callback] Callback |
118 | * @returns {Promise<LogWriteResponse>}
|
119 | *
|
120 | * ```
|
121 | * const {Logging} = require('@google-cloud/logging');
|
122 | * const logging = new Logging();
|
123 | * const log = logging.log('my-log');
|
124 | *
|
125 | * const entry = log.entry('gce_instance', {
|
126 | * instance: 'my_instance'
|
127 | * });
|
128 | *
|
129 | * log.alert(entry, (err, apiResponse) => {});
|
130 | *
|
131 | * //-
|
132 | * // If the callback is omitted, we'll return a Promise.
|
133 | * //-
|
134 | * log.alert(entry).then(data => {
|
135 | * const apiResponse = data[0];
|
136 | * });
|
137 | * ```
|
138 | */
|
139 | alert(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
140 | alert(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
141 | alert(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
142 | /**
|
143 | * Write a log entry with a severity of "CRITICAL".
|
144 | *
|
145 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
146 | * the same as documented there.
|
147 | *
|
148 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
149 | * @param {?WriteOptions} [options] Write options
|
150 | * @param {LogWriteCallback} [callback] Callback function.
|
151 | * @returns {Promise<LogWriteResponse>}
|
152 | * @example
|
153 | * ```
|
154 | * const {Logging} = require('@google-cloud/logging');
|
155 | * const logging = new Logging();
|
156 | * const log = logging.log('my-log');
|
157 | *
|
158 | * const entry = log.entry('gce_instance', {
|
159 | * instance: 'my_instance'
|
160 | * });
|
161 | *
|
162 | * log.critical(entry, (err, apiResponse) => {});
|
163 | *
|
164 | * //-
|
165 | * // If the callback is omitted, we'll return a Promise.
|
166 | * //-
|
167 | * log.critical(entry).then(data => {
|
168 | * const apiResponse = data[0];
|
169 | * });
|
170 | * ```
|
171 | */
|
172 | critical(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
173 | critical(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
174 | critical(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
175 | /**
|
176 | * Write a log entry with a severity of "DEBUG".
|
177 | *
|
178 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
179 | * the same as documented there.
|
180 | *
|
181 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
182 | * @param {?WriteOptions} [options] Write options
|
183 | * @param {LogWriteCallback} [callback] Callback function.
|
184 | * @returns {Promise<LogWriteResponse>}
|
185 | * @example
|
186 | * ```
|
187 | * const {Logging} = require('@google-cloud/logging');
|
188 | * const logging = new Logging();
|
189 | * const log = logging.log('my-log');
|
190 | *
|
191 | * const entry = log.entry('gce_instance', {
|
192 | * instance: 'my_instance'
|
193 | * });
|
194 | *
|
195 | * log.debug(entry, (err, apiResponse) => {});
|
196 | *
|
197 | * //-
|
198 | * // If the callback is omitted, we'll return a Promise.
|
199 | * //-
|
200 | * log.debug(entry).then(data => {
|
201 | * const apiResponse = data[0];
|
202 | * });
|
203 | * ```
|
204 | */
|
205 | debug(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
206 | debug(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
207 | debug(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
208 | /**
|
209 | * @typedef {array} DeleteLogResponse
|
210 | * @property {object} 0 The full API response.
|
211 | */
|
212 | /**
|
213 | * @callback DeleteLogCallback
|
214 | * @param {?Error} err Request error, if any.
|
215 | * @param {object} apiResponse The full API response.
|
216 | */
|
217 | /**
|
218 | * Delete the log.
|
219 | *
|
220 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.logs/delete|projects.logs.delete API Documentation}
|
221 | *
|
222 | * @param {object} [gaxOptions] Request configuration options, outlined
|
223 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
224 | * @param {DeleteLogCallback} [callback] Callback function.
|
225 | * @returns {Promise<DeleteLogResponse>}
|
226 | *
|
227 | * @example
|
228 | * ```
|
229 | * const {Logging} = require('@google-cloud/logging');
|
230 | * const logging = new Logging();
|
231 | * const log = logging.log('my-log');
|
232 | *
|
233 | * log.delete((err, apiResponse) => {
|
234 | * if (!err) {
|
235 | * // The log was deleted.
|
236 | * }
|
237 | * });
|
238 | *
|
239 | * //-
|
240 | * // If the callback is omitted, we'll return a Promise.
|
241 | * //-
|
242 | * log.delete().then(data => {
|
243 | * const apiResponse = data[0];
|
244 | * });
|
245 | *
|
246 | * ```
|
247 | * @example <caption>include:samples/logs.js</caption>
|
248 | * region_tag:logging_delete_log
|
249 | * Another example:
|
250 | */
|
251 | delete(gaxOptions?: CallOptions): Promise<ApiResponse>;
|
252 | delete(gaxOptions: CallOptions, callback: DeleteCallback): void;
|
253 | delete(callback: DeleteCallback): void;
|
254 | /**
|
255 | * Write a log entry with a severity of "EMERGENCY".
|
256 | *
|
257 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
258 | * the same as documented there.
|
259 | *
|
260 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
261 | * @param {?WriteOptions} [options] Write options
|
262 | * @param {LogWriteCallback} [callback] Callback function.
|
263 | * @returns {Promise<LogWriteResponse>}
|
264 | * @example
|
265 | * ```
|
266 | * const {Logging} = require('@google-cloud/logging');
|
267 | * const logging = new Logging();
|
268 | * const log = logging.log('my-log');
|
269 | *
|
270 | * const entry = log.entry('gce_instance', {
|
271 | * instance: 'my_instance'
|
272 | * });
|
273 | *
|
274 | * log.emergency(entry, (err, apiResponse) => {});
|
275 | *
|
276 | * //-
|
277 | * // If the callback is omitted, we'll return a Promise.
|
278 | * //-
|
279 | * log.emergency(entry).then(data => {
|
280 | * const apiResponse = data[0];
|
281 | * });
|
282 | * ```
|
283 | */
|
284 | emergency(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
285 | emergency(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
286 | /**
|
287 | * Create an entry object for this log.
|
288 | *
|
289 | * Using this method will not itself make any API requests. You will use
|
290 | * the object returned in other API calls, such as
|
291 | * {@link Log#write}.
|
292 | *
|
293 | * Note, {@link https://cloud.google.com/logging/quotas|Cloud Logging Quotas and limits}
|
294 | * dictates that the maximum log entry size, including all
|
295 | * [LogEntry Resource properties]{@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry},
|
296 | * cannot exceed _approximately_ 256 KB.
|
297 | *
|
298 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry|LogEntry JSON representation}
|
299 | *
|
300 | * @param {?object} metadata See a
|
301 | * [LogEntry
|
302 | * Resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).
|
303 | * @param {object|string} data The data to use as the value for this log
|
304 | * entry.
|
305 | * @returns {Entry}
|
306 | *
|
307 | * @example
|
308 | * ```
|
309 | * const {Logging} = require('@google-cloud/logging');
|
310 | * const logging = new Logging();
|
311 | * const log = logging.log('my-log');
|
312 | *
|
313 | * const metadata = {
|
314 | * resource: {
|
315 | * type: 'gce_instance',
|
316 | * labels: {
|
317 | * zone: 'global',
|
318 | * instance_id: '3'
|
319 | * }
|
320 | * }
|
321 | * };
|
322 | *
|
323 | * const entry = log.entry(metadata, {
|
324 | * delegate: 'my_username'
|
325 | * });
|
326 | *
|
327 | * entry.toJSON();
|
328 | * // {
|
329 | * // logName: 'projects/grape-spaceship-123/logs/syslog',
|
330 | * // resource: {
|
331 | * // type: 'gce_instance',
|
332 | * // labels: {
|
333 | * // zone: 'global',
|
334 | * // instance_id: '3'
|
335 | * // }
|
336 | * // },
|
337 | * // jsonPayload: {
|
338 | * // delegate: 'my_username'
|
339 | * // }
|
340 | * // }
|
341 | * ```
|
342 | */
|
343 | entry(metadata?: LogEntry): Entry;
|
344 | entry(data?: string | {}): Entry;
|
345 | entry(metadata?: LogEntry, data?: string | {}): Entry;
|
346 | /**
|
347 | * Write a log entry with a severity of "ERROR".
|
348 | *
|
349 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
350 | * the same as documented there.
|
351 | *
|
352 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
353 | * @param {?WriteOptions} [options] Write options
|
354 | * @param {LogWriteCallback} [callback] Callback function.
|
355 | * @returns {Promise<LogWriteResponse>}
|
356 | * @example
|
357 | * ```
|
358 | * const {Logging} = require('@google-cloud/logging');
|
359 | * const logging = new Logging();
|
360 | * const log = logging.log('my-log');
|
361 | *
|
362 | * const entry = log.entry('gce_instance', {
|
363 | * instance: 'my_instance'
|
364 | * });
|
365 | *
|
366 | * log.error(entry, (err, apiResponse) => {});
|
367 | *
|
368 | * //-
|
369 | * // If the callback is omitted, we'll return a Promise.
|
370 | * //-
|
371 | * log.error(entry).then(data => {
|
372 | * const apiResponse = data[0];
|
373 | * });
|
374 | * ```
|
375 | */
|
376 | error(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
377 | error(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
378 | error(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
379 | /**
|
380 | * This method is a wrapper around {module:logging#getEntries}, but with a
|
381 | * filter specified to only return entries from this log.
|
382 | *
|
383 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list|entries.list API Documentation}
|
384 | *
|
385 | * @param {GetEntriesRequest} [query] Query object for listing entries.
|
386 | * @param {GetEntriesCallback} [callback] Callback function.
|
387 | * @returns {Promise<GetEntriesResponse>}
|
388 | *
|
389 | * @example
|
390 | * ```
|
391 | * const {Logging} = require('@google-cloud/logging');
|
392 | * const logging = new Logging();
|
393 | * const log = logging.log('my-log');
|
394 | *
|
395 | * log.getEntries((err, entries) => {
|
396 | * // `entries` is an array of Cloud Logging entry objects.
|
397 | * // See the `data` property to read the data from the entry.
|
398 | * });
|
399 | *
|
400 | * //-
|
401 | * // To control how many API requests are made and page through the results
|
402 | * // manually, set `autoPaginate` to `false`.
|
403 | * //-
|
404 | * function callback(err, entries, nextQuery, apiResponse) {
|
405 | * if (nextQuery) {
|
406 | * // More results exist.
|
407 | * log.getEntries(nextQuery, callback);
|
408 | * }
|
409 | * }
|
410 | *
|
411 | * log.getEntries({
|
412 | * autoPaginate: false
|
413 | * }, callback);
|
414 | *
|
415 | * //-
|
416 | * // If the callback is omitted, we'll return a Promise.
|
417 | * //-
|
418 | * log.getEntries().then(data => {
|
419 | * const entries = data[0];
|
420 | * });
|
421 | * ```
|
422 | */
|
423 | getEntries(options?: GetEntriesRequest): Promise<GetEntriesResponse>;
|
424 | getEntries(callback: GetEntriesCallback): void;
|
425 | getEntries(options: GetEntriesRequest, callback: GetEntriesCallback): void;
|
426 | /**
|
427 | * This method is a wrapper around {module:logging#getEntriesStream}, but with
|
428 | * a filter specified to only return {module:logging/entry} objects from this
|
429 | * log.
|
430 | *
|
431 | * @method Log#getEntriesStream
|
432 | * @param {GetEntriesRequest} [query] Query object for listing entries.
|
433 | * @returns {ReadableStream} A readable stream that emits {@link Entry}
|
434 | * instances.
|
435 | *
|
436 | * @example
|
437 | * ```
|
438 | * const {Logging} = require('@google-cloud/logging');
|
439 | * const logging = new Logging();
|
440 | * const log = logging.log('my-log');
|
441 | *
|
442 | * log.getEntriesStream()
|
443 | * .on('error', console.error)
|
444 | * .on('data', entry => {
|
445 | * // `entry` is a Cloud Logging entry object.
|
446 | * // See the `data` property to read the data from the entry.
|
447 | * })
|
448 | * .on('end', function() {
|
449 | * // All entries retrieved.
|
450 | * });
|
451 | *
|
452 | * //-
|
453 | * // If you anticipate many results, you can end a stream early to prevent
|
454 | * // unnecessary processing and API requests.
|
455 | * //-
|
456 | * log.getEntriesStream()
|
457 | * .on('data', function(entry) {
|
458 | * this.end();
|
459 | * });
|
460 | * ```
|
461 | */
|
462 | getEntriesStream(options: GetEntriesRequest): import("stream").Duplex;
|
463 | /**
|
464 | * This method is a wrapper around {module:logging#tailEntries}, but with
|
465 | * a filter specified to only return {module:logging/entry} objects from this
|
466 | * log.
|
467 | *
|
468 | * @method Log#tailEntries
|
469 | * @param {TailEntriesRequest} [query] Query object for tailing entries.
|
470 | * @returns {DuplexStream} A duplex stream that emits TailEntriesResponses
|
471 | * containing an array of {@link Entry} instances.
|
472 | *
|
473 | * @example
|
474 | * ```
|
475 | * const {Logging} = require('@google-cloud/logging');
|
476 | * const logging = new Logging();
|
477 | * const log = logging.log('my-log');
|
478 | *
|
479 | * log.tailEntries()
|
480 | * .on('error', console.error)
|
481 | * .on('data', resp => {
|
482 | * console.log(resp.entries);
|
483 | * console.log(resp.suppressionInfo);
|
484 | * })
|
485 | * .on('end', function() {
|
486 | * // All entries retrieved.
|
487 | * });
|
488 | *
|
489 | * //-
|
490 | * // If you anticipate many results, you can end a stream early to prevent
|
491 | * // unnecessary processing and API requests.
|
492 | * //-
|
493 | * log.tailEntries()
|
494 | * .on('data', function(entry) {
|
495 | * this.end();
|
496 | * });
|
497 | * ```
|
498 | */
|
499 | tailEntries(options?: TailEntriesRequest): import("stream").Duplex;
|
500 | /**
|
501 | * Write a log entry with a severity of "INFO".
|
502 | *
|
503 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
504 | * the same as documented there.
|
505 | *
|
506 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
507 | * @param {?WriteOptions} [options] Write options
|
508 | * @param {LogWriteCallback} [callback] Callback function.
|
509 | * @returns {Promise<LogWriteResponse>}
|
510 | * @example
|
511 | * ```
|
512 | * const {Logging} = require('@google-cloud/logging');
|
513 | * const logging = new Logging();
|
514 | * const log = logging.log('my-log');
|
515 | *
|
516 | * const entry = log.entry('gce_instance', {
|
517 | * instance: 'my_instance'
|
518 | * });
|
519 | *
|
520 | * log.info(entry, (err, apiResponse) => {});
|
521 | *
|
522 | * //-
|
523 | * // If the callback is omitted, we'll return a Promise.
|
524 | * //-
|
525 | * log.info(entry).then(data => {
|
526 | * const apiResponse = data[0];
|
527 | * });
|
528 | * ```
|
529 | */
|
530 | info(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
531 | info(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
532 | info(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
533 | /**
|
534 | * Write a log entry with a severity of "NOTICE".
|
535 | *
|
536 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
537 | * the same as documented there.
|
538 | *
|
539 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
540 | * @param {?WriteOptions} [options] Write options
|
541 | * @param {LogWriteCallback} [callback] Callback function.
|
542 | * @returns {Promise<LogWriteResponse>}
|
543 | * @example
|
544 | * ```
|
545 | * const {Logging} = require('@google-cloud/logging');
|
546 | * const logging = new Logging();
|
547 | * const log = logging.log('my-log');
|
548 | *
|
549 | * const entry = log.entry('gce_instance', {
|
550 | * instance: 'my_instance'
|
551 | * });
|
552 | *
|
553 | * log.notice(entry, (err, apiResponse) => {});
|
554 | *
|
555 | * //-
|
556 | * // If the callback is omitted, we'll return a Promise.
|
557 | * //-
|
558 | * log.notice(entry).then(data => {
|
559 | * const apiResponse = data[0];
|
560 | * });
|
561 | * ```
|
562 | */
|
563 | notice(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
564 | notice(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
565 | notice(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
566 | /**
|
567 | * Write a log entry with a severity of "WARNING".
|
568 | *
|
569 | * This is a simple wrapper around {@link Log.write|Log.write}. All arguments are
|
570 | * the same as documented there.
|
571 | *
|
572 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
573 | * @param {?WriteOptions} [options] Write options
|
574 | * @param {LogWriteCallback} [callback] Callback function.
|
575 | * @returns {Promise<LogWriteResponse>}
|
576 | * @example
|
577 | * ```
|
578 | * const {Logging} = require('@google-cloud/logging');
|
579 | * const logging = new Logging();
|
580 | * const log = logging.log('my-log');
|
581 | *
|
582 | * const entry = log.entry('gce_instance', {
|
583 | * instance: 'my_instance'
|
584 | * });
|
585 | *
|
586 | * log.warning(entry, (err, apiResponse) => {});
|
587 | *
|
588 | * //-
|
589 | * // If the callback is omitted, we'll return a Promise.
|
590 | * //-
|
591 | * log.warning(entry).then(data => {
|
592 | * const apiResponse = data[0];
|
593 | * });
|
594 | * ```
|
595 | */
|
596 | warning(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
597 | warning(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
598 | warning(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
599 | /**
|
600 | * @typedef {array} LogWriteResponse
|
601 | * @property {object} 0 The full API response.
|
602 | */
|
603 | /**
|
604 | * @callback LogWriteCallback
|
605 | * @param {?Error} err Request error, if any.
|
606 | * @param {object} apiResponse The full API response.
|
607 | */
|
608 | /**
|
609 | * Write options.
|
610 | *
|
611 | * @typedef {object} WriteOptions
|
612 | * @property {boolean} [dryRun] If true, the request should expect normal
|
613 | * response, but the entries won't be persisted nor exported.
|
614 | * @property {object} gaxOptions Request configuration options, outlined here:
|
615 | * https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
616 | * @property {object[]} labels Labels to set on the log.
|
617 | * @property {boolean} [partialSuccess] Whether valid entries should be
|
618 | * written even if some other entries fail due to INVALID_ARGUMENT
|
619 | * or PERMISSION_DENIED errors.
|
620 | * @property {object} resource A default monitored resource for entries where
|
621 | * one isn't specified.
|
622 | */
|
623 | /**
|
624 | * Write log entries to Cloud Logging.
|
625 | *
|
626 | * Note, {@link https://cloud.google.com/logging/quotas|Cloud Logging Quotas and limits}
|
627 | * dictates that the maximum cumulative size of all entries per write,
|
628 | * including all [LogEntry Resource properties]{@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry},
|
629 | * cannot exceed _approximately_ 10 MB.
|
630 | *
|
631 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write|entries.write API Documentation}
|
632 | *
|
633 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
634 | * @param {?WriteOptions} [options] Write options
|
635 | * @param {LogWriteCallback} [callback] Callback function.
|
636 | * @returns {Promise<LogWriteResponse>}
|
637 | *
|
638 | * @example
|
639 | * ```
|
640 | * const entry = log.entry('gce_instance', {
|
641 | * instance: 'my_instance'
|
642 | * });
|
643 | *
|
644 | * log.write(entry, (err, apiResponse) => {
|
645 | * if (!err) {
|
646 | * // The log entry was written.
|
647 | * }
|
648 | * });
|
649 | *
|
650 | * //-
|
651 | * // You may also pass multiple log entries to write.
|
652 | * //-
|
653 | * const secondEntry = log.entry('compute.googleapis.com', {
|
654 | * user: 'my_username'
|
655 | * });
|
656 | *
|
657 | * log.write([
|
658 | * entry,
|
659 | * secondEntry
|
660 | * ], (err, apiResponse) => {
|
661 | * if (!err) {
|
662 | * // The log entries were written.
|
663 | * }
|
664 | * });
|
665 | *
|
666 | * //-
|
667 | * // To save some steps, you can also pass in plain values as your entries.
|
668 | * // Note, however, that you must provide a configuration object to specify
|
669 | * // the resource.
|
670 | * //-
|
671 | * const entries = [
|
672 | * {
|
673 | * user: 'my_username'
|
674 | * },
|
675 | * {
|
676 | * home: process.env.HOME
|
677 | * }
|
678 | * ];
|
679 | *
|
680 | * const options = {
|
681 | * resource: 'compute.googleapis.com'
|
682 | * };
|
683 | *
|
684 | * log.write(entries, options, (err, apiResponse) => {});
|
685 | *
|
686 | * //-
|
687 | * // If the callback is omitted, we'll return a Promise.
|
688 | * //-
|
689 | * log.write(entries).then(data => {
|
690 | * const apiResponse = data[0];
|
691 | * });
|
692 | *
|
693 | * ```
|
694 | * @example <caption>include:samples/logs.js</caption>
|
695 | * region_tag:logging_write_log_entry
|
696 | * Another example:
|
697 | *
|
698 | * @example <caption>include:samples/logs.js</caption>
|
699 | * region_tag:logging_write_log_entry_advanced
|
700 | * Another example:
|
701 | */
|
702 | write(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>;
|
703 | write(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void;
|
704 | write(entry: Entry | Entry[], callback: ApiResponseCallback): void;
|
705 | /**
|
706 | * getOrSetResource looks for GCP service context first at the user
|
707 | * declaration level (snakecasing keys), then in the Logging instance,
|
708 | * before finally detecting a resource from the environment.
|
709 | * The resource is then memoized at the Logging instance level for future use.
|
710 | *
|
711 | * @param options
|
712 | * @private
|
713 | */
|
714 | private getOrSetResource;
|
715 | /**
|
716 | * All entries are passed through here in order be formatted and serialized.
|
717 | * User provided Entry values are formatted per LogEntry specifications.
|
718 | * Read more about the LogEntry format:
|
719 | * https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
|
720 | *
|
721 | * @private
|
722 | *
|
723 | * @param {object[]} entries - Entry objects.
|
724 | * @returns {object[]} Serialized entries.
|
725 | * @throws if there is an error during serialization.
|
726 | */
|
727 | private decorateEntries;
|
728 | /**
|
729 | * Truncate log entries at maxEntrySize, so that error is not thrown, see:
|
730 | * https://cloud.google.com/logging/quotas
|
731 | *
|
732 | * @private
|
733 | *
|
734 | * @param {object|string} the JSON log entry.
|
735 | * @returns {object|string} truncated JSON log entry.
|
736 | */
|
737 | private truncateEntries;
|
738 | /**
|
739 | * Return an array of log entries with the desired severity assigned.
|
740 | *
|
741 | * @private
|
742 | *
|
743 | * @param {object|object[]} entries - Log entries.
|
744 | * @param {string} severity - The desired severity level.
|
745 | */
|
746 | static assignSeverityToEntries_(entries: Entry | Entry[], severity: string): Entry[];
|
747 | /**
|
748 | * Format the name of a log. A log's full name is in the format of
|
749 | * 'projects/{projectId}/logs/{logName}'.
|
750 | *
|
751 | * @private
|
752 | *
|
753 | * @returns {string}
|
754 | */
|
755 | static formatName_(projectId: string, name: string): string;
|
756 | }
|
757 | /**
|
758 | * Reference to the {@link Log} class.
|
759 | * @name module:@google-cloud/logging.Log
|
760 | * @see Log
|
761 | */
|
762 | export { Log };
|