Skip to content

Commit

Permalink
Merge pull request #308 from OpenFn/pretty-logging
Browse files Browse the repository at this point in the history
Pretty logging
  • Loading branch information
josephjclark authored Jul 21, 2023
2 parents 4c875b3 + 749afe8 commit 97cc9f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-trainers-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/logger': patch
---

Pretty print output
2 changes: 1 addition & 1 deletion packages/logger/src/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type SanitizeOptions = {
const sanitize = (item: any, options: SanitizeOptions = {}) => {
// Stringify output to ensure we show deep nesting
const maybeStringify = (o: any) =>
options.stringify === false ? o : stringify(o);
options.stringify === false ? o : stringify(o, null, 2);

if (item instanceof Error) {
return item;
Expand Down
23 changes: 20 additions & 3 deletions packages/logger/test/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ test('should log objects as strings', (t) => {
logger.success(obj);

const { message } = logger._parse(logger._last);
t.is(message, '{"a":22}');
t.is(
message,
`{
"a": 22
}`
);

const messageObj = JSON.parse(message as string);
t.deepEqual(messageObj.a, 22);
Expand Down Expand Up @@ -346,7 +351,14 @@ test('log a circular object', async (t) => {
logger.success(a);

const { message } = logger._parse(logger._last);
t.is(message, '{"z":{"a":"[Circular]"}}');
t.is(
message,
`{
"z": {
"a": "[Circular]"
}
}`
);
});

test('log a circular object as JSON', async (t) => {
Expand Down Expand Up @@ -375,7 +387,12 @@ test('ignore functions on logged objects', async (t) => {
logger.success(obj);

const { message } = logger._parse(logger._last);
t.is(message, '{"a":1}');
t.is(
message,
`{
"a": 1
}`
);
});

test('log an error object', (t) => {
Expand Down

0 comments on commit 97cc9f3

Please sign in to comment.