about summary refs log tree commit diff
path: root/src/logger/types.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-12-12 05:00:09 +0000
committerGitHub <noreply@github.com>2024-12-12 05:00:09 +0000
commit704e36c2801c4c06a3763eaef90c6a3e532a326d (patch)
tree79b5150a283af98c2197f69d2dea7679808c5a2b /src/logger/types.ts
parent20ac42a5a324ad553324d15ad868a1fea1868641 (diff)
downloadvoidsky-704e36c2801c4c06a3763eaef90c6a3e532a326d.tar.zst
Fix web build (#7069)
* Fix web build

* Fix circular deps

* Hoist log functions
Diffstat (limited to 'src/logger/types.ts')
-rw-r--r--src/logger/types.ts69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/logger/types.ts b/src/logger/types.ts
new file mode 100644
index 000000000..252e7373b
--- /dev/null
+++ b/src/logger/types.ts
@@ -0,0 +1,69 @@
+import type {Sentry} from '#/logger/sentry'
+
+export enum LogLevel {
+  Debug = 'debug',
+  Info = 'info',
+  Log = 'log',
+  Warn = 'warn',
+  Error = 'error',
+}
+
+export type Transport = (
+  level: LogLevel,
+  message: string | Error,
+  metadata: Metadata,
+  timestamp: number,
+) => void
+
+/**
+ * A union of some of Sentry's breadcrumb properties as well as Sentry's
+ * `captureException` parameter, `CaptureContext`.
+ */
+export type Metadata = {
+  /**
+   * Applied as Sentry breadcrumb types. Defaults to `default`.
+   *
+   * @see https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#breadcrumb-types
+   */
+  type?:
+    | 'default'
+    | 'debug'
+    | 'error'
+    | 'navigation'
+    | 'http'
+    | 'info'
+    | 'query'
+    | 'transaction'
+    | 'ui'
+    | 'user'
+
+  /**
+   * Passed through to `Sentry.captureException`
+   *
+   * @see https://github.com/getsentry/sentry-javascript/blob/903addf9a1a1534a6cb2ba3143654b918a86f6dd/packages/types/src/misc.ts#L65
+   */
+  tags?: {
+    [key: string]:
+      | number
+      | string
+      | boolean
+      | bigint
+      | symbol
+      | null
+      | undefined
+  }
+
+  /**
+   * Any additional data, passed through to Sentry as `extra` param on
+   * exceptions, or the `data` param on breadcrumbs.
+   */
+  [key: string]: unknown
+} & Parameters<typeof Sentry.captureException>[1]
+
+export type ConsoleTransportEntry = {
+  id: string
+  timestamp: number
+  level: LogLevel
+  message: string | Error
+  metadata: Metadata
+}