diff options
author | 2021-06-06 18:34:01 -0700 | |
---|---|---|
committer | 2021-06-06 18:34:01 -0700 | |
commit | d49e0a5fa129152c27b70a57d1cc7a2af770577c (patch) | |
tree | 1ac581bda71fec5dfd09a6ab508a1adfca80b358 /src/logger.zig | |
parent | e66466cc1a453db1370a199a32729441747761bb (diff) | |
download | bun-d49e0a5fa129152c27b70a57d1cc7a2af770577c.tar.gz bun-d49e0a5fa129152c27b70a57d1cc7a2af770577c.tar.zst bun-d49e0a5fa129152c27b70a57d1cc7a2af770577c.zip |
WIP node module bundles
Former-commit-id: 797b2ff557542e9d318c953b840b102695711888
Diffstat (limited to 'src/logger.zig')
-rw-r--r-- | src/logger.zig | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/logger.zig b/src/logger.zig index 4d9e5150a..cd58e29d8 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -123,6 +123,31 @@ pub const Data = struct { allocator.free(text); } + + pub fn writeFormat( + this: *const Data, + to: anytype, + kind: Kind, + ) !void { + if (this.text.len == 0) return; + + if (this.location) |location| { + try std.fmt.format(to, "\n\n{s}: {s}\n{s}\n{s}:{}:{} {d}", .{ + kind.string(), + this.text, + location.line_text, + location.file, + location.line, + location.column, + location.offset, + }); + } else { + try std.fmt.format(to, "\n\n{s}: {s}\n", .{ + kind.string(), + this.text, + }); + } + } }; pub const Msg = struct { @@ -144,26 +169,17 @@ pub const Msg = struct { msg: *const Msg, to: anytype, ) !void { - if (msg.data.location) |location| { - try std.fmt.format(to, "\n\n{s}: {s}\n{s}\n{s}:{}:{} {d}", .{ - msg.kind.string(), - msg.data.text, - location.line_text, - location.file, - location.line, - location.column, - location.offset, - }); - } else { - try std.fmt.format(to, "\n\n{s}: {s}\n", .{ - msg.kind.string(), - msg.data.text, - }); + try msg.data.writeFormat(to, msg.kind); + + if (msg.notes) |notes| { + for (notes) |note| { + try note.writeFormat(to, msg.kind); + } } } pub fn doFormat(msg: *const Msg, to: anytype, formatterFunc: anytype) !void { - try formatterFunc(to, "\n\n{s}: {s}\n{s}\n{s}:{}:{} {d}", .{ + try formatterFunc(to, "\n\n{s}: {s}\n{s}\n{s}:{s}:{s} {d}", .{ msg.kind.string(), msg.data.text, msg.data.location.?.line_text, @@ -368,7 +384,7 @@ pub const Log = struct { // TODO: pub fn print(self: *Log, to: anytype) !void { for (self.msgs.items) |msg| { - try msg.doFormat(to, std.fmt.format); + try msg.writeFormat(to); } } }; |