Local Development Setup
Learn how to set up Loggator for local development with hot-reload and debugging.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
- Node.js 20+ or Bun (recommended)
- Docker and Docker Compose
- Git
- A code editor (VS Code recommended)
Quick Start
Section titled “Quick Start”1. Clone the Repository
Section titled “1. Clone the Repository”git clone https://github.com/MBeggiato/loggator.gitcd loggator2. Install Dependencies
Section titled “2. Install Dependencies”# Using bun (recommended)bun install
# Or using npmnpm install3. Start Development Services
Section titled “3. Start Development Services”Start Meilisearch and a test logger container:
bun run dev:servicesThis starts:
- Meilisearch on
localhost:7700 - Test Logger (generates sample logs)
4. Start the Dev Server
Section titled “4. Start the Dev Server”In a new terminal:
bun run devThe application will be available at: http://localhost:5173
Development Environment
Section titled “Development Environment”What’s Running
Section titled “What’s Running”When you run bun run dev:services:
| Service | Port | Purpose |
|---|---|---|
| Meilisearch | 7700 | Search engine |
| Test Logger | - | Generates sample logs |
When you run bun run dev:
| Service | Port | Purpose |
|---|---|---|
| SvelteKit Dev Server | 5173 | Web UI with hot-reload |
Environment Configuration
Section titled “Environment Configuration”Development uses .env.development:
MEILISEARCH_HOST=http://localhost:7700MEILISEARCH_API_KEY=aSampleMasterKey1234567890abcdefDOCKER_LABEL_FILTER=loggator.enable=truePORT=5173
# Optional - AI FeaturesOPENROUTER_API_KEY=sk-or-v1-your-key-hereAI_MODEL=xiaomi/mimo-v2-flash:freeSITE_URL=http://localhost:5173Development Workflow
Section titled “Development Workflow”Hot Reload
Section titled “Hot Reload”SvelteKit provides hot module replacement (HMR):
- Edit a
.sveltefile → Browser updates instantly - Edit a
.tsfile → Server restarts automatically - Edit a
.cssfile → Styles update without reload
File Structure
Section titled “File Structure”loggator/├── src/│ ├── routes/ # SvelteKit routes│ │ ├── +page.svelte # Dashboard│ │ ├── +layout.svelte # Layout│ │ └── api/ # API endpoints│ │ ├── chat/│ │ ├── containers/│ │ └── logs/│ ├── lib/│ │ ├── components/ # Svelte components│ │ ├── server/ # Server-side code│ │ │ ├── ai-tools.ts│ │ │ ├── docker-collector.ts│ │ │ ├── log-aggregator.ts│ │ │ └── meilisearch-indexer.ts│ │ └── i18n/ # Translations│ └── app.css # Global styles├── static/ # Static assets├── package.json├── svelte.config.js├── vite.config.ts└── tsconfig.jsonDevelopment Commands
Section titled “Development Commands”# Start dev services (Meilisearch + Test Logger)bun run dev:services
# Start dev serverbun run dev
# Both in one commandbun run dev:full
# Stop dev servicesbun run dev:stop
# Type checkingbun run check
# Lintingbun run lint
# Formattingbun run format
# Build for productionbun run build
# Preview production buildbun run previewDebugging
Section titled “Debugging”Server-Side Debugging
Section titled “Server-Side Debugging”Add console.log statements in server code:
console.log("Indexing log:", log);Logs appear in the terminal running bun run dev.
Client-Side Debugging
Section titled “Client-Side Debugging”Use browser DevTools:
<script> console.log('Component mounted:', data);</script>VS Code Debugging
Section titled “VS Code Debugging”Create .vscode/launch.json:
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug Dev Server", "runtimeExecutable": "bun", "runtimeArgs": ["run", "dev"], "skipFiles": ["<node_internals>/**"] } ]}Docker Logs
Section titled “Docker Logs”Check Meilisearch logs:
docker logs meilisearch-devCheck test logger:
docker logs test-loggerTesting
Section titled “Testing”Manual Testing
Section titled “Manual Testing”- Start dev environment
- Open http://localhost:5173
- Test features manually
API Testing
Section titled “API Testing”Use curl or Postman:
# Test log searchcurl "http://localhost:5173/api/logs/search?query=test"
# Test AI chatcurl -X POST http://localhost:5173/api/chat \ -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"test"}]}'Test Containers
Section titled “Test Containers”Label test containers:
docker run -d \ --label loggator.enable=true \ --name test-app \ nginx:latestCommon Issues
Section titled “Common Issues”Port Already in Use
Section titled “Port Already in Use”If port 5173 is occupied:
# Kill process on port 5173lsof -ti:5173 | xargs kill -9
# Or change the port in package.json"dev": "vite dev --port 3000"Meilisearch Connection Failed
Section titled “Meilisearch Connection Failed”Check Meilisearch is running:
docker ps | grep meilisearch-devcurl http://localhost:7700/healthRestart if needed:
bun run dev:stopbun run dev:servicesNo Logs Appearing
Section titled “No Logs Appearing”-
Check test logger is running:
Terminal window docker ps | grep test-logger -
Verify label:
Terminal window docker inspect test-logger | grep loggator.enable -
Check Loggator server logs in terminal
Type Errors
Section titled “Type Errors”Run type checking:
bun run checkFix errors in TypeScript files.
Best Practices
Section titled “Best Practices”1. Use TypeScript
Section titled “1. Use TypeScript”Always type your code:
// ✅ Goodinterface LogEntry { message: string; timestamp: number;}
function processLog(log: LogEntry): void { // ...}
// ❌ Badfunction processLog(log: any): void { // ...}2. Follow Code Style
Section titled “2. Follow Code Style”Run formatter before committing:
bun run format3. Test Changes
Section titled “3. Test Changes”Test your changes:
- Manually in the browser
- With API calls
- With different scenarios
4. Check for Errors
Section titled “4. Check for Errors”Before committing:
bun run check # Type checkingbun run lint # Lintingbun run format # Formatting5. Use Git Branches
Section titled “5. Use Git Branches”Create feature branches:
git checkout -b feature/my-feature# Make changesgit commit -m "Add my feature"git push origin feature/my-featureHot Reload Tips
Section titled “Hot Reload Tips”Client-Side Changes
Section titled “Client-Side Changes”- Components: Update instantly
- Routes: Update instantly
- Styles: Update instantly
Server-Side Changes
Section titled “Server-Side Changes”- API routes: Server restarts (2-3 seconds)
- Server utilities: Server restarts
- Environment vars: Manual restart required
Forcing Reload
Section titled “Forcing Reload”If hot reload doesn’t work:
# Ctrl+C to stop# Then restartbun run devEnvironment Variables
Section titled “Environment Variables”Local Development
Section titled “Local Development”Create .env.development.local (gitignored):
# Override for local devOPENROUTER_API_KEY=your-local-keyAI_MODEL=your-preferred-modelProduction Testing
Section titled “Production Testing”Test production build locally:
# Buildbun run build
# Previewbun run preview
# Open http://localhost:4173Docker Development
Section titled “Docker Development”Testing in Docker
Section titled “Testing in Docker”Build and run in Docker:
# Build imagedocker build -t loggator:dev .
# Run with docker-composedocker compose -f docker-compose.dev.yml upVolume Mounts
Section titled “Volume Mounts”For live code changes in Docker:
services: loggator: volumes: - ./src:/app/src - ./package.json:/app/package.jsonPerformance Optimization
Section titled “Performance Optimization”Development Performance
Section titled “Development Performance”For faster development:
- Use Bun: Faster than npm
- Use SSD: Faster file operations
- Close unused tabs: Less memory usage
- Disable source maps: In vite.config.ts (if needed)
Build Performance
Section titled “Build Performance”For faster builds:
export default defineConfig({ build: { minify: "esbuild", // Faster than terser sourcemap: false, // Skip source maps },});Next Steps
Section titled “Next Steps”- Architecture - Understand the codebase
- Contributing - Contribution guidelines
- API Reference - API documentation