Logger improvements (#7729)
* Remove enablement * Refactor context and filtering * Fix imports, simplify transports config * Migrate usages of debug context * Re-org, add colors and grouping to console logging * Remove temp default context * Remove manual prefix * Move colorizing out of console transport body * Reduce reuse * Pass through context * Ensure bitdrift is enabled in dev * Enable Sentry on web only * Clean up types * Docs * Format * Update tests * Clean up tests * No positional args * Revert Sentry changes * Clean up context, use it, pass metadata through to Bitdrift * Fix up debugging * Clean up metadata before passing to Bitdrift * Correct transports * Reserve context prop on metadata and include in transports * Update tests
This commit is contained in:
+31
-18
@@ -1,4 +1,15 @@
|
||||
import type {Sentry} from '#/logger/sentry'
|
||||
/**
|
||||
* DO NOT IMPORT THIS DIRECTLY
|
||||
*
|
||||
* Logger contexts, defined here and used via `Logger.Context.*` static prop.
|
||||
*/
|
||||
export enum LogContext {
|
||||
Default = 'logger',
|
||||
Session = 'session',
|
||||
Notifications = 'notifications',
|
||||
ConversationAgent = 'conversation-agent',
|
||||
DMsAgent = 'dms-agent',
|
||||
}
|
||||
|
||||
export enum LogLevel {
|
||||
Debug = 'debug',
|
||||
@@ -10,6 +21,7 @@ export enum LogLevel {
|
||||
|
||||
export type Transport = (
|
||||
level: LogLevel,
|
||||
context: LogContext | undefined,
|
||||
message: string | Error,
|
||||
metadata: Metadata,
|
||||
timestamp: number,
|
||||
@@ -20,6 +32,11 @@ export type Transport = (
|
||||
* `captureException` parameter, `CaptureContext`.
|
||||
*/
|
||||
export type Metadata = {
|
||||
/**
|
||||
* Reserved for appending `LogContext` to logging payloads
|
||||
*/
|
||||
context?: undefined
|
||||
|
||||
/**
|
||||
* Applied as Sentry breadcrumb types. Defaults to `default`.
|
||||
*
|
||||
@@ -43,27 +60,23 @@ export type Metadata = {
|
||||
* @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
|
||||
[key: string]: number | string | boolean | 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
|
||||
[key: string]: Serializable | Error | unknown
|
||||
}
|
||||
|
||||
export type Serializable =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| null
|
||||
| undefined
|
||||
| Serializable[]
|
||||
| {
|
||||
[key: string]: Serializable
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user