1 | /*!
|
2 | * Copyright 2021 Google LLC
|
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 | /**
|
18 | * This is a helper library for synchronously writing logs to any transport.
|
19 | */
|
20 | import { Logging } from '.';
|
21 | import { Entry, LogEntry } from './entry';
|
22 | import { Writable } from 'stream';
|
23 | import { LogSeverityFunctions, WriteOptions } from './utils/log-common';
|
24 | /**
|
25 | * A logSync is a named collection of entries in structured log format. In Cloud
|
26 | * Logging, structured logs refer to log entries that use the jsonPayload field
|
27 | * to add structure to their payloads. In most GCP environments, like GKE and
|
28 | * Cloud Functions, structured logs written to process.stdout are automatically
|
29 | * picked up and formatted by logging agents.
|
30 | *
|
31 | * Recommended for Serverless environment logging, especially where async log
|
32 | * calls made by the `Log` class can be dropped by the CPU.
|
33 | *
|
34 | * See {@link https://cloud.google.com/logging/docs/structured-logging|Structured Logging}
|
35 | *
|
36 | * @class
|
37 | *
|
38 | * @param {Logging} logging {@link Logging} instance.
|
39 | * @param {string} name Name of the logSync.
|
40 | * @param {Writable} [transport] transport A custom writable transport stream.
|
41 | * Default: process.stdout.
|
42 | *
|
43 | * @example
|
44 | * ```
|
45 | * const {Logging} = require('@google-cloud/logging');
|
46 | * const logging = new Logging();
|
47 | * const log = logging.logSync('mylog');
|
48 | * ```
|
49 | */
|
50 | declare class LogSync implements LogSeverityFunctions {
|
51 | formattedName_: string;
|
52 | logging: Logging;
|
53 | name: string;
|
54 | transport: Writable;
|
55 | constructor(logging: Logging, name: string, transport?: Writable);
|
56 | /**
|
57 | * Write a log entry with a severity of "ALERT".
|
58 | *
|
59 | * This is a simple wrapper around {arguments are
LogSync#write}. All |
60 | * the same as documented there.
|
61 | *
|
62 | * {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
63 | * {?WriteOptions} [options] Write options
|
64 | *
|
65 | * ```
|
66 | * const {Logging} = require('@google-cloud/logging');
|
67 | * const logging = new Logging();
|
68 | * const log = logging.logSync('my-log');
|
69 | *
|
70 | * const entry = log.entry('gce_instance', {
|
71 | * instance: 'my_instance'
|
72 | * });
|
73 | *
|
74 | * log.alert(entry);
|
75 | * ```
|
76 | */
|
77 | alert(entry: Entry | Entry[], options?: WriteOptions): void;
|
78 | /**
|
79 | * Write a log entry with a severity of "CRITICAL".
|
80 | *
|
81 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
82 | * the same as documented there.
|
83 | *
|
84 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
85 | * @param {?WriteOptions} [options] Write options
|
86 | * @example
|
87 | * ```
|
88 | * const {Logging} = require('@google-cloud/logging');
|
89 | * const logging = new Logging();
|
90 | * const log = logging.logSync('my-log');
|
91 | *
|
92 | * const entry = log.entry('gce_instance', {
|
93 | * instance: 'my_instance'
|
94 | * });
|
95 | *
|
96 | * log.critical(entry);
|
97 | * ```
|
98 | */
|
99 | critical(entry: Entry | Entry[], options?: WriteOptions): void;
|
100 | /**
|
101 | * Write a log entry with a severity of "DEBUG".
|
102 | *
|
103 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
104 | * the same as documented there.
|
105 | *
|
106 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
107 | * @param {?WriteOptions} [options] Write options
|
108 | * @example
|
109 | * ```
|
110 | * const {Logging} = require('@google-cloud/logging');
|
111 | * const logging = new Logging();
|
112 | * const log = logging.logSync('my-log');
|
113 | *
|
114 | * const entry = log.entry('gce_instance', {
|
115 | * instance: 'my_instance'
|
116 | * });
|
117 | *
|
118 | * log.debug(entry);
|
119 | * ```
|
120 | */
|
121 | debug(entry: Entry | Entry[], options?: WriteOptions): void;
|
122 | /**
|
123 | * Write a log entry with a severity of "EMERGENCY".
|
124 | *
|
125 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
126 | * the same as documented there.
|
127 | *
|
128 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
129 | * @param {?WriteOptions} [options] Write options
|
130 | * @example
|
131 | * ```
|
132 | * const {Logging} = require('@google-cloud/logging');
|
133 | * const logging = new Logging();
|
134 | * const log = logging.logSync('my-log');
|
135 | *
|
136 | * const entry = log.entry('gce_instance', {
|
137 | * instance: 'my_instance'
|
138 | * });
|
139 | *
|
140 | * log.emergency(entry);
|
141 | * ```
|
142 | */
|
143 | emergency(entry: Entry | Entry[], options?: WriteOptions): void;
|
144 | /**
|
145 | * Create an entry object for this log.
|
146 | *
|
147 | * Using this method will not itself do any logging.
|
148 | *
|
149 | * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry|LogEntry JSON representation}
|
150 | *
|
151 | * @param {?object} metadata See a
|
152 | * [LogEntry
|
153 | * Resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).
|
154 | * @param {object|string} data The data to use as the value for this log
|
155 | * entry.
|
156 | * @returns {Entry}
|
157 | *
|
158 | * @example
|
159 | * ```
|
160 | * const {Logging} = require('@google-cloud/logging');
|
161 | * const logging = new Logging();
|
162 | * const log = logging.logSync('my-log');
|
163 | *
|
164 | * const metadata = {
|
165 | * resource: {
|
166 | * type: 'gce_instance',
|
167 | * labels: {
|
168 | * zone: 'global',
|
169 | * instance_id: '3'
|
170 | * }
|
171 | * }
|
172 | * };
|
173 | *
|
174 | * const entry = log.entry(metadata, {
|
175 | * delegate: 'my_username'
|
176 | * });
|
177 | * ```
|
178 | */
|
179 | entry(metadata?: LogEntry): Entry;
|
180 | entry(data?: string | {}): Entry;
|
181 | entry(metadata?: LogEntry, data?: string | {}): Entry;
|
182 | /**
|
183 | * Write a log entry with a severity of "ERROR".
|
184 | *
|
185 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
186 | * the same as documented there.
|
187 | *
|
188 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
189 | * @param {?WriteOptions} [options] Write options
|
190 | * @example
|
191 | * ```
|
192 | * const {Logging} = require('@google-cloud/logging');
|
193 | * const logging = new Logging();
|
194 | * const log = logging.logSync('my-log');
|
195 | *
|
196 | * const entry = log.entry('gce_instance', {
|
197 | * instance: 'my_instance'
|
198 | * });
|
199 | *
|
200 | * log.error(entry);
|
201 | * ```
|
202 | */
|
203 | error(entry: Entry | Entry[], options?: WriteOptions): void;
|
204 | /**
|
205 | * Write a log entry with a severity of "INFO".
|
206 | *
|
207 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
208 | * the same as documented there.
|
209 | *
|
210 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
211 | * @param {?WriteOptions} [options] Write options
|
212 | * @example
|
213 | * ```
|
214 | * const {Logging} = require('@google-cloud/logging');
|
215 | * const logging = new Logging();
|
216 | * const log = logging.logSync('my-log');
|
217 | *
|
218 | * const entry = log.entry('gce_instance', {
|
219 | * instance: 'my_instance'
|
220 | * });
|
221 | *
|
222 | * log.info(entry);
|
223 | * ```
|
224 | */
|
225 | info(entry: Entry | Entry[], options?: WriteOptions): void;
|
226 | /**
|
227 | * Write a log entry with a severity of "NOTICE".
|
228 | *
|
229 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
230 | * the same as documented there.
|
231 | *
|
232 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
233 | * @param {?WriteOptions} [options] Write options
|
234 | * @example
|
235 | * ```
|
236 | * const {Logging} = require('@google-cloud/logging');
|
237 | * const logging = new Logging();
|
238 | * const log = logging.logSync('my-log');
|
239 | *
|
240 | * const entry = log.entry('gce_instance', {
|
241 | * instance: 'my_instance'
|
242 | * });
|
243 | *
|
244 | * log.notice(entry);
|
245 | * ```
|
246 | */
|
247 | notice(entry: Entry | Entry[], options?: WriteOptions): void;
|
248 | /**
|
249 | * Write a log entry with a severity of "WARNING".
|
250 | *
|
251 | * This is a simple wrapper around {@link LogSync#write}. All arguments are
|
252 | * the same as documented there.
|
253 | *
|
254 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
255 | * @param {?WriteOptions} [options] Write options
|
256 | * @example
|
257 | * ```
|
258 | * const {Logging} = require('@google-cloud/logging');
|
259 | * const logging = new Logging();
|
260 | * const log = logging.logSync('my-log');
|
261 | *
|
262 | * const entry = log.entry('gce_instance', {
|
263 | * instance: 'my_instance'
|
264 | * });
|
265 | *
|
266 | * log.warning(entry);
|
267 | * ```
|
268 | */
|
269 | warning(entry: Entry | Entry[], options?: WriteOptions): void;
|
270 | /**
|
271 | * Write log entries to a custom transport (default: process.stdout).
|
272 | *
|
273 | * @param {Entry|Entry[]} entry A log entry, or array of entries, to write.
|
274 | * @param {?WriteOptions} [options] Write options
|
275 | *
|
276 | * @example
|
277 | * ```
|
278 | * const entry = log.entry('gce_instance', {
|
279 | * instance: 'my_instance'
|
280 | * });
|
281 | *
|
282 | * log.write(entry);
|
283 | *
|
284 | * //-
|
285 | * // You may also pass multiple log entries to write.
|
286 | * //-
|
287 | * const secondEntry = log.entry('compute.googleapis.com', {
|
288 | * user: 'my_username'
|
289 | * });
|
290 | *
|
291 | * log.write([entry, secondEntry]);
|
292 | *
|
293 | * //-
|
294 | * // To save some steps, you can also pass in plain values as your entries.
|
295 | * // Note, however, that you must provide a configuration object to specify
|
296 | * // the resource.
|
297 | * //-
|
298 | * const entries = [
|
299 | * {
|
300 | * user: 'my_username'
|
301 | * },
|
302 | * {
|
303 | * home: process.env.HOME
|
304 | * }
|
305 | * ];
|
306 | *
|
307 | * const options = {
|
308 | * resource: 'compute.googleapis.com'
|
309 | * };
|
310 | *
|
311 | * log.write(entries, options);
|
312 | *
|
313 | * log.write(entries);
|
314 | * });
|
315 | * ```
|
316 | */
|
317 | write(entry: Entry | Entry[], opts?: WriteOptions): void;
|
318 | }
|
319 | /**
|
320 | * Reference to the {@link LogSync} class.
|
321 | * @name module:@google-cloud/logging.LogSync
|
322 | * @see LogSync
|
323 | */
|
324 | export { LogSync };
|