You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API includes an optional admin panel for managing users and API keys through a web interface. It's disabled by default and must be explicitly enabled.
223
+
224
+
!!! info "Admin Panel Access"
225
+
Only existing admin users can access the admin panel. See the [Admin Panel Documentation](../admin-panel.md) for details on usage and features.
226
+
227
+
### Enable Admin Pages
228
+
229
+
Set this to `True` to enable the admin panel web interface:
230
+
231
+
```ini
232
+
ADMIN_PAGES_ENABLED=True
233
+
```
234
+
235
+
When enabled, the admin panel will be accessible at the route specified in `ADMIN_PAGES_ROUTE`. When disabled (default), the admin routes return a 404 error.
236
+
237
+
### Customize Admin Pages Route
238
+
239
+
The admin panel is accessible at `/admin` by default. You can customize this:
240
+
241
+
```ini
242
+
ADMIN_PAGES_ROUTE=/admin
243
+
```
244
+
245
+
You can change this to any route you prefer, for example `/management` or `/dashboard`. The route must start with a forward slash (`/`).
246
+
247
+
### Customize Admin Panel Title
248
+
249
+
The title shown in the browser tab and page header:
250
+
251
+
```ini
252
+
ADMIN_PAGES_TITLE="API Administration"
253
+
```
254
+
255
+
Customize this to match your application name or branding.
256
+
257
+
### Session Encryption Key
258
+
259
+
!!! danger "Critical Security Setting"
260
+
This key encrypts admin session tokens. Treat it like your SECRET_KEY - keep it secret, unique per environment, never commit to version control, and regenerate if compromised.
261
+
262
+
The encryption key for admin session tokens:
263
+
264
+
```ini
265
+
ADMIN_PAGES_ENCRYPTION_KEY=
266
+
```
267
+
268
+
**Behavior:**
269
+
270
+
-**Empty (default):** Auto-generates a new key on each server startup
271
+
- Sessions are invalidated when the server restarts
272
+
- Admins must re-login after each restart
273
+
- Fine for development
274
+
-**Set with a key:** Persistent sessions across server restarts
The API uses loguru for structured logging with rotation, retention, and category-based filtering. Logging provides debugging, monitoring, and compliance capabilities.
335
+
336
+
!!! note "Console Logging"
337
+
FastAPI/Uvicorn already log to console. The file-based logging configured here is in addition to that and provides persistent, categorized logs.
338
+
339
+
### Log Output Directory
340
+
341
+
Directory where log files are written:
342
+
343
+
```ini
344
+
LOG_PATH=./logs
345
+
```
346
+
347
+
Default is `./logs` (relative to project root). The directory must be writable by the application process. You can use absolute paths for production:
| API_KEYS | API key operations | Production (security) |
454
+
455
+
**Configuration examples:**
456
+
457
+
```ini
458
+
# Development: log everything
459
+
LOG_CATEGORIES=ALL
460
+
461
+
# Production: security-focused
462
+
LOG_CATEGORIES=ERRORS,AUTH,ADMIN,EMAIL
463
+
464
+
# Production: minimal logging
465
+
LOG_CATEGORIES=ERRORS
466
+
467
+
# Debugging database issues
468
+
LOG_CATEGORIES=ERRORS,DATABASE,REQUESTS
469
+
470
+
# Comprehensive monitoring
471
+
LOG_CATEGORIES=ERRORS,AUTH,ADMIN,EMAIL,DATABASE
472
+
473
+
# Disable all logging
474
+
LOG_CATEGORIES=NONE
475
+
```
476
+
477
+
!!! tip "Production Recommendation"
478
+
For production, use `LOG_CATEGORIES=ERRORS,AUTH,ADMIN,EMAIL` with `LOG_LEVEL=INFO`. This provides security monitoring (AUTH/ADMIN), error tracking (ERRORS), and email operation logging (EMAIL) while keeping log files manageable.
479
+
480
+
**How combinations work:**
481
+
482
+
- Comma-separated values are combined (bitwise OR)
483
+
- Order doesn't matter: `AUTH,ERRORS` = `ERRORS,AUTH`
484
+
- Case-insensitive: `auth` = `AUTH`
485
+
- Whitespace is trimmed: `AUTH, ERRORS` works fine
486
+
487
+
### Log Filename
488
+
489
+
Custom filename for the log file:
490
+
491
+
```ini
492
+
LOG_FILENAME=api.log
493
+
```
494
+
495
+
Default is `api.log`. The filename **cannot contain path separators** (`/` or `\`) - use `LOG_PATH` to set the directory.
496
+
497
+
Useful for separating logs by environment:
498
+
499
+
```ini
500
+
# In .env for production
501
+
LOG_FILENAME=api.log
502
+
503
+
# In test config
504
+
LOG_FILENAME=test_api.log
505
+
```
506
+
507
+
The full log path will be: `{LOG_PATH}/{LOG_FILENAME}`
508
+
509
+
### Console Logging
510
+
511
+
Enable console output in addition to file logging:
512
+
513
+
```ini
514
+
LOG_CONSOLE_ENABLED=false
515
+
```
516
+
517
+
!!! warning "Duplicate Console Output"
518
+
FastAPI/Uvicorn already log to console. Setting this to `true` causes **duplicate console output** - each log message appears twice in the console. Only enable if you have a specific reason (e.g., custom log formatting, Docker/Kubernetes setups).
519
+
520
+
**When to use:**
521
+
522
+
- ✅ Custom log formatting requirements
523
+
- ✅ Centralized logging systems that only capture console
524
+
- ✅ Docker/Kubernetes environments without file access
525
+
526
+
**When NOT to use:**
527
+
528
+
- ❌ Local development (already has console output)
529
+
- ❌ High-traffic APIs (performance impact)
530
+
- ❌ Default installations (causes confusion)
531
+
532
+
### Complete Logging Configuration Examples
533
+
534
+
**Development configuration:**
535
+
536
+
```ini
537
+
LOG_PATH=./logs
538
+
LOG_LEVEL=DEBUG
539
+
LOG_ROTATION=1 day
540
+
LOG_RETENTION=7 days
541
+
LOG_COMPRESSION=zip
542
+
LOG_CATEGORIES=ALL
543
+
LOG_FILENAME=api.log
544
+
LOG_CONSOLE_ENABLED=false
545
+
```
546
+
547
+
**Production configuration (security-focused):**
548
+
549
+
```ini
550
+
LOG_PATH=/var/log/myapi
551
+
LOG_LEVEL=INFO
552
+
LOG_ROTATION=1 day
553
+
LOG_RETENTION=90 days
554
+
LOG_COMPRESSION=zip
555
+
LOG_CATEGORIES=ERRORS,AUTH,ADMIN,EMAIL
556
+
LOG_FILENAME=api.log
557
+
LOG_CONSOLE_ENABLED=false
558
+
```
559
+
560
+
**Production configuration (minimal):**
561
+
562
+
```ini
563
+
LOG_PATH=/var/log/myapi
564
+
LOG_LEVEL=ERROR
565
+
LOG_ROTATION=1 day
566
+
LOG_RETENTION=30 days
567
+
LOG_COMPRESSION=zip
568
+
LOG_CATEGORIES=ERRORS
569
+
LOG_FILENAME=api.log
570
+
LOG_CONSOLE_ENABLED=false
571
+
```
572
+
573
+
### Troubleshooting Logging
574
+
575
+
**Log files not created:**
576
+
577
+
- Check `LOG_PATH` directory exists and is writable
578
+
- Check file permissions on the directory
579
+
- Verify the application process has write access
580
+
581
+
**Log files filling disk:**
582
+
583
+
- Adjust `LOG_ROTATION` to rotate more frequently
584
+
- Reduce `LOG_RETENTION` to delete old logs sooner
585
+
- Use `LOG_COMPRESSION` to save space
586
+
- Reduce `LOG_LEVEL` to ERROR or WARNING
587
+
- Limit `LOG_CATEGORIES` to only what you need
588
+
589
+
**Missing expected logs:**
590
+
591
+
- Check `LOG_CATEGORIES` includes the category you're looking for
592
+
- Verify `LOG_LEVEL` isn't filtering out messages
593
+
- Check logs are being written to the correct file path
594
+
- Ensure the operation you're logging is actually executing
595
+
596
+
**Duplicate console output:**
597
+
598
+
- Set `LOG_CONSOLE_ENABLED=false` (this is the default)
599
+
220
600
## Example full `.env` file
221
601
222
602
Below is a full .env file. This can also be found in the root of the API as
0 commit comments