The SaaS Founder's Guide to Logging: What to Log and What Not to Log
Key Facts
Direct answer: The direct answer is that SaaS logging has three principles: log the right things (requests, errors, business events), do not log the wrong things (secrets, PII), and use structured logging (JSON, not plain text) for searchability. For more on logging, see our article on the logging gap .
What to Log: Log every HTTP request (method, URL, status, duration, IP, user ID).
What NOT to Log: Never log secrets (API keys, passwords, tokens, connection strings).
How to Log: Structured Logging: Use structured logging (JSON format), not plain text.
How to Search Logs: With structured logs, you can search by any field.
Logs are your eyes in production. Without them, you cannot diagnose issues, understand user behavior, or comply with audit requirements. But too many logs are noise — they make it harder to find the important information. This article is the SaaS founder's guide to what to log, what not to log, and how to make logs useful.
The direct answer is that SaaS logging has three principles: log the right things (requests, errors, business events), do not log the wrong things (secrets, PII), and use structured logging (JSON, not plain text) for searchability. For more on logging, see our article on the logging gap.
What to Log
1. Requests
Log every HTTP request (method, URL, status, duration, IP, user ID):
{
"level": "info",
"time": "2026-09-15T10:00:00Z",
"type": "request",
"method": "POST",
"url": "/api/users",
"status": 201,
"duration_ms": 45,
"ip": "1.2.3.4",
"userId": "123",
"requestId": "abc-123"
}This lets you answer: "How many requests per minute?" "What is the average response time?" "Which endpoints are slowest?"
2. Errors
Log every error (message, stack trace, request ID, user ID):
{
"level": "error",
"time": "2026-09-15T10:00:00Z",
"type": "error",
"message": "Database connection failed",
"stack": "Error: Database connection failed\n at ...",
"requestId": "abc-123",
"userId": "123"
}This lets you answer: "What errors occurred in the last hour?" "Which user was affected?" "What was the stack trace?"
3. Business Events
Log significant business events (signup, payment, plan change, cancellation):
{
"level": "info",
"time": "2026-09-15T10:00:00Z",
"type": "business_event",
"event": "payment_succeeded",
"userId": "123",
"amount": 29.00,
"plan": "pro"
}This lets you answer: "How many payments succeeded today?" "How many users upgraded to Pro?" "How many cancellations occurred?"
What NOT to Log
1. Secrets
Never log secrets (API keys, passwords, tokens, connection strings). If you log console.log(process.env), all your secrets appear in the logs, which is a security incident.
2. PII (Personally Identifiable Information)
Do not log PII (email addresses, phone numbers, addresses, credit card numbers). GDPR and CCPA require you to protect PII, and logging it creates a compliance risk.
If you need to log a user identifier, use the user ID (not the email): userId: "123" (not email: "[email protected]").
3. Request Bodies
Do not log full request bodies, because they might contain secrets or PII (e.g., passwords in login requests, credit card numbers in payment requests). Log the request method and URL, but not the body.
4. Verbose Debug Output
Do not log verbose debug output in production. Set the log level to INFO (not DEBUG), which filters out debug messages. If you need debug output for a specific issue, temporarily set the level to DEBUG for that component.
How to Log: Structured Logging
Use structured logging (JSON format), not plain text. Structured logs are searchable, filterable, and machine-readable:
// Bad (plain text)
console.log('User 123 logged in from 1.2.3.4');
// Good (structured)
logger.info({
type: 'auth',
event: 'login',
userId: '123',
ip: '1.2.3.4',
});Use a structured logger:
- Node.js: pino (fast, JSON output, built-in redaction)
- Python: structlog (JSON output, structured fields)
- Go: slog (standard library, JSON output)
For more on structured logging, see our article on the logging gap.
How to Search Logs
With structured logs, you can search by any field:
- Find all errors: level: "error"
- Find errors for a specific user: level: "error" AND userId: "123"
- Find errors for a specific request: requestId: "abc-123"
- Find slow requests: duration_ms > 1000
- Find business events: type: "business_event" AND event: "payment_succeeded"
Deployxa's dashboard includes a log viewer that supports search and filtering. You can also access logs via the CLI (deployxa logs) or the MCP server. For more, see our article on how we built the logging pipeline.
Log Levels
Use log levels to control verbosity:
- DEBUG. Detailed information for debugging (disabled in production).
- INFO. Normal events (requests, business events). Default level in production.
- WARN. Potential issues (e.g., rate limit exceeded, deprecated API used).
- ERROR. Errors that need attention (e.g., database connection failed).
- FATAL. Errors that crash the app (e.g., cannot start the server).
In production, set the level to INFO (which filters out DEBUG). When debugging an issue, temporarily set the level to DEBUG for the affected component.
Common Pitfalls and Troubleshooting
The first pitfall is logging secrets. If you log process.env or request bodies, secrets appear in the logs. The fix is to use a logger that supports redaction (like pino) and to redact sensitive fields.
The second pitfall is logging PII. If you log email addresses or phone numbers, you create a compliance risk. The fix is to log user IDs (not emails) and to never log PII.
The third pitfall is too many logs. If you log every database query, the logs are overwhelming and hard to search. The fix is to log at the INFO level (requests, errors, business events) and to use DEBUG for detailed information.
The fourth pitfall is not using structured logging. Plain-text logs are hard to search and filter. The fix is to use a structured logger (JSON format).
The fifth pitfall is not including request IDs. Without request IDs, you cannot trace a single request through the logs. The fix is to generate a unique request ID for each request and include it in every log entry.
Conclusion: Log Smart, Not More
Logs are your eyes in production, but too many logs are noise. By logging the right things (requests, errors, business events), not logging the wrong things (secrets, PII), and using structured logging (JSON), you can make your logs useful for debugging, monitoring, and compliance. The key is quality, not quantity.
Ready to improve your logging? Install a structured logger, add request IDs, and review what you are logging. For more, see the logging gap and monitoring your SaaS without hiring a DevOps engineer. Explore our free developer tools to speed up your workflow.