1import { captureMessage, captureException, Severity as LogLevel } from '@sentry/browser';
2export { LogLevel };
3
4// a bit stricter than what Sentry allows
5type Contexts = Record<string, Record<string, number | string | Record<string, string | number>>>;
6
7/**
8 * Log a message at INFO level. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
9 *
10 * @public
11 */
12export function logInfo(message: string, contexts?: Contexts) {
13  captureMessage(message, {
14    level: LogLevel.Info,
15    contexts,
16  });
17}
18
19/**
20 * Log a message at WARNING level. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
21 *
22 * @public
23 */
24export function logWarning(message: string, contexts?: Contexts) {
25  captureMessage(message, {
26    level: LogLevel.Warning,
27    contexts,
28  });
29}
30
31/**
32 * Log a message at DEBUG level. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
33 *
34 * @public
35 */
36export function logDebug(message: string, contexts?: Contexts) {
37  captureMessage(message, {
38    level: LogLevel.Debug,
39    contexts,
40  });
41}
42
43/**
44 * Log an error. Depending on configuration might be forwarded to backend and logged to stdout or sent to Sentry
45 *
46 * @public
47 */
48export function logError(err: Error, contexts?: Contexts) {
49  captureException(err, { contexts });
50}
51