stacks-logging

$npx mdskill add stacksjs/stacks/stacks-logging

Implement logging in Stacks using the log facade, dump/dd, timing, and file-based logging.

  • Log messages at various levels (info, error, warn, debug, success).
  • Depends on @stacksjs/clarity Logger and config/logging.ts.
  • Uses log facade methods and timing functions based on developer intent.
  • Writes logs to storage/logs/stacks.log and supports dump/dd for debugging.

SKILL.md

.github/skills/stacks-loggingView on GitHub ↗
---
name: stacks-logging
description: Use when implementing logging in Stacks — the log facade (info, error, warn, debug, success), dump/dd debugging, timing functions, file-based logging, or log configuration. Covers @stacksjs/logging and config/logging.ts.
license: MIT
compatibility: Bun >= 1.3.0, TypeScript
allowed-tools: Read Edit Write Bash Grep Glob
---

# Stacks Logging

Uses @stacksjs/clarity Logger with file writing to `storage/logs/stacks.log`.

## Key Paths
- Core package: `storage/framework/core/logging/src/`
- Configuration: `config/logging.ts`
- Log model: `storage/framework/models/Log.ts`
- Log file: `storage/logs/stacks.log`

## Log Facade

```typescript
import { log } from '@stacksjs/logging'

await log.info('User created', { userId: 1 })
await log.success('Deployment complete')
await log.warn('Rate limit approaching', { remaining: 10 })
await log.warning('Alias for warn')
await log.error(new Error('Something failed'), { context: 'handler' })
await log.debug('Debug info', { query: 'SELECT ...' })
```

### Error with Exit
```typescript
await log.error(err, { shouldExit: true })  // logs and exits process
```

## Dump & Die

```typescript
import { dump, dd, echo } from '@stacksjs/logging'

await dump(variable1, variable2)    // inspect without stopping
await dd(variable1, variable2)      // inspect and exit (never returns)
await echo('simple output')
```

## Timing

```typescript
const done = log.time('database-query')
await performQuery()
await done()  // logs elapsed time
```

## Logger Instance

```typescript
import { logger } from '@stacksjs/logging'

const l = logger  // underlying clarity Logger instance
```

## config/logging.ts
```typescript
{
  logsPath: 'storage/logs',
  deploymentsPath: 'storage/logs/deployments'
}
```

## Gotchas
- All log methods are async — they write to both console and file
- Log file is at `storage/logs/stacks.log`
- `dd()` never returns — it exits the process after dumping
- `dump()` continues execution — use for non-destructive debugging
- The Log model enables database-backed log storage and querying
- Error logging can optionally exit the process with `shouldExit: true`
- Logging is a dependency of many other packages — it's available everywhere

More from stacksjs/stacks

SkillDescription
stacks-actionsUse when working with Stacks server actions — creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the 80+ default framework actions (auth, dashboard, commerce, content, deployment, jobs), action request/response handling, or action registration. Covers @stacksjs/actions and storage/framework/defaults/actions/.
stacks-aiUse when integrating AI capabilities into a Stacks application — using Anthropic/OpenAI/Ollama/AWS Bedrock drivers, image generation (DALL-E), vision analysis, RAG/vector search, embeddings, MCP (Model Context Protocol) clients, text summarization, sentiment analysis, content classification, personalization, or the buddy AI assistant. Covers @stacksjs/ai and config/ai.ts.
stacks-aliasUse when working with path aliases in a Stacks project — import resolution, module aliasing, or debugging import paths. Covers @stacksjs/alias which defines 260+ path mappings for the entire framework.
stacks-analyticsUse when adding analytics to a Stacks application — configuring Fathom or self-hosted analytics, generating tracking scripts, privacy-friendly analytics setup, or the analytics configuration. Covers @stacksjs/analytics and config/analytics.ts.
stacks-apiUse when building, modifying, or debugging API endpoints in a Stacks application — defining routes, handling requests, API middleware, working with the API server, HTTP client (fetcher), API resources, or OpenAPI generation. Covers both @stacksjs/api utilities and the stacks-api server implementation.
stacks-arraysUse when working with array utilities in Stacks — statistical operations (average, median, mode, standard deviation, z-score, percentile, covariance), array manipulation (unique, flatten, partition, shuffle, sample, move), containment checks, or the Arr facade. Covers @stacksjs/arrays.
stacks-authUse when implementing authentication, authorization, passkeys, TOTP/2FA, RBAC, gates, policies, session auth, token management, email verification, password resets, or rate limiting in a Stacks application. Covers the @stacksjs/auth package, config/auth.ts, app/Gates.ts, and app/Middleware/.
stacks-auto-importsUse when working with the Stacks auto-import system — understanding how browser and server auto-imports work, configuring auto-imported functions/models/composables, the auto-import manifests, type generation, or how globals are injected. Covers the auto-import pipeline at storage/framework/auto-imports/.
stacks-brandkitUse when defining or exploring a brand identity for a Stacks project and you want premium brand-kit REFERENCE IMAGES first - logo directions, palettes, typography specimens, identity boards, and application/mockup decks. Generates IMAGES ONLY, never code. Trained for minimalist, cinematic, editorial, dark-tech, luxury, cultural, security, gaming, developer-tool, and consumer-app brand systems with intentional logo concepting, sparse type, strong symbolic meaning, and disciplined palettes a coding step can build against.
stacks-browseUse for headless browser QA on Stacks applications — navigation, screenshots, responsive testing, console/network monitoring, and accessibility snapshots. Dependency-free: drives a system browser over the Chrome DevTools Protocol using only Bun (no Playwright/Puppeteer). Invoke with /stacks-browse.