@leaflink/snitch 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js.map +1 -1
- package/dist/transports/sentry.d.ts +4 -1
- package/dist/transports/sentry.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,27 @@
|
|
|
5
5
|
|
|
6
6
|
Simple and extensible browser logging, inspired by [Winston](https://github.com/winstonjs/winston).
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
10
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Transports](#transports)
|
|
15
|
+
- [Log Levels](#log-levels)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Singleton Logger](#singleton-logger)
|
|
18
|
+
- [New Logger](#new-logger)
|
|
19
|
+
- [Console Transport](#console-transport)
|
|
20
|
+
- [Sentry Transport](#sentry-transport)
|
|
21
|
+
- [Datadog Logs Transport](#datadog-logs-transport)
|
|
22
|
+
- [With Log Level](#with-log-level)
|
|
23
|
+
- [Custom Transports](#custom-transports)
|
|
24
|
+
- [Testing](#testing)
|
|
25
|
+
- [Stubbing snitch](#stubbing-snitch)
|
|
26
|
+
|
|
27
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
28
|
+
|
|
8
29
|
## Installation
|
|
9
30
|
|
|
10
31
|
`$ npm i @leaflink/snitch`
|
|
@@ -215,3 +236,20 @@ logger.add(new CustomTransport());
|
|
|
215
236
|
```
|
|
216
237
|
|
|
217
238
|
Note: You can add a custom transport in your project, but consider opening a PR in this repo instead!
|
|
239
|
+
|
|
240
|
+
## Testing
|
|
241
|
+
|
|
242
|
+
### Stubbing snitch
|
|
243
|
+
|
|
244
|
+
When there's a need to mock this logger or you want to test if a specific log was printed, you can just mock it inside you test file:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
import logger from '@leaflink/snitch';
|
|
248
|
+
|
|
249
|
+
vi.mock('@leaflink/snitch');
|
|
250
|
+
|
|
251
|
+
it('should redirect to error page if fetching the user profile fails', async () => {
|
|
252
|
+
// ...
|
|
253
|
+
expect(logger.error).toHaveBeenCalled();
|
|
254
|
+
})
|
|
255
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export interface Transport {
|
|
|
7
7
|
}
|
|
8
8
|
export declare class Logger {
|
|
9
9
|
transports: Transport[];
|
|
10
|
-
constructor(opts?:
|
|
10
|
+
constructor(opts?: {
|
|
11
|
+
transports: Transport[];
|
|
12
|
+
});
|
|
11
13
|
private _log;
|
|
12
14
|
debug(message: LogMessage, meta?: Record<string, unknown>): void;
|
|
13
15
|
info(message: LogMessage, meta?: Record<string, unknown>): void;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAUF,MAAM,OAAO,MAAM;IACjB,UAAU,CAAc;IAExB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAUF,MAAM,OAAO,MAAM;IACjB,UAAU,CAAc;IAExB,YAAY,IAAkC;QAC5C,IAAI,CAAC,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,EA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MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { LogLevel, Transport } from '../index.js';
|
|
2
2
|
export interface SentryTransportOptions {
|
|
3
3
|
level?: LogLevel;
|
|
4
|
-
sentryInstance:
|
|
4
|
+
sentryInstance: {
|
|
5
|
+
captureMessage: (message: string, sentryMeta: Record<string, unknown> | undefined) => void;
|
|
6
|
+
captureException: (message: object, sentryMeta: Record<string, unknown> | undefined) => void;
|
|
7
|
+
};
|
|
5
8
|
}
|
|
6
9
|
export declare class SentryTransport implements Transport {
|
|
7
10
|
level: LogLevel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/transports/sentry.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;CACf,CAAC;
|
|
1
|
+
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../src/transports/sentry.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;CACf,CAAC;AAUF,MAAM,OAAO,eAAe;IAC1B,KAAK,CAAW;IAChB,GAAG,CAAiG;IAEpG,YAAY,IAA4B;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC;QACnC,IAAI,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;YAClC,MAAM,UAAU,GAAG;gBACjB,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC;gBACjC,GAAG,IAAI;aACR,CAAC;YACF,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC/B,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;aACzD;iBAAM;gBACL,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;aAC3D;QACH,CAAC,CAAC;IACJ,CAAC;CACF"}
|