this repo has no description

colorful logs

altagos.dev b829759e 79b09f56

verified
+64 -12
+20 -12
src/austin.zig
··· 1 1 const std = @import("std"); 2 2 const mem = std.mem; 3 3 4 + const log = std.log.scoped(.austin); 5 + 4 6 pub const Process = struct { 5 7 /// Process ID 6 8 pid: usize, ··· 150 152 } else { 151 153 // Sample 152 154 const sample = self.parseSample(line, line_num) catch |err| { 153 - std.log.err("[file:{}] {}", .{ line_num, err }); 155 + log.warn("Caught {} while parsing line {}:\n\x1b[90m{} |\x1b[0m {s}{s}", .{ 156 + err, 157 + line_num, 158 + line_num, 159 + if (line.items.len <= 80) line.items else line.items[0..80], 160 + if (line.items.len <= 80) "" else " ...", 161 + }); 154 162 if (err == ParseError.InvalidSample) continue; 155 163 156 164 std.process.exit(1); ··· 189 197 } 190 198 }; 191 199 192 - std.log.warn( 193 - \\No metrics found while parsing line {}, returning partial sample 194 - \\{} | {s}{s} 195 - , 200 + log.warn( 201 + "No metrics found while parsing line {}, returning partial sample:\n\x1b[90m{} |\x1b[0m {s}{s}", 196 202 .{ 197 203 line_num, 198 204 line_num, ··· 227 233 }; 228 234 229 235 self.parseFullSample(sample, data_raw, line_num) catch |err| { 230 - std.log.warn( 231 - \\Caught {} while parsing line {}, returning metrics ({}): 232 - \\{} | {s}{s} 233 - , 236 + log.debug( 237 + "Caught {} while parsing line {}, returning metrics " ++ 238 + "(time delta: {}, idle state: {}, rss memory delta: {}):\n" ++ 239 + "\x1b[90m{} |\x1b[0m {s}{s}", 234 240 .{ 235 241 err, 236 242 line_num, 237 - sample.metric, 243 + sample.metric.time_delta, 244 + sample.metric.idle_state, 245 + sample.metric.rss_memory_delta, 238 246 line_num, 239 247 if (line.items.len <= 80) line.items else line.items[0..80], 240 248 if (line.items.len <= 80) "" else " ...", ··· 282 290 ParseError.NoFunction, 283 291 ParseError.NoLineNumber, 284 292 => { 285 - std.log.warn( 286 - "Cought invalid frame while parsing line {}:\n{} | {s}{s}", 293 + log.debug( 294 + "Caught invalid frame while parsing line {}:\n\x1b[90m{} |\x1b[0m {s}{s}", 287 295 .{ 288 296 line_num, 289 297 line_num,
+44
src/main.zig
··· 3 3 const args = @import("args"); 4 4 const austin = @import("austin"); 5 5 6 + pub const std_options = std.Options{ 7 + .log_level = .debug, 8 + .logFn = logFn, 9 + }; 10 + 6 11 const Options = struct { 7 12 help: bool = false, 8 13 output: ?[]const u8 = null, ··· 73 78 74 79 std.log.info("num samples: {} - meta: {}", .{ profile.samples.len, profile.meta }); 75 80 } 81 + 82 + pub fn logFn( 83 + comptime message_level: std.log.Level, 84 + comptime scope: @TypeOf(.enum_literal), 85 + comptime format: []const u8, 86 + args_: anytype, 87 + ) void { 88 + const prefix = comptime blk: { 89 + const level_text = lt: { 90 + switch (message_level) { 91 + .err => { 92 + break :lt "\x1b[31merror \x1b[0m"; 93 + }, 94 + .warn => { 95 + break :lt "\x1b[33mwarning\x1b[0m"; 96 + }, 97 + .info => { 98 + break :lt "\x1b[32minfo \x1b[0m"; 99 + }, 100 + .debug => { 101 + break :lt "\x1b[34mdebug \x1b[0m"; 102 + }, 103 + } 104 + }; 105 + const scope_prefix = scope: { 106 + if (scope == .default) { 107 + break :scope ""; 108 + } 109 + break :scope " \x1b[90m[\x1b[0m" ++ @tagName(scope) ++ "\x1b[90m]\x1b[0m"; 110 + }; 111 + 112 + break :blk level_text ++ scope_prefix ++ "\x1b[90m \x1b[0m"; 113 + }; 114 + 115 + std.debug.lockStdErr(); 116 + defer std.debug.unlockStdErr(); 117 + const stderr = std.io.getStdErr().writer(); 118 + nosuspend stderr.print(prefix ++ format ++ "\x1b[0m\n", args_) catch return; 119 + }