UNPKG

10 kBTypeScriptView Raw
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 */
16import { CallOptions } from 'google-gax';
17import { CreateSinkCallback, CreateSinkRequest, DeleteCallback, DeleteResponse, Logging, LogSink } from '.';
18export interface SinkMetadataCallback {
19 (error: Error | null, response?: LogSink): void;
20}
21export type SinkMetadataResponse = [LogSink];
22export interface SetSinkMetadata extends LogSink {
23 gaxOptions?: CallOptions;
24 uniqueWriterIdentity?: boolean | string;
25}
26/**
27 * A sink is an object that lets you to specify a set of log entries to export
28 * to a particular destination. Cloud Logging lets you export log entries
29 * to destinations including Cloud Storage buckets (for long term log
30 * storage), Google BigQuery datasets (for log analysis), Google Pub/Sub (for
31 * streaming to other applications).
32 *
33 * See {@link https://cloud.google.com/logging/docs/basic-concepts#sinks|Introduction to Sinks}
34 *
35 * @class
36 *
37 * @param {Logging} logging {@link Logging} instance.
38 * @param {string} name Name of the sink.
39 *
40 * @example
41 * ```
42 * const {Logging} = require('@google-cloud/logging');
43 * const logging = new Logging();
44 * const sink = logging.sink('my-sink');
45 * ```
46 */
47declare class Sink {
48 logging: Logging;
49 name: string;
50 formattedName_: string;
51 metadata?: LogSink;
52 constructor(logging: Logging, name: string);
53 /**
54 * Create a sink.
55 *
56 * @param {CreateSinkRequest} config Config to set for the sink.
57 * @param {CreateSinkCallback} [callback] Callback function.
58 * @returns {Promise<CreateSinkResponse>}
59 * @throws {Error} if a config object is not provided.
60 * @see Logging#createSink
61 *
62 * @example
63 * ```
64 * const {Logging} = require('@google-cloud/logging');
65 * const logging = new Logging();
66 * const sink = logging.sink('my-sink');
67 *
68 * const config = {
69 * destination: {
70 * // ...
71 * }
72 * };
73 *
74 * sink.create(config, (err, sink, apiResponse) => {
75 * if (!err) {
76 * // The sink was created successfully.
77 * }
78 * });
79 *
80 * //-
81 * // If the callback is omitted, we'll return a Promise.
82 * //-
83 * sink.create(config).then(data => {
84 * const sink = data[0];
85 * const apiResponse = data[1];
86 * });
87 *
88 * ```
89 * @example <caption>include:samples/sinks.js</caption>
90 * region_tag:logging_create_sink
91 * Another example:
92 */
93 create(config: CreateSinkRequest): Promise<[Sink, LogSink]>;
94 create(config: CreateSinkRequest, callback: CreateSinkCallback): void;
95 /**
96 * @typedef {array} DeleteSinkResponse
97 * @property {object} 0 The full API response.
98 */
99 /**
100 * @callback DeleteSinkCallback
101 * @param {?Error} err Request error, if any.
102 * @param {object} apiResponse The full API response.
103 */
104 /**
105 * Delete the sink.
106 *
107 * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/delete|projects.sink.delete API Documentation}
108 *
109 * @param {object} [gaxOptions] Request configuration options, outlined
110 * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
111 * @param {DeleteSinkCallback} [callback] Callback function.
112 * @returns {Promise<DeleteSinkResponse>}
113 *
114 * @example
115 * ```
116 * const {Logging} = require('@google-cloud/logging');
117 * const logging = new Logging();
118 * const sink = logging.sink('my-sink');
119 *
120 * sink.delete((err, apiResponse) => {
121 * if (!err) {
122 * // The log was deleted.
123 * }
124 * });
125 *
126 * //-
127 * // If the callback is omitted, we'll return a Promise.
128 * //-
129 * sink.delete().then(data => {
130 * const apiResponse = data[0];
131 * });
132 *
133 * ```
134 * @example <caption>include:samples/sinks.js</caption>
135 * region_tag:logging_delete_sink
136 * Another example:
137 */
138 delete(gaxOptions?: CallOptions): Promise<DeleteResponse>;
139 delete(callback: DeleteCallback): void;
140 delete(gaxOptions: CallOptions, callback: DeleteCallback): void;
141 /**
142 * @typedef {array} GetSinkMetadataResponse
143 * @property {object} 0 The {@link Sink} metadata.
144 * @property {object} 1 The full API response.
145 */
146 /**
147 * @callback GetSinkMetadataCallback
148 * @param {?Error} err Request error, if any.
149 * @param {object} metadata The {@link Sink} metadata.
150 * @param {object} apiResponse The full API response.
151 */
152 /**
153 * Get the sink's metadata.
154 *
155 * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks#LogSink|Sink Resource}
156 * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/get|projects.sink.get API Documentation}
157 *
158 * @param {object} [gaxOptions] Request configuration options, outlined
159 * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
160 * @param {SinkMetadataCallback} [callback] Callback function.
161 * @returns {Promise<SinkMetadataResponse>}
162 *
163 * @example
164 * ```
165 * const {Logging} = require('@google-cloud/logging');
166 * const logging = new Logging();
167 * const sink = logging.sink('my-sink');
168 *
169 * sink.getMetadata((err, metadata, apiResponse) => {});
170 *
171 * //-
172 * // If the callback is omitted, we'll return a Promise.
173 * //-
174 * sink.getMetadata().then(data => {
175 * const metadata = data[0];
176 * });
177 *
178 * ```
179 * @example <caption>include:samples/sinks.js</caption>
180 * region_tag:logging_get_sink
181 * Another example:
182 */
183 getMetadata(gaxOptions?: CallOptions): Promise<SinkMetadataResponse>;
184 getMetadata(callback: SinkMetadataCallback): void;
185 getMetadata(gaxOptions: CallOptions, callback: SinkMetadataCallback): void;
186 /**
187 * @typedef {array} SetSinkFilterResponse
188 * @property {object} 0 The full API response.
189 */
190 /**
191 * @callback SetSinkFilterCallback
192 * @param {?Error} err Request error, if any.
193 * @param {object} apiResponse The full API response.
194 */
195 /**
196 * Set the sink's filter.
197 *
198 * This will override any filter that was previously set.
199 *
200 * See {@link https://cloud.google.com/logging/docs/view/advanced_filters|Advanced Logs Filters}
201 *
202 * @param {string} filter The new filter.
203 * @param {SetSinkFilterCallback} [callback] Callback function.
204 * @returns {Promise<SetSinkFilterResponse>}
205 *
206 * @example
207 * ```
208 * const {Logging} = require('@google-cloud/logging');
209 * const logging = new Logging();
210 * const sink = logging.sink('my-sink');
211 *
212 * const filter = 'metadata.severity = ALERT';
213 *
214 * sink.setFilter(filter, (err, apiResponse) => {});
215 *
216 * //-
217 * // If the callback is omitted, we'll return a Promise.
218 * //-
219 * sink.setFilter(filter).then(data => {
220 * const apiResponse = data[0];
221 * });
222 * ```
223 */
224 setFilter(filter: string): Promise<SinkMetadataResponse>;
225 setFilter(filter: string, callback: SinkMetadataCallback): void;
226 /**
227 * @typedef {array} SetSinkMetadataResponse
228 * @property {object} 0 The full API response.
229 */
230 /**
231 * @callback SetSinkMetadataCallback
232 * @param {?Error} err Request error, if any.
233 * @param {object} apiResponse The full API response.
234 */
235 /**
236 * Set the sink's metadata.
237 *
238 * Note: If the sink was previously created or updated with
239 * uniqueWriterIdentity = true, then you must update the sink by setting
240 * uniqueWriterIdentity = true. Read more about using a unique writer identity
241 * here: https://cloud.google.com/logging/docs/api/tasks/exporting-logs#using_a_unique_writer_identity
242 *
243 * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks#LogSink|Sink Resource}
244 * See {@link https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/update|projects.sink.update API Documentation}
245 *
246 * @param {object} metadata See a
247 * [Sink
248 * resource](https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks#LogSink).
249 * @param {object} [metadata.gaxOptions] Request configuration options,
250 * outlined here:
251 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
252 * @param {SetSinkMetadataCallback} [callback] Callback function.
253 * @returns {Promise<SetSinkMetadataResponse>}
254 *
255 * @example
256 * ```
257 * const {Logging} = require('@google-cloud/logging');
258 * const logging = new Logging();
259 * const sink = logging.sink('my-sink');
260 *
261 * const metadata = {
262 * filter: 'metadata.severity = ALERT'
263 * };
264 *
265 * sink.setMetadata(metadata, (err, apiResponse) => {});
266 *
267 * //-
268 * // If the callback is omitted, we'll return a Promise.
269 * //-
270 * sink.setMetadata(metadata).then(data => {
271 * const apiResponse = data[0];
272 * });
273 *
274 * ```
275 * @example <caption>include:samples/sinks.js</caption>
276 * region_tag:logging_update_sink
277 * Another example:
278 */
279 setMetadata(metadata: SetSinkMetadata): Promise<SinkMetadataResponse>;
280 setMetadata(metadata: SetSinkMetadata, callback: SinkMetadataCallback): void;
281}
282/**
283 * Reference to the {@link Sink} class.
284 * @name module:@google-cloud/logging.Sink
285 * @see Sink
286 */
287export { Sink };