-
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add inset config option - ability to set log json data
#42
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -487,6 +487,7 @@ initLogger({ | |
| pretty?: boolean // Pretty print (default: true in dev) | ||
| stringify?: boolean // JSON.stringify output (default: true, false for Workers) | ||
| include?: string[] // Route patterns to log (glob), e.g. ['/api/**'] | ||
| inset?: string // Nest all log data inside this property | ||
| sampling?: { | ||
| rates?: { // Head sampling (random per level) | ||
| info?: number // 0-100, default 100 | ||
|
|
@@ -561,6 +562,29 @@ export default defineNitroPlugin((nitroApp) => { | |
| }) | ||
| ``` | ||
|
|
||
| ### Inset - Nesting Logs | ||
|
|
||
| By default, `pretty` is disabled, so evlog will log the object at root level when logging in production; however, for services like Cloudflare Observability, you may wish to nest the data inside an arbitrary property name. This can help organize your data and make it easier to query and analyze. | ||
|
|
||
| > **Note**: Nesting can have adverse effects if your logging system expects root-level json data, such as requestIds, or tracing ids. | ||
|
|
||
|
|
||
| In this example, your logs will then be nested under the `data` property: | ||
|
|
||
| ```json [Observability Logs] | ||
| { | ||
| "$data": { | ||
| "timestamp": "2026-02-05T06:48:18.122Z", | ||
| "level": "info", | ||
| "message": "This is an info log", | ||
| "method": "GET", | ||
| ... | ||
| }, | ||
| "$metadata": {...}, | ||
| "$workers": {...} | ||
| } | ||
| ``` | ||
|
|
||
| ### Pretty Output Format | ||
|
|
||
| In development, evlog uses a compact tree format: | ||
|
|
@@ -678,6 +702,8 @@ try { | |
| } | ||
| ``` | ||
|
|
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you pls remove this blank line |
||
|
|
||
| ## Framework Support | ||
|
|
||
| evlog works with any framework powered by [Nitro](https://nitro.unjs.io/): | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,8 @@ export default defineNuxtConfig({ | |||||
| include: ['/api/**'], | ||||||
| // Optional: exclude specific routes from logging | ||||||
| exclude: ['/api/_nuxt_icon/**'], | ||||||
| // Optional: nested property name for wide events | ||||||
| inset: 'evlog' | ||||||
| }, | ||||||
| }) | ||||||
| ``` | ||||||
|
|
@@ -60,6 +62,7 @@ export default defineNuxtConfig({ | |||||
| | `exclude` | `string[]` | `undefined` | Route patterns to exclude from logging. Supports glob (`/api/_nuxt_icon/**`). Exclusions take precedence over inclusions | | ||||||
| | `routes` | `Record<string, RouteConfig>` | `undefined` | Route-specific service configuration. Allows setting different service names for different routes using glob patterns | | ||||||
| | `pretty` | `boolean` | `true` in dev | Pretty print with tree formatting | | ||||||
| | `inset` | `string` | `'evlog'` | Nested property name for wide events | | ||||||
|
||||||
| | `inset` | `string` | `'evlog'` | Nested property name for wide events | | |
| | `inset` | `string` | `undefined` | Nested property name for wide events | |
Copilot
AI
Feb 6, 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.
Inconsistent formatting: There are triple backticks (```) used inline instead of single backticks (`). The word "pretty" should use single backticks for inline code formatting, not triple backticks.
| By default, evlog will log the object at root level when logging without ```pretty``` enabled (see [Configuration Options](/getting-started/installation#configuration-options)); however, for services like Cloudflare Observability, you may wish to nest the data inside an arbitrary property name. This can help organize your data and make it easier to query and analyze. | |
| By default, evlog will log the object at root level when logging without `pretty` enabled (see [Configuration Options](/getting-started/installation#configuration-options)); however, for services like Cloudflare Observability, you may wish to nest the data inside an arbitrary property name. This can help organize your data and make it easier to query and analyze. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,5 @@ export type { | |
| TailSamplingContext, | ||
| TransportConfig, | ||
| WideEvent, | ||
| InsetWideEvent | ||
| } from './types' | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||
| import { defu } from 'defu' | ||||||||
| import type { EnvironmentContext, Log, LogLevel, LoggerConfig, RequestLogger, RequestLoggerOptions, SamplingConfig, TailSamplingContext, WideEvent } from './types' | ||||||||
| import type { EnvironmentContext, InsetWideEvent, Log, LogLevel, LoggerConfig, RequestLogger, RequestLoggerOptions, SamplingConfig, TailSamplingContext, WideEvent } from './types' | ||||||||
| import { colors, detectEnvironment, formatDuration, getConsoleMethod, getLevelColor, isDev, matchesPattern } from './utils' | ||||||||
|
|
||||||||
| let globalEnv: EnvironmentContext = { | ||||||||
|
|
@@ -10,6 +10,7 @@ let globalEnv: EnvironmentContext = { | |||||||
| let globalPretty = isDev() | ||||||||
| let globalSampling: SamplingConfig = {} | ||||||||
| let globalStringify = true | ||||||||
| let globalInset: string | undefined = undefined | ||||||||
|
|
||||||||
| /** | ||||||||
| * Initialize the logger with configuration. | ||||||||
|
|
@@ -29,6 +30,7 @@ export function initLogger(config: LoggerConfig = {}): void { | |||||||
| globalPretty = config.pretty ?? isDev() | ||||||||
| globalSampling = config.sampling ?? {} | ||||||||
| globalStringify = config.stringify ?? true | ||||||||
| globalInset = config.inset ?? undefined | ||||||||
|
Comment on lines
13
to
33
|
||||||||
| globalInset = config.inset ?? undefined | |
| // Only accept non-empty strings for inset; treat empty or invalid values as undefined | |
| globalInset = typeof config.inset === 'string' && config.inset.trim() ? config.inset : undefined |
Copilot
AI
Feb 6, 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.
Redundant check: globalInset && globalInset !== undefined is redundant. The first condition globalInset already handles the undefined check since an empty string is falsy. This can be simplified to just globalInset.
| const formatted: InsetWideEvent | WideEvent = !globalPretty && globalInset && globalInset !== undefined ? { | |
| const formatted: InsetWideEvent | WideEvent = !globalPretty && globalInset ? { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -213,6 +213,8 @@ export interface LoggerConfig { | |||||
| * @default true | ||||||
| */ | ||||||
| stringify?: boolean | ||||||
| /** Nested property name for wide events */ | ||||||
| inset?: string; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -228,6 +230,13 @@ export interface BaseWideEvent { | |||||
| region?: string | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Wide event inside a nested propery from global config: inset | ||||||
|
||||||
| * Wide event inside a nested propery from global config: inset | |
| * Wide event inside a nested property from global config: inset |
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.
Spelling error: "Next" should be "Nest" in the description "Next evlog data inside a property".