Skip to content

Local Development Setup

Learn how to set up Loggator for local development with hot-reload and debugging.

Before you begin, ensure you have:

  • Node.js 20+ or Bun (recommended)
  • Docker and Docker Compose
  • Git
  • A code editor (VS Code recommended)
Terminal window
git clone https://github.com/MBeggiato/loggator.git
cd loggator
Terminal window
# Using bun (recommended)
bun install
# Or using npm
npm install

Start Meilisearch and a test logger container:

Terminal window
bun run dev:services

This starts:

  • Meilisearch on localhost:7700
  • Test Logger (generates sample logs)

In a new terminal:

Terminal window
bun run dev

The application will be available at: http://localhost:5173

When you run bun run dev:services:

ServicePortPurpose
Meilisearch7700Search engine
Test Logger-Generates sample logs

When you run bun run dev:

ServicePortPurpose
SvelteKit Dev Server5173Web UI with hot-reload

Development uses .env.development:

.env.development
MEILISEARCH_HOST=http://localhost:7700
MEILISEARCH_API_KEY=aSampleMasterKey1234567890abcdef
DOCKER_LABEL_FILTER=loggator.enable=true
PORT=5173
# Optional - AI Features
OPENROUTER_API_KEY=sk-or-v1-your-key-here
AI_MODEL=xiaomi/mimo-v2-flash:free
SITE_URL=http://localhost:5173

SvelteKit provides hot module replacement (HMR):

  • Edit a .svelte file → Browser updates instantly
  • Edit a .ts file → Server restarts automatically
  • Edit a .css file → Styles update without reload
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.json
Terminal window
# Start dev services (Meilisearch + Test Logger)
bun run dev:services
# Start dev server
bun run dev
# Both in one command
bun run dev:full
# Stop dev services
bun run dev:stop
# Type checking
bun run check
# Linting
bun run lint
# Formatting
bun run format
# Build for production
bun run build
# Preview production build
bun run preview

Add console.log statements in server code:

src/lib/server/log-aggregator.ts
console.log("Indexing log:", log);

Logs appear in the terminal running bun run dev.

Use browser DevTools:

<script>
console.log('Component mounted:', data);
</script>

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>/**"]
}
]
}

Check Meilisearch logs:

Terminal window
docker logs meilisearch-dev

Check test logger:

Terminal window
docker logs test-logger
  1. Start dev environment
  2. Open http://localhost:5173
  3. Test features manually

Use curl or Postman:

Terminal window
# Test log search
curl "http://localhost:5173/api/logs/search?query=test"
# Test AI chat
curl -X POST http://localhost:5173/api/chat \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"test"}]}'

Label test containers:

Terminal window
docker run -d \
--label loggator.enable=true \
--name test-app \
nginx:latest

If port 5173 is occupied:

Terminal window
# Kill process on port 5173
lsof -ti:5173 | xargs kill -9
# Or change the port in package.json
"dev": "vite dev --port 3000"

Check Meilisearch is running:

Terminal window
docker ps | grep meilisearch-dev
curl http://localhost:7700/health

Restart if needed:

Terminal window
bun run dev:stop
bun run dev:services
  1. Check test logger is running:

    Terminal window
    docker ps | grep test-logger
  2. Verify label:

    Terminal window
    docker inspect test-logger | grep loggator.enable
  3. Check Loggator server logs in terminal

Run type checking:

Terminal window
bun run check

Fix errors in TypeScript files.

Always type your code:

// ✅ Good
interface LogEntry {
message: string;
timestamp: number;
}
function processLog(log: LogEntry): void {
// ...
}
// ❌ Bad
function processLog(log: any): void {
// ...
}

Run formatter before committing:

Terminal window
bun run format

Test your changes:

  • Manually in the browser
  • With API calls
  • With different scenarios

Before committing:

Terminal window
bun run check # Type checking
bun run lint # Linting
bun run format # Formatting

Create feature branches:

Terminal window
git checkout -b feature/my-feature
# Make changes
git commit -m "Add my feature"
git push origin feature/my-feature
  • Components: Update instantly
  • Routes: Update instantly
  • Styles: Update instantly
  • API routes: Server restarts (2-3 seconds)
  • Server utilities: Server restarts
  • Environment vars: Manual restart required

If hot reload doesn’t work:

Terminal window
# Ctrl+C to stop
# Then restart
bun run dev

Create .env.development.local (gitignored):

Terminal window
# Override for local dev
OPENROUTER_API_KEY=your-local-key
AI_MODEL=your-preferred-model

Test production build locally:

Terminal window
# Build
bun run build
# Preview
bun run preview
# Open http://localhost:4173

Build and run in Docker:

Terminal window
# Build image
docker build -t loggator:dev .
# Run with docker-compose
docker compose -f docker-compose.dev.yml up

For live code changes in Docker:

services:
loggator:
volumes:
- ./src:/app/src
- ./package.json:/app/package.json

For faster development:

  1. Use Bun: Faster than npm
  2. Use SSD: Faster file operations
  3. Close unused tabs: Less memory usage
  4. Disable source maps: In vite.config.ts (if needed)

For faster builds:

vite.config.ts
export default defineConfig({
build: {
minify: "esbuild", // Faster than terser
sourcemap: false, // Skip source maps
},
});