-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When you use the `aws logs tail` command, it outputs non-JSON along with the JSON log entries. For example: ```bash 2024-01-01T19:52:19 {"level":20,"time":1704138739937,"pid":8,"hostname":"169.254.43.189","source":"search/src/lib/typesense.ts","msg":"found 20 records not in index"} ``` This change allows piping this type of output and having pjl still be able to parse the log entry. In theory, we could output the extraneous non-JSON data to stdout, but I don't personally need that, so I didn't implement it. FYI, I use pino to output JSON log entries from an AWS Lambda function. --------- Co-authored-by: Blayne Chard <[email protected]>
- Loading branch information
Showing
4 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import assert from 'node:assert'; | ||
import { describe, it } from 'node:test'; | ||
|
||
import { tryGetJson } from './transform.js'; | ||
|
||
describe('transform', () => { | ||
describe('tryGetJson', () => { | ||
it('returns null for invalid JSON', () => { | ||
assert.strictEqual(tryGetJson(''), null); | ||
assert.strictEqual(tryGetJson('foo'), null); | ||
assert.strictEqual(tryGetJson('{"foo":'), null); | ||
assert.strictEqual(tryGetJson('2024-01-01T19:53:58 {"foo":'), null); | ||
assert.strictEqual(tryGetJson('2024-01-01T19:53:58 {"foo": "bar"}}'), null); | ||
}); | ||
|
||
it('returns the parsed JSON', () => { | ||
assert.deepStrictEqual(tryGetJson('{}'), {}); | ||
assert.deepStrictEqual(tryGetJson('{"foo": "bar"}'), { foo: 'bar' }); | ||
assert.deepStrictEqual(tryGetJson('2024-01-01T19:53:58 {"foo": "bar"}'), { foo: 'bar' }); | ||
assert.deepStrictEqual(tryGetJson('2024-01-01T19:53:58 {"foo": "bar"} garbage'), { foo: 'bar' }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters