Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 7fd01cf

Browse files
committed
📝 Update docs, changelog and meta
Related: #28
1 parent 424faae commit 7fd01cf

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Added
44
- parent logger name inheritance
5+
- logging to sentry
56

67
### Changed
78
- `pino.pretty` replaced with `util.inspect`

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ All loglevels up to warning (exclusive) - trace, debug and info - are logged to
8484

8585
All loglevels from warning up (inclusive) - warning, error, fatal - are logged to `stderr` **only**.
8686

87+
## Using Sentry
88+
89+
Cosmas logs every message to [Sentry](https://sentry.io/) for you, when configured. This feature is disabled by default.
90+
91+
Sentry SDK `@sentry/node` is a peer dependency. If you want cosmas to use it, install it in your project.
92+
93+
```js
94+
// (1) Let cosmas initialize sentry with provided DSN
95+
const myLogger = logger({ sentry: 'https://<key>@sentry.io/<project>' })
96+
97+
// (2) Configure sentry yourself and let cosmas use it
98+
Sentry.init({/*...*/})
99+
const myLogger = logger({ sentry: true })
100+
101+
// (3) Disable sentry (default, no need to send false option)
102+
const myLogger = logger({ sentry: false })
103+
```
104+
105+
When configured, cosmas (additionally to standard logging) captures all logs via Sentry SDK. Logs containing `stack` are logged as exceptions via `captureException` (preserves stack trace) and all other messages via `captureMessage`.
106+
107+
Either way, scope is appropriately set, as well as all payload is passed on in scope's metadata.
108+
109+
110+
87111
## Express middleware
88112

89113
`cosmas` contains an express middleware which you can use to log all requests and responses of your express application.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
]
2323
},
2424
"author": "Michal Vlasák <michal.vlasak@ackee.cz>",
25+
"contributors": [
26+
"Michal Vlasák <michal.vlasak@ackee.cz>",
27+
"Jaroslav Šmolík <grissius@gmail.com>"
28+
],
2529
"license": "ISC",
2630
"engines": {
2731
"node": ">=6"

0 commit comments

Comments
 (0)