-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathlogger.ts
More file actions
43 lines (41 loc) · 1.01 KB
/
logger.ts
File metadata and controls
43 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { logger as sentryLogger } from '@sentry/core';
import * as Logger from 'effect/Logger';
/**
* Effect Logger that sends logs to Sentry.
*/
export const SentryEffectLogger = Logger.make(({ logLevel, message }) => {
let msg: string;
if (typeof message === 'string') {
msg = message;
} else if (Array.isArray(message) && message.length === 1) {
const firstElement = message[0];
msg = typeof firstElement === 'string' ? firstElement : JSON.stringify(firstElement);
} else {
msg = JSON.stringify(message);
}
switch (logLevel._tag) {
case 'Fatal':
sentryLogger.fatal(msg);
break;
case 'Error':
sentryLogger.error(msg);
break;
case 'Warning':
sentryLogger.warn(msg);
break;
case 'Info':
sentryLogger.info(msg);
break;
case 'Debug':
sentryLogger.debug(msg);
break;
case 'Trace':
sentryLogger.trace(msg);
break;
case 'All':
case 'None':
break;
default:
logLevel satisfies never;
}
});