Skip to content

Commit

Permalink
feat: add JSON Show instance
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jan 19, 2023
1 parent d85f040 commit 8e19bcb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/modules/index.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Added in v0.1.0
- [match](#match)
- [instances](#instances)
- [EqLogEntry](#eqlogentry)
- [JsonShowLogEntry](#jsonshowlogentry)
- [ShowLogEntry](#showlogentry)
- [debug](#debug)
- [debugP](#debugp)
Expand Down Expand Up @@ -98,6 +99,16 @@ export declare const EqLogEntry: E.Eq<LogEntry>
Added in v0.1.2
## JsonShowLogEntry
**Signature**
```ts
export declare const JsonShowLogEntry: S.Show<LogEntry>
```
Added in v0.2.2
## ShowLogEntry
**Signature**
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export const ShowLogEntry: Show<LogEntry> = {
}`,
}

/**
* @category instances
* @since 0.2.2
*/
export const JsonShowLogEntry: Show<LogEntry> = {
show: safeStringify,
}

/**
* Colorizes log entries based on the level.
*
Expand Down
13 changes: 13 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ describe('logger-fp-ts', () => {
})
})

test('JsonShowLogEntry', () => {
fc.assert(
fc.property(fc.logEntry(), logEntry => {
expect(JSON.parse(_.JsonShowLogEntry.show(logEntry))).toStrictEqual({
date: logEntry.date.toISOString(),
level: logEntry.level,
message: logEntry.message,
payload: logEntry.payload,
})
}),
)
})

describe('getColoredShow', () => {
test('with a DEBUG', () => {
fc.assert(
Expand Down

0 comments on commit 8e19bcb

Please sign in to comment.