-
Notifications
You must be signed in to change notification settings - Fork 38
feat: add client log transport #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ad6b08
043bad1
5cd30a8
3a73d82
5715a98
a246174
3662487
f0c9c89
19fd047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,12 @@ | ||||||||||||||
| import type { Log, LogLevel } from '../../types' | ||||||||||||||
| import type { Log, LogLevel, TransportConfig } from '../../types' | ||||||||||||||
| import { getConsoleMethod } from '../../utils' | ||||||||||||||
|
|
||||||||||||||
| const isClient = typeof window !== 'undefined' | ||||||||||||||
|
|
||||||||||||||
| let clientPretty = true | ||||||||||||||
| let clientService = 'client' | ||||||||||||||
| let transportEnabled = false | ||||||||||||||
| let transportEndpoint = '/api/_evlog/ingest' | ||||||||||||||
|
|
||||||||||||||
| const LEVEL_COLORS: Record<string, string> = { | ||||||||||||||
| error: 'color: #ef4444; font-weight: bold', | ||||||||||||||
|
|
@@ -13,9 +15,27 @@ const LEVEL_COLORS: Record<string, string> = { | |||||||||||||
| debug: 'color: #6b7280; font-weight: bold', | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function initLog(options: { pretty?: boolean, service?: string } = {}): void { | ||||||||||||||
| export function initLog(options: { pretty?: boolean, service?: string, transport?: TransportConfig } = {}): void { | ||||||||||||||
| clientPretty = options.pretty ?? true | ||||||||||||||
| clientService = options.service ?? 'client' | ||||||||||||||
| transportEnabled = options.transport?.enabled ?? false | ||||||||||||||
| transportEndpoint = options.transport?.endpoint ?? '/api/_evlog/ingest' | ||||||||||||||
| } | ||||||||||||||
|
HugoRCD marked this conversation as resolved.
|
||||||||||||||
|
|
||||||||||||||
| async function sendToServer(event: Record<string, unknown>): Promise<void> { | ||||||||||||||
| if (!transportEnabled) return | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| await fetch(transportEndpoint, { | ||||||||||||||
| method: 'POST', | ||||||||||||||
| headers: { 'Content-Type': 'application/json' }, | ||||||||||||||
| body: JSON.stringify(event), | ||||||||||||||
|
||||||||||||||
| body: JSON.stringify(event), | |
| body: JSON.stringify(event), | |
| credentials: 'same-origin', |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fetch call doesn't include the keepalive flag. When a page is being unloaded or navigated away from, logs sent at that moment might be cancelled before completion. Adding keepalive: true to the fetch options would ensure that the request continues even if the page is closed, improving reliability of log delivery during page transitions.
| body: JSON.stringify(event), | |
| body: JSON.stringify(event), | |
| keepalive: true, |
Uh oh!
There was an error while loading. Please reload this page.