Skip to content

Commit 09dd369

Browse files
committed
2 parents 3293c21 + c4e709d commit 09dd369

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

docs/API.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const writeStream = stackdriver.createWriteStream({
3737

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

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

4343

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

7373
Set the gRPC fallback option for the Google Stackdriver API.
74+
75+
## Prefixing messages
76+
77+
Prefixing message is supported via a `prefix` property from the log data:
78+
79+
```js
80+
logger.info({ prefix: 'foo' }, 'Info message')
81+
logger.child({ prefix: 'foo' }).info('Info message')
82+
```
83+
84+
Will send the following JSON payload to Stackdriver:
85+
86+
```json
87+
{
88+
"prefix": "foo",
89+
"message": "[foo] Info message"
90+
// ...
91+
}
92+
```

src/stackdriver.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ module.exports.parseJsonStream = function () {
4747
}
4848

4949
module.exports.toLogEntry = function (log, options = {}) {
50-
const { labels, prefix, resource, keys } = options
50+
const { labels, resource, keys } = options
51+
const { prefix } = log
5152

5253
const severity = _levelToSeverity(log.level)
5354
let message = log.msg || log.message || severity

test/stackdriver.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ test('transforms custom log entry level', t => {
6464
test('prefixes log entry message', t => {
6565
t.plan(1)
6666

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

0 commit comments

Comments
 (0)