Skip to content

Commit

Permalink
add auto batching entries (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovhemert committed Jul 20, 2021
1 parent 09dd369 commit 6e70027
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Type: `String` or `{ client_email: String, private_key: String }` *(optional)*
Full path to the JSON file containing the Google Service Credentials,
you can also use an object parameter with the client_email and the private_key instead of the path. Defaults to the GOOGLE_APPLICATION_CREDENTIALS environment variable. At least one has to be available.


#### projectId

Type: `String` *(required)*
Expand Down Expand Up @@ -72,6 +71,10 @@ Type: Boolean *(optional)*

Set the gRPC fallback option for the Google Stackdriver API.

## Batching

Log entries will automatically be batched by the Google cloud logging library that's being used internally using a *fire and forget* meganism.

## Prefixing messages

Prefixing message is supported via a `prefix` property from the log data:
Expand All @@ -89,4 +92,4 @@ Will send the following JSON payload to Stackdriver:
"message": "[foo] Info message"
// ...
}
```
```
5 changes: 4 additions & 1 deletion src/stackdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function _getKey (log, data, k, keys) {
return undefined
}

function _noop () {}

module.exports.parseJsonStream = function () {
return split2(_jsonParser)
}
Expand Down Expand Up @@ -108,7 +110,8 @@ module.exports.toStackdriverStream = function (options = {}) {
objectMode: true,
write (chunk, encoding, callback) {
const entry = log.entry(chunk.meta, chunk.data)
log[chunk.meta.severity](entry, callback)
log[chunk.meta.severity](entry, _noop)
callback()
}
})
return writableStream
Expand Down

0 comments on commit 6e70027

Please sign in to comment.