0

Send Log Lines

by
Published Oct 17, 2025

Use this method to send logs to a logging instance.

Script mezmo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Send Log Lines
4
 * Use this method to send logs to a logging instance.
5
 */
6
export async function main(
7
	auth: RT.Mezmo,
8
	hostname: string | undefined,
9
	body: Body,
10
	mac?: string | undefined,
11
	ip?: string | undefined,
12
	now?: string | undefined,
13
	tags?: string | undefined
14
) {
15
	const url = new URL(`https://api.mezmo.com/logs/ingest`)
16
	for (const [k, v] of [
17
		['hostname', hostname],
18
		['mac', mac],
19
		['ip', ip],
20
		['now', now],
21
		['tags', tags]
22
	]) {
23
		if (v !== undefined && v !== '') {
24
			url.searchParams.append(k, v)
25
		}
26
	}
27
	const response = await fetch(url, {
28
		method: 'POST',
29
		headers: {
30
			'Content-Type': 'application/json',
31
			Authorization: 'Token ' + auth.apiKey
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41

42
/* eslint-disable */
43
/**
44
 * This file was automatically generated by json-schema-to-typescript.
45
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
46
 * and run json-schema-to-typescript to regenerate this file.
47
 */
48

49
export interface Body {
50
	lines?: {
51
		/**
52
		 * UNIX timestamp, including milliseconds, when the log entry was recorded.
53
		 */
54
		timestamp?: string
55
		/**
56
		 * Text of the log line.
57
		 */
58
		line: string
59
		/**
60
		 * Name of the application that generates the log line.
61
		 */
62
		app?: string
63
		/**
64
		 * Set a value for the level. For example, sample values for this parameter are INFO, WARNING, ERROR.
65
		 */
66
		level?: string
67
		/**
68
		 * This field is reserved for custom information that is associated with a log line. To add metadata to an API call, specify the meta field under the lines object. Metadata can be viewed inside that line's context.
69
		 */
70
		meta?: string
71
		[k: string]: unknown
72
	}[]
73
	[k: string]: unknown
74
}
75