logfire client for zig
at 7449e2525dcd7e1e3fc0ad5e331bd73019db27ca 60 lines 1.5 kB view raw
1//! basic logfire example 2//! 3//! demonstrates spans, logging, and export to logfire. 4//! 5//! run with: 6//! LOGFIRE_TOKEN=your_token zig build example 7//! 8//! or without token for console-only output: 9//! zig build example 10 11const std = @import("std"); 12const logfire = @import("logfire"); 13 14pub fn main() !void { 15 // configure logfire 16 // will send to logfire if LOGFIRE_TOKEN is set, otherwise just prints 17 const lf = try logfire.configure(.{ 18 .service_name = "logfire-zig-example", 19 .service_version = "0.1.0", 20 .environment = "development", 21 }); 22 defer lf.shutdown(); 23 24 // simple logging 25 logfire.info("application started", .{}); 26 logfire.debug("debug message with value: {d}", .{42}); 27 28 // span with timing 29 { 30 const s = logfire.span("example.work", .{ 31 .iteration = @as(i64, 1), 32 }); 33 defer s.end(); 34 35 // simulate some work 36 std.posix.nanosleep(0, 10 * std.time.ns_per_ms); 37 38 logfire.info("work completed", .{}); 39 } 40 41 // nested spans 42 { 43 const outer = logfire.span("example.outer", .{}); 44 defer outer.end(); 45 46 { 47 const inner = logfire.span("example.inner", .{ 48 .depth = @as(i64, 1), 49 }); 50 defer inner.end(); 51 52 std.posix.nanosleep(0, 5 * std.time.ns_per_ms); 53 } 54 } 55 56 // flush to ensure all data is sent 57 try lf.flush(); 58 59 logfire.info("example complete", .{}); 60}