Skip to main content
pb-ext provides a comprehensive logging system built on PocketBase’s logger with structured field support, request tracing, automatic error handling, and panic recovery.

Key Features

  • Structured logging — key-value pairs for easy log parsing
  • Request tracing — unique trace IDs for request correlation
  • Automatic middleware — logs all HTTP requests with timing
  • Error handling — centralized error responses with stack traces
  • Panic recovery — graceful handling of runtime panics
  • PocketBase integration — uses PocketBase’s native logger
  • Selective exclusion — skip logging for static files and service workers

Setup

From core/logging/logging.go:118:

Request Middleware

From core/logging/logging.go:143:

Trace IDs

From core/logging/logging.go:27:
Every request gets a unique 18-character trace ID:
Use this ID to correlate logs, errors, and analytics for a single request.

Log Levels

From core/logging/logging.go:19:

Structured Logging

Info Logging

From core/logging/logging.go:75:
Usage:

Error Logging

From core/logging/logging.go:94:
Usage:

Direct PocketBase Logger Usage

Error Handling

From core/logging/error_handler.go:31:

Error Response Structure

From core/logging/error_handler.go:19:

Panic Recovery

From core/logging/error_handler.go:152:

Excluded Paths

From core/logging/logging.go:60:
These paths don’t generate logs to reduce noise from browser auto-requests.

Application Lifecycle Logging

From core/logging/logging.go:128:

Log Context Structure

From core/logging/logging.go:48:

Example Log Output

Request Log

Error Log

Panic Log

Best Practices

  1. Use trace IDs for request correlation across logs
  2. Log structured data with key-value pairs instead of concatenated strings
  3. Include context — user ID, record ID, operation name
  4. Set appropriate levels — Debug for verbose, Error for failures
  5. Don’t log sensitive data — passwords, tokens, PII
  6. Use WithGroup() to organize related logs
  7. Test panic recovery to ensure graceful error handling
  8. Monitor log volume — exclude noisy paths if needed

Integration with Error Types

From core/logging/error_handler.go:124: