Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thank you for following the naming conventions! 🙏 |
info() and warn() methodsinfo() and warn() methods
info() and warn() methodsinfo() and warn() methods to logger
commit: |
There was a problem hiding this comment.
Pull request overview
Adds request-scoped info() / warn() methods to the evlog request logger so intermediate messages can be captured into the final “wide event” (including final-level escalation to warn when warnings occurred), rather than emitted as standalone logs.
Changes:
- Extend
RequestLoggerwithinfo(message, context?)andwarn(message, context?). - Introduce
RequestLogEntryand store per-request entries oncontext.logs. - Add unit tests validating log capture, ordering, context merging, and warn-level escalation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/evlog/src/logger.ts |
Implements request-scoped info()/warn(), accumulates entries into context.logs, and escalates emitted level to warn when applicable. |
packages/evlog/src/types.ts |
Adds RequestLogEntry and extends RequestLogger/InternalFields to type the new behavior. |
packages/evlog/test/logger.test.ts |
Adds tests for info()/warn() capture, ordering, context merge behavior, and warn escalation at emit time. |
Comments suppressed due to low confidence (1)
packages/evlog/src/types.ts:340
- Adding
logstoInternalFieldsmakeslogsa reserved key that is omitted from user-defined field types (FieldContextisOmit<T, keyof InternalFields> & InternalFields). This is a potentially breaking API change for consumers that already have alogsfield in their typed request context. If backwards compatibility is a concern, consider using a less collision-prone internal name (e.g.,requestLogs/_logs) or clearly documentinglogsas reserved in the public API/changelog.
export interface InternalFields {
status?: number
service?: string
logs?: RequestLogEntry[]
}
/**
* Request-scoped log entry captured during a request lifecycle.
*/
export interface RequestLogEntry {
level: 'info' | 'warn'
message: string
timestamp: string
}
/**
* Resolved context type for logger methods.
* User fields are deeply partial (matching deep merge behavior) with internal
* field keys omitted to avoid intersection conflicts, then internal fields
* are added back with their canonical types.
*/
export type FieldContext<T extends object = Record<string, unknown>> =
DeepPartial<Omit<T, keyof InternalFields>> & InternalFields
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
packages/evlog/src/logger.ts:304
info()/warn()explicitly strip alogskey from the provided context to avoid clobbering accumulated request logs, but other entry points can still overwritecontext.logs(e.g.set(),error(..., context), andemit(overrides)acceptFieldContextwhich now includeslogs). Consider also omitting/ignoringlogsin those merge paths and/or tightening parameter types (e.g.Omit<FieldContext<T>, 'logs'>) so request log accumulation can’t be accidentally replaced.
}
return {
set(data: FieldContext<T>): void {
context = deepDefaults(data as Record<string, unknown>, context) as Record<string, unknown>
},
error(error: Error | string, errorContext?: FieldContext<T>): void {
hasError = true
const err = typeof error === 'string' ? new Error(error) : error
const errorData = {
...(errorContext as Record<string, unknown>),
error: {
name: err.name,
message: err.message,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| : T | ||
|
|
||
| /** | ||
| * Fields set internally by the evlog plugin (status, service, etc.). | ||
| * These are always accepted by `set()` regardless of the user-defined field type. | ||
| */ | ||
| export interface InternalFields { | ||
| status?: number | ||
| service?: string | ||
| logs?: RequestLogEntry[] | ||
| } | ||
|
|
||
| /** | ||
| * Request-scoped log entry captured during a request lifecycle. |
There was a problem hiding this comment.
logs is added to InternalFields, which makes logs a reserved key in FieldContext (it gets omitted from user-defined field types). This is a potentially breaking TypeScript change for consumers that previously had their own logs field in their request context. Consider renaming this internal field to something less collision-prone (e.g. requestLogs) or otherwise documenting/mitigating the reserved-key change.
This pull request enhances the request-scoped logging capabilities in the
evlogpackage by introducing structured support for informational and warning log messages within a request's lifecycle. It adds new logging methods, updates type definitions, and expands test coverage to ensure correct behavior and log escalation.