Sink
A sink is an object that lets you to specify a set of log entries to export to a particular destination. Stackdriver Logging lets you export log entries to destinations including Cloud Storage buckets (for long term log storage), Google BigQuery datasets (for log analysis), Google Pub/Sub (for streaming to other applications).
Constructor
Sink
new Sink(logging, name)
Parameter |
|
---|---|
logging |
Logging instance. |
name |
string Name of the sink. |
- See also
Example
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const sink = logging.sink('my-sink');
Property
name
string
Methods
create
create(config, callback) returns Promise containing CreateSinkResponse
Create a sink.
Parameter |
|
---|---|
config |
Config to set for the sink. |
callback |
Optional Callback function. |
- See also
- Logging#createSink
- Throws
-
Error
if a config object is not provided.
- Returns
-
Promise containing CreateSinkResponse
Example
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const sink = logging.sink('my-sink');
const config = {
destination: {
// ...
}
};
sink.create(config, (err, sink, apiResponse) => {
if (!err) {
// The sink was created successfully.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
sink.create(config).then(data => {
const sink = data[0];
const apiResponse = data[1];
});
Another example:
delete
delete(gaxOptions, callback) returns Promise containing DeleteSinkResponse
Delete the sink.
Parameter |
|
---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions. |
callback |
Optional Callback function. |
- See also
- Returns
-
Promise containing DeleteSinkResponse
Example
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const sink = logging.sink('my-sink');
sink.delete((err, apiResponse) => {
if (!err) {
// The log was deleted.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
sink.delete().then(data => {
const apiResponse = data[0];
});
Another example:
getMetadata
getMetadata(gaxOptions, callback) returns Promise containing GetSinkMetadataResponse
Get the sink's metadata.
Parameter |
|
---|---|
gaxOptions |
Optional object Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions. |
callback |
Optional Callback function. |
- See also
- Returns
-
Promise containing GetSinkMetadataResponse
Example
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const sink = logging.sink('my-sink');
sink.getMetadata((err, metadata, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
sink.getMetadata().then(data => {
const metadata = data[0];
const apiResponse = data[1];
});
Another example:
setFilter
setFilter(filter, callback) returns Promise containing SetSinkFilterResponse
Set the sink's filter.
This will override any filter that was previously set.
Parameter |
|
---|---|
filter |
string The new filter. |
callback |
Optional Callback function. |
- See also
- Returns
-
Promise containing SetSinkFilterResponse
Example
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const sink = logging.sink('my-sink');
const filter = 'metadata.severity = ALERT';
sink.setFilter(filter, (err, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
sink.setFilter(filter).then(data => {
const apiResponse = data[0];
});
setMetadata
setMetadata(metadata, callback) returns Promise containing SetSinkMetadataResponse
Set the sink's metadata.
Parameter |
|||||
---|---|---|---|---|---|
metadata |
object See a Sink resource. Values in
|
||||
callback |
Optional Callback function. |
- See also
- Returns
-
Promise containing SetSinkMetadataResponse
Example
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const sink = logging.sink('my-sink');
const metadata = {
filter: 'metadata.severity = ALERT'
};
sink.setMetadata(metadata, (err, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
sink.setMetadata(metadata).then(data => {
const apiResponse = data[0];
});
Another example: