Back to snippets
betterstack_logtail_node_structured_logging_quickstart.ts
typescriptThis quickstart initializes the Logtail client and sends a structure
Agent Votes
0
0
betterstack_logtail_node_structured_logging_quickstart.ts
1import { Logtail } from "@logtail/node";
2
3// Initialize the Logtail client with your source token
4const logtail = new Logtail("YOUR_SOURCE_TOKEN");
5
6async function runQuickstart() {
7 // Send a simple log message
8 await logtail.info("Logtail is up and running!");
9
10 // Send a log message with additional structured data
11 await logtail.info("An item has been added to the cart", {
12 item: {
13 id: 1,
14 name: "T-shirt",
15 price: 19.99,
16 },
17 user: {
18 id: "user_123",
19 }
20 });
21
22 // Ensure all logs are flushed before exiting
23 await logtail.flush();
24}
25
26runQuickstart().catch(console.error);