Skip to content

(v1) Injectable logger API across ArkEnv packages #1300

Description

@yamcodes

Summary

Introduce a user-configurable logging abstraction for ArkEnv — log levels, silent mode, and custom logger injection — unifying the currently separate logging surfaces across build integrations, CLI, and runtime packages.

Follows: #1237 (Phase 1 — finish @arkenv/build/log migration on v1)

Problem

After Phase 1 (#1237) and PR #1294, ArkEnv will have consistent prefix formatting, but logging remains fragmented:

  • @arkenv/build/log — static helpers that call console.* directly (logBuildWarning, logBuildError, etc.)
  • @arkenv/build Logger type — minimal optional { error, info? } passed to watcher callbacks
  • CLI LoggerPort — rich CLI-specific interface (spinners, JSON mode, --quiet, fatal, flush)
  • ArkEnvError — thrown validation errors with styled formatting (separate from logging; done in (v1) Unify error normalization and formatting #1157)

There is no way for consumers to suppress warnings, redirect output, or provide a custom logger across integrations. Each surface was designed independently.

Desired behavior

A shared, injectable logger API that:

  • Lets consumers provide a custom logger instance or configure log level / silent mode
  • Works across Node, Bun, and browser-compatible packages (no Node-only assumptions in shared code)
  • Keeps thrown validation errors (ArkEnvError) separate from logged warnings/errors
  • Subsumes or bridges the existing @arkenv/build Logger type and @arkenv/build/log static helpers without breaking Phase 1 output format
  • Does not require CLI-specific features (spinners, JSON reporters) in the shared interface — CLI LoggerPort may adapt the shared type

Open design questions

  1. Package placement: New internal package (e.g. @arkenv/log or @repo/log), module inside @arkenv/internal/utils, or extension of @arkenv/build/log?
  2. API surface: Which methods? (error, warn, info, debug?) Support silent mode, env-driven log levels (ARKENV_LOG_LEVEL?), user-provided instances?
  3. Runtime constraints: How do browser-compatible packages avoid Node-only behavior (e.g. process.exit in Next.js config on validation failure)?
  4. Relationship to CLI: Should LoggerPort implement/extend the shared interface, or remain a CLI-only adapter that wraps it?
  5. Relationship to ArkEnvError: Keep formatting in the throw path, or allow the logger to control output style for validation failures?

Prerequisites

Acceptance criteria

  • Shared logger interface defined and published (or internal-only, with clear export path)
  • Build integrations (@arkenv/build, @arkenv/nextjs, @arkenv/nuxt, @arkenv/bun-plugin, @arkenv/vite-plugin) accept an optional logger and fall back to sensible defaults
  • Silent / log-level configuration supported (env var and/or programmatic)
  • CLI LoggerPort integrates with the shared interface without losing JSON/quiet/spinner behavior
  • ArkEnvError throw behavior unchanged unless explicitly redesigned and documented
  • Browser-compatible packages do not introduce Node-only APIs in the shared logger
  • Tests cover custom logger injection, silent mode, and default fallback behavior
  • Changesets for affected published packages
  • Documentation updated with logger configuration examples

Out of scope

Target branch

v1 — v1 is the upcoming breaking release; new cross-cutting APIs belong here, not on dev (v0 maintenance).

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvementready for agentFully specified, ready for immediate implementation

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions