Logger
Structured logging with Pino.
QUESTPIE uses Pino for structured, high-performance JSON logging.
Usage
Access the logger through the context in hooks, routes, jobs, and services:
handler: async ({ logger }) => {
logger.info("Processing request");
logger.warn({ userId: "abc" }, "Rate limit approaching");
logger.error({ err: error }, "Failed to process payment");
};Log Levels
| Level | Value | Usage |
|---|---|---|
trace | 10 | Verbose debugging (hidden by default) |
debug | 20 | Development debugging |
info | 30 | Normal operations (default minimum) |
warn | 40 | Potential issues, deprecations |
error | 50 | Errors that need attention |
fatal | 60 | Critical failures, process should exit |
Structured Logging
Pass an object as the first argument for structured data. Pino serializes it as JSON fields:
logger.info(
{
appointmentId: "abc",
action: "created",
barberId: "def",
duration: 45,
},
"Appointment created",
);Output (JSON):
{
"level": 30,
"time": 1710854400000,
"appointmentId": "abc",
"action": "created",
"barberId": "def",
"duration": 45,
"msg": "Appointment created"
}Child Loggers
Create scoped loggers with persistent context:
const bookingLogger = logger.child({ module: "booking", requestId: "req-123" });
bookingLogger.info("Checking availability");
// → { module: "booking", requestId: "req-123", msg: "Checking availability" }Error Logging
Use the err key for Error objects — Pino serializes the stack trace:
try {
await processPayment(orderId);
} catch (error) {
logger.error({ err: error, orderId }, "Payment processing failed");
}Configuration
The log level defaults to info. Set it via environment variable:
LOG_LEVEL=debugPretty Printing (Development)
In development, pipe output through pino-pretty for human-readable logs:
{
"scripts": {
"dev": "questpie dev | pino-pretty"
}
}Production Best Practices
- Use
infolevel in production (default) - Ship JSON logs to your observability platform (Datadog, Grafana, etc.)
- Use structured fields for queryable metadata
- Avoid logging sensitive data (passwords, tokens, PII)
- Use child loggers to add request context automatically
Related Pages
- Deployment — Production setup
- Config API — Application configuration