aboutsummaryrefslogtreecommitdiff
path: root/src/logger.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/logger.zig')
-rw-r--r--src/logger.zig47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/logger.zig b/src/logger.zig
index dfe60e2af..c7846ab62 100644
--- a/src/logger.zig
+++ b/src/logger.zig
@@ -662,11 +662,11 @@ pub const Log = struct {
}
pub const Level = enum(i8) {
- verbose,
- debug,
- info,
- warn,
- err,
+ verbose, // 0
+ debug, // 1
+ info, // 2
+ warn, // 3
+ err, // 4
pub fn atLeast(this: Level, other: Level) bool {
return @intFromEnum(this) <= @intFromEnum(other);
@@ -703,7 +703,19 @@ pub const Log = struct {
};
}
+ pub fn addDebugFmt(log: *Log, source: ?*const Source, l: Loc, allocator: std.mem.Allocator, comptime text: string, args: anytype) !void {
+ if (!Kind.shouldPrint(.debug, log.level)) return;
+
+ @setCold(true);
+ try log.addMsg(.{
+ .kind = .debug,
+ .data = try rangeData(source, Range{ .loc = l }, allocPrint(allocator, text, args) catch unreachable).cloneLineText(log.clone_line_text, log.msgs.allocator),
+ });
+ }
+
pub fn addVerbose(log: *Log, source: ?*const Source, loc: Loc, text: string) !void {
+ if (!Kind.shouldPrint(.verbose, log.level)) return;
+
@setCold(true);
try log.addMsg(.{
.kind = .verbose,
@@ -1096,6 +1108,31 @@ pub const Log = struct {
});
}
+ pub fn addRangeErrorFmtWithNote(
+ log: *Log,
+ source: ?*const Source,
+ r: Range,
+ allocator: std.mem.Allocator,
+ comptime fmt: string,
+ args: anytype,
+ comptime note_fmt: string,
+ note_args: anytype,
+ note_range: Range,
+ ) !void {
+ @setCold(true);
+ if (!Kind.shouldPrint(.err, log.level)) return;
+ log.errors += 1;
+
+ var notes = try allocator.alloc(Data, 1);
+ notes[0] = rangeData(source, note_range, allocPrint(allocator, note_fmt, note_args) catch unreachable);
+
+ try log.addMsg(.{
+ .kind = .err,
+ .data = rangeData(source, r, allocPrint(allocator, fmt, args) catch unreachable),
+ .notes = notes,
+ });
+ }
+
pub fn addWarning(log: *Log, source: ?*const Source, l: Loc, text: string) !void {
@setCold(true);
if (!Kind.shouldPrint(.warn, log.level)) return;