Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ovhemert committed Jul 19, 2021
2 parents 3293c21 + c4e709d commit 09dd369
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
21 changes: 20 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const writeStream = stackdriver.createWriteStream({

Type: `String` or `{ client_email: String, private_key: String }` *(optional)*

Full path to the JSON file containing the Google Service Credentials,
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.


Expand Down Expand Up @@ -71,3 +71,22 @@ supports `httpRequest`, `trace`. Defaults to `{ httpRequest: "httpRequest" }`.
Type: Boolean *(optional)*

Set the gRPC fallback option for the Google Stackdriver API.

## Prefixing messages

Prefixing message is supported via a `prefix` property from the log data:

```js
logger.info({ prefix: 'foo' }, 'Info message')
logger.child({ prefix: 'foo' }).info('Info message')
```

Will send the following JSON payload to Stackdriver:

```json
{
"prefix": "foo",
"message": "[foo] Info message"
// ...
}
```
3 changes: 2 additions & 1 deletion src/stackdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module.exports.parseJsonStream = function () {
}

module.exports.toLogEntry = function (log, options = {}) {
const { labels, prefix, resource, keys } = options
const { labels, resource, keys } = options
const { prefix } = log

const severity = _levelToSeverity(log.level)
let message = log.msg || log.message || severity
Expand Down
4 changes: 2 additions & 2 deletions test/stackdriver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ test('transforms custom log entry level', t => {
test('prefixes log entry message', t => {
t.plan(1)

const log = { level: 30, time: parseInt('1532081790730', 10), msg: 'info message', pid: 9118, hostname: 'Osmonds-MacBook-Pro.local', v: 1 }
const entry = tested.toLogEntry(log, { prefix: 'INFO' })
const log = { level: 30, time: parseInt('1532081790730', 10), msg: 'info message', pid: 9118, hostname: 'Osmonds-MacBook-Pro.local', prefix: 'INFO' }
const entry = tested.toLogEntry(log)
t.ok(entry.data.message.startsWith('[INFO] '))
})

Expand Down

0 comments on commit 09dd369

Please sign in to comment.