-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path+page.svelte
More file actions
343 lines (323 loc) · 12 KB
/
+page.svelte
File metadata and controls
343 lines (323 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<script lang="ts">
import * as Card from "$lib/components/ui/card/index.js";
import { Badge } from "$lib/components/ui/badge/index.js";
</script>
<div class="p-6 space-y-6 max-w-6xl mx-auto">
<div class="space-y-2">
<h1 class="text-4xl font-bold">Lighthouse API Documentation</h1>
<p class="text-muted-foreground text-lg">
REST API for centralized log collection and management
</p>
</div>
<Card.Root>
<Card.Header>
<Card.Title>Overview</Card.Title>
</Card.Header>
<Card.Content class="space-y-4">
<p>
Lighthouse provides a simple REST API for collecting logs from multiple services.
Projects are automatically created when you send your first log with a project name.
</p>
<div class="space-y-2">
<div class="flex items-center gap-2">
<Badge variant="outline">Base URL</Badge>
<code class="px-2 py-1 bg-muted rounded text-sm font-mono">
https://your-lighthouse-instance.com/api
</code>
</div>
<div class="flex items-center gap-2">
<Badge variant="outline">Content-Type</Badge>
<code class="px-2 py-1 bg-muted rounded text-sm font-mono">
application/json
</code>
</div>
</div>
</Card.Content>
</Card.Root>
<Card.Root>
<Card.Header>
<Card.Title>Quick Start</Card.Title>
</Card.Header>
<Card.Content class="space-y-4">
<div>
<h3 class="text-lg font-semibold mb-2">1. Send Your First Log</h3>
<p class="text-sm text-muted-foreground mb-3">
Simply send a POST request with your log data. Include a project_name to automatically create a project.
</p>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{`curl -X POST https://your-lighthouse-instance.com/api/logs \\
-H "Content-Type: application/json" \\
-d '{
"project_name": "my-backend-service",
"level": "INFO",
"source": "auth-service",
"message": "User logged in successfully",
"metadata": {
"user_id": "12345",
"ip": "192.168.1.100"
}
}'`}</code></pre>
</div>
<div>
<h3 class="text-lg font-semibold mb-2">2. Project Auto-Creation</h3>
<p class="text-sm text-muted-foreground">
When you send a log with a project_name that doesn't exist, Lighthouse automatically creates the project and generates an API key for it.
</p>
</div>
</Card.Content>
</Card.Root>
<Card.Root>
<Card.Header>
<div class="flex items-center gap-3">
<Badge variant="destructive">POST</Badge>
<Card.Title>/api/logs</Card.Title>
</div>
<Card.Description>Create a new log entry</Card.Description>
</Card.Header>
<Card.Content class="space-y-4">
<div>
<h4 class="font-semibold mb-2">Request Body</h4>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="border-b">
<tr>
<th class="text-left py-2 px-3">Field</th>
<th class="text-left py-2 px-3">Type</th>
<th class="text-left py-2 px-3">Required</th>
<th class="text-left py-2 px-3">Description</th>
</tr>
</thead>
<tbody class="divide-y">
<tr>
<td class="py-2 px-3 font-mono text-xs">project_name</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3"><Badge variant="outline">optional</Badge></td>
<td class="py-2 px-3">Project name for auto-creation</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">project_id</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3"><Badge variant="outline">optional</Badge></td>
<td class="py-2 px-3">Existing project ID</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">level</td>
<td class="py-2 px-3">enum</td>
<td class="py-2 px-3"><Badge>required</Badge></td>
<td class="py-2 px-3">DEBUG, INFO, WARN, ERROR</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">source</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3"><Badge>required</Badge></td>
<td class="py-2 px-3">Service or component name (max 255 chars)</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">message</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3"><Badge>required</Badge></td>
<td class="py-2 px-3">Log message (1-5000 chars)</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">metadata</td>
<td class="py-2 px-3">object</td>
<td class="py-2 px-3"><Badge variant="outline">optional</Badge></td>
<td class="py-2 px-3">Additional structured data</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">timestamp</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3"><Badge variant="outline">optional</Badge></td>
<td class="py-2 px-3">ISO 8601 datetime (defaults to now)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<h4 class="font-semibold mb-2">Example Request</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{JSON.stringify({
project_name: "my-api",
level: "ERROR",
source: "database-service",
message: "Connection timeout",
metadata: {
host: "db.example.com",
timeout_ms: 5000,
retry_count: 3
},
timestamp: "2024-02-28T10:30:00.000Z"
}, null, 2)}</code></pre>
</div>
<div>
<h4 class="font-semibold mb-2">Success Response (201)</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{JSON.stringify({
success: true,
data: {
id: "logs:abc123def456",
level: "ERROR",
source: "database-service",
message: "Connection timeout",
metadata: {
host: "db.example.com",
timeout_ms: 5000,
retry_count: 3
},
timestamp: "2024-02-28T10:30:00.000Z",
project_id: "projects:xyz789"
}
}, null, 2)}</code></pre>
</div>
<div>
<h4 class="font-semibold mb-2">Error Response (400)</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{JSON.stringify({
success: false,
error: "Validation error message"
}, null, 2)}</code></pre>
</div>
</Card.Content>
</Card.Root>
<Card.Root>
<Card.Header>
<div class="flex items-center gap-3">
<Badge variant="secondary">GET</Badge>
<Card.Title>/api/logs</Card.Title>
</div>
<Card.Description>Retrieve logs with optional filtering</Card.Description>
</Card.Header>
<Card.Content class="space-y-4">
<div>
<h4 class="font-semibold mb-2">Query Parameters</h4>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="border-b">
<tr>
<th class="text-left py-2 px-3">Parameter</th>
<th class="text-left py-2 px-3">Type</th>
<th class="text-left py-2 px-3">Description</th>
</tr>
</thead>
<tbody class="divide-y">
<tr>
<td class="py-2 px-3 font-mono text-xs">project_id</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3">Filter by project ID</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">level</td>
<td class="py-2 px-3">enum</td>
<td class="py-2 px-3">Filter by log level</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">source</td>
<td class="py-2 px-3">string</td>
<td class="py-2 px-3">Filter by source service</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">limit</td>
<td class="py-2 px-3">number</td>
<td class="py-2 px-3">Max results (1-1000, default: 100)</td>
</tr>
<tr>
<td class="py-2 px-3 font-mono text-xs">offset</td>
<td class="py-2 px-3">number</td>
<td class="py-2 px-3">Pagination offset (default: 0)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<h4 class="font-semibold mb-2">Example Request</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{`GET /api/logs?level=ERROR&source=auth-service&limit=50`}</code></pre>
</div>
</Card.Content>
</Card.Root>
<Card.Root>
<Card.Header>
<Card.Title>Integration Examples</Card.Title>
</Card.Header>
<Card.Content class="space-y-6">
<div>
<h4 class="font-semibold mb-2">Node.js / JavaScript</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{`async function sendLog(level, source, message, metadata = {}) {
const response = await fetch('https://your-lighthouse-instance.com/api/logs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
project_name: 'my-service',
level,
source,
message,
metadata
})
});
return response.json();
}
await sendLog('INFO', 'user-service', 'User created', { user_id: '123' });`}</code></pre>
</div>
<div>
<h4 class="font-semibold mb-2">Python</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{`import requests
import json
def send_log(level, source, message, metadata=None):
response = requests.post(
'https://your-lighthouse-instance.com/api/logs',
headers={'Content-Type': 'application/json'},
json={
'project_name': 'my-service',
'level': level,
'source': source,
'message': message,
'metadata': metadata or {}
}
)
return response.json()
send_log('ERROR', 'payment-service', 'Payment failed', {'order_id': '456'})`}</code></pre>
</div>
<div>
<h4 class="font-semibold mb-2">Go</h4>
<pre class="bg-muted p-4 rounded-lg overflow-x-auto text-sm"><code>{`package main
import (
"bytes"
"encoding/json"
"net/http"
)
type LogEntry struct {
ProjectName string \`json:"project_name"\`
Level string \`json:"level"\`
Source string \`json:"source"\`
Message string \`json:"message"\`
Metadata map[string]interface{} \`json:"metadata,omitempty"\`
}
func SendLog(entry LogEntry) error {
body, _ := json.Marshal(entry)
resp, err := http.Post(
"https://your-lighthouse-instance.com/api/logs",
"application/json",
bytes.NewBuffer(body),
)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}`}</code></pre>
</div>
</Card.Content>
</Card.Root>
<Card.Root>
<Card.Header>
<Card.Title>Best Practices</Card.Title>
</Card.Header>
<Card.Content>
<ul class="space-y-2 list-disc list-inside text-sm">
<li>Use consistent source names across your services for better filtering</li>
<li>Include relevant metadata for debugging (user IDs, request IDs, etc.)</li>
<li>Use appropriate log levels: DEBUG for development, INFO for events, WARN for issues, ERROR for failures</li>
<li>Send logs asynchronously to avoid blocking your application</li>
<li>Use project_name on first request, then cache and reuse project_id for better performance</li>
<li>Include timestamps from your service for accurate log timing</li>
</ul>
</Card.Content>
</Card.Root>
</div>