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

Commit 175800b

Browse files
author
Michal Vlasák
committed
🐛Move Sentry to separate file
1 parent 9ee35a4 commit 175800b

4 files changed

Lines changed: 21 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ You can enhance cosmas logger with automatic [Sentry](https://sentry.io/) loggin
9191
Sentry SDK `@sentry/node` is a peer dependency. If you want cosmas to use it, install it in your project.
9292

9393
```js
94-
import extendSentry from 'cosmas'
94+
import extendSentry from 'cosmas/sentry'
9595

9696
// (1) Let cosmas initialize sentry with provided DSN
9797
const myLogger = loggerFactory();

src/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Scope } from '@sentry/node';
21
import { ErrorRequestHandler } from 'express';
32
import * as fs from 'fs';
43
import isObject = require('lodash.isobject');
@@ -27,25 +26,6 @@ export interface Cosmas extends PinoLogger {
2726
(childName: string): Cosmas;
2827
}
2928

30-
export interface LogFnSentry {
31-
(msg: string, sentryCallback?: (scope: Scope) => void, ...args: any[]): void;
32-
<T extends object>(obj: T, sentryCallback?: (scope: Scope) => void, ...args: any[]): void;
33-
<T extends object>(obj: T, msg?: string, sentryCallback?: (scope: Scope) => void, ...args: any[]): void;
34-
}
35-
36-
export interface CosmasSentry extends Cosmas {
37-
fatal: LogFnSentry;
38-
error: LogFnSentry;
39-
warning: LogFnSentry;
40-
warn: LogFnSentry;
41-
info: LogFnSentry;
42-
debug: LogFnSentry;
43-
trace: LogFnSentry;
44-
silent: LogFnSentry;
45-
}
46-
47-
export * from './sentry';
48-
4929
export interface CosmasFactory extends Cosmas {
5030
(data?: string | CosmasOptions, loggerOptions?: CosmasOptions): Cosmas;
5131
}

src/sentry.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import { captureException, captureMessage, Scope, Severity, withScope } from '@sentry/node';
22
import { createNamespace } from 'cls-hooked';
33
import * as pino from 'pino';
4-
import { Cosmas, CosmasSentry } from '.';
4+
import { Cosmas } from '.';
55
import { levels } from './levels';
66

77
const clsNamespace = createNamespace('cosmas.sentryExtend');
88

99
type SentryCallback = (scope: Scope) => void;
1010

11+
export interface LogFnSentry {
12+
(msg: string, sentryCallback?: (scope: Scope) => void, ...args: any[]): void;
13+
<T extends object>(obj: T, sentryCallback?: (scope: Scope) => void, ...args: any[]): void;
14+
<T extends object>(obj: T, msg?: string, sentryCallback?: (scope: Scope) => void, ...args: any[]): void;
15+
}
16+
17+
export interface CosmasSentry extends Cosmas {
18+
fatal: LogFnSentry;
19+
error: LogFnSentry;
20+
warning: LogFnSentry;
21+
warn: LogFnSentry;
22+
info: LogFnSentry;
23+
debug: LogFnSentry;
24+
trace: LogFnSentry;
25+
silent: LogFnSentry;
26+
}
27+
1128
const reportToSentry = (obj: any) => {
1229
if (!obj.stack) {
1330
return captureMessage(obj.message || obj);

src/tests/sentry-mocked.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Scope } from '@sentry/node';
22
import omit = require('omit-deep');
3-
import { Cosmas, CosmasFactory, CosmasSentry } from '../index';
3+
import { Cosmas, CosmasFactory } from '../index';
44
import { levels } from '../levels';
5+
import { CosmasSentry } from '../sentry';
56

67
let loggerFactory: CosmasFactory;
78
let extendSentry: (logger: Cosmas, options: { sentry: string | true; sentryLevel?: number }) => CosmasSentry;

0 commit comments

Comments
 (0)