Use it to control log volume and cost.
Log Levels and Retention
Log levels (DEBUG, INFO, WARN, ERROR, FATAL) mark severity; retention decides how long logs are kept, often by level, source and compliance requirements.
1. Volume by level, e.g. LogQL sum by (level)(count_over_time({app="api"}[1h])).
2. DEBUG enabled in production?
3. Retention per stream/index.
4. Compliance requirements.
5. Adjust.
event severity → level → retention policy → deletion
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Search for a week-old event and confirm it is still available. Alert on sudden changes in error log volume.
Step 2 Common failures Narrow the fault
Logging every request at info on a busy service creates huge volume. Errors logged as info are never noticed. Short retention loses the evidence needed for slow-burning incidents.
Production at INFO; enable DEBUG temporarily. ERROR should mean someone may need to act. Retain security/audit logs longer than debug logs, and delete personal data per policy.
sum by (level)(count_over_time({app="api"}[1h]))— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool check config prometheus.yml— config valid
ReferenceWhat it is1 section · depth on demand
How it works
Log platforms charge or scale by ingest volume and retention. Hot storage keeps recent logs fast; cold or archive tiers keep older logs cheaply.
ReferenceImportant terms & boundaries3 sections · depth on demand
Levels and retention
| Level | Use |
|---|---|
| DEBUG | Developer detail; off in production by default |
| INFO | Normal significant events |
| WARN | Unexpected but handled |
| ERROR | Failed operation needing attention |
| FATAL | Process cannot continue |
Retention example: 7–14 days hot (searchable), 90 days warm, 1 year+ archive for security logs (check legal requirements, NIS2/GDPR). Make log levels changeable at runtime to debug without redeploys.
In depth
Choosing levels by who acts on them
| Level | Someone should… | Typical volume |
|---|---|---|
| ERROR | Look at it — something failed for a user or a job | Low; alert on rate |
| WARN | Be able to find it — degraded, retried, fell back | Low–medium |
| INFO | Understand the flow afterwards — one line per significant event, not per loop iteration | Medium |
| DEBUG/TRACE | Diagnose a specific problem, switched on temporarily | High |
An error that is expected and handled (a user typing a wrong password) is INFO or WARN; logging it as ERROR teaches everyone to ignore errors.
Changing level without redeploying
Make the level configurable per logger or module at runtime (environment variable reread, admin endpoint, feature flag) so DEBUG can be enabled for one component for 15 minutes during an incident and switched off again.
Retention by purpose
| Data | Typical retention | Storage |
|---|---|---|
| Application debug/info | 7–30 days | Hot, searchable |
| Errors and warnings | 30–90 days | Hot or warm |
| Security and audit logs | 1 year or more (per policy and law) | Cold/archive, immutable |
| Access logs with personal data | As short as the purpose allows (GDPR) | — |
In Loki, retention is applied by the compactor (retention_enabled: true) with a global retention_period and per-stream overrides:
limits_config:
retention_period: 744h # 31 days default
retention_stream:
- selector: '{namespace="security"}'
priority: 1
period: 8760h # 1 year
Controlling volume
Sample or drop noisy lines in the collector (health-check access logs, repetitive debug), and track ingest volume per service so a logging bug in one release shows up as a cost spike the same day, not on the monthly bill.
Common mistakes
- DEBUG level in production.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.