1 | |
2 | type Render = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List logs |
7 | * List logs matching the provided filters. Logs are paginated by start and end timestamps. |
8 | There are more logs to fetch if `hasMore` is true in the response. Provide the `nextStartTime` |
9 | and `nextEndTime` timestamps as the `startTime` and `endTime` query parameters to fetch the next page of logs. |
10 |
|
11 | You can query for logs across multiple resources, but all resources must be in the same region and belong to the same owner. |
12 |
|
13 | */ |
14 | export async function main( |
15 | auth: Render, |
16 | ownerId: string | undefined, |
17 | startTime: string | undefined, |
18 | endTime: string | undefined, |
19 | direction: 'forward' | 'backward' | undefined, |
20 | resource: string | undefined, |
21 | instance: string | undefined, |
22 | host: string | undefined, |
23 | statusCode: string | undefined, |
24 | method: string | undefined, |
25 | level: string | undefined, |
26 | _type: string | undefined, |
27 | text: string | undefined, |
28 | path: string | undefined, |
29 | limit: string | undefined |
30 | ) { |
31 | const url = new URL(`https://api.render.com/v1/logs`) |
32 | for (const [k, v] of [ |
33 | ['ownerId', ownerId], |
34 | ['startTime', startTime], |
35 | ['endTime', endTime], |
36 | ['direction', direction], |
37 | ['resource', resource], |
38 | ['instance', instance], |
39 | ['host', host], |
40 | ['statusCode', statusCode], |
41 | ['method', method], |
42 | ['level', level], |
43 | ['type', _type], |
44 | ['text', text], |
45 | ['path', path], |
46 | ['limit', limit] |
47 | ]) { |
48 | if (v !== undefined && v !== '' && k !== undefined) { |
49 | url.searchParams.append(k, v) |
50 | } |
51 | } |
52 | const response = await fetch(url, { |
53 | method: 'GET', |
54 | headers: { |
55 | Authorization: 'Bearer ' + auth.apiKey |
56 | }, |
57 | body: undefined |
58 | }) |
59 | if (!response.ok) { |
60 | const text = await response.text() |
61 | throw new Error(`${response.status} ${text}`) |
62 | } |
63 | return await response.json() |
64 | } |
65 |
|