1 | |
2 | |
3 | * Export log lines |
4 | * Use this method to export logs in JSON format from a logging instance. |
5 | */ |
6 | export async function main( |
7 | auth: RT.Mezmo, |
8 | from: string | undefined, |
9 | to: string | undefined, |
10 | size?: string | undefined, |
11 | hosts?: string | undefined, |
12 | apps?: string | undefined, |
13 | levels?: string | undefined, |
14 | query?: string | undefined, |
15 | prefer?: string | undefined, |
16 | pagination_id?: string | undefined |
17 | ) { |
18 | const url = new URL(`https://api.mezmo.com/v2/export`) |
19 | for (const [k, v] of [ |
20 | ['from', from], |
21 | ['to', to], |
22 | ['size', size], |
23 | ['hosts', hosts], |
24 | ['apps', apps], |
25 | ['levels', levels], |
26 | ['query', query], |
27 | ['prefer', prefer], |
28 | ['pagination_id', pagination_id] |
29 | ]) { |
30 | if (v !== undefined && v !== '') { |
31 | url.searchParams.append(k, v) |
32 | } |
33 | } |
34 | const response = await fetch(url, { |
35 | method: 'GET', |
36 | headers: { |
37 | Authorization: 'Token ' + auth.apiKey |
38 | }, |
39 | body: undefined |
40 | }) |
41 | if (!response.ok) { |
42 | const text = await response.text() |
43 | throw new Error(`${response.status} ${text}`) |
44 | } |
45 | return await response.json() |
46 | } |
47 |
|