aboutsummaryrefslogtreecommitdiff
path: root/src/logger.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/logger.zig')
-rw-r--r--src/logger.zig18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/logger.zig b/src/logger.zig
index f8602f007..08be0d70d 100644
--- a/src/logger.zig
+++ b/src/logger.zig
@@ -11,13 +11,17 @@ const expect = std.testing.expect;
const assert = std.debug.assert;
const ArrayList = std.ArrayList;
-pub const Kind = enum {
+pub const Kind = enum(i8) {
err,
warn,
note,
debug,
verbose,
+ pub inline fn shouldPrint(this: Kind, other: Log.Level) bool {
+ return @enumToInt(this) - @enumToInt(other) >= 0;
+ }
+
pub fn string(self: Kind) string {
return switch (self) {
.err => "error",
@@ -323,7 +327,7 @@ pub const Log = struct {
warnings: usize = 0,
errors: usize = 0,
msgs: ArrayList(Msg),
- level: Level = Level.debug,
+ level: Level = Level.info,
pub fn toAPI(this: *const Log, allocator: *std.mem.Allocator) !Api.Log {
return Api.Log{
@@ -333,7 +337,7 @@ pub const Log = struct {
};
}
- pub const Level = enum {
+ pub const Level = enum(i8) {
verbose,
debug,
info,
@@ -516,6 +520,14 @@ pub const Log = struct {
}
}
+ pub fn printForLogLevel(self: *Log, to: anytype) !void {
+ for (self.msgs.items) |msg| {
+ if (msg.kind.shouldPrint(self.level)) {
+ try msg.writeFormat(to);
+ }
+ }
+ }
+
pub fn toZigException(this: *const Log, allocator: *std.mem.Allocator) *js.ZigException.Holder {
var holder = try allocator.create(js.ZigException.Holder);
holder.* = js.ZigException.Holder.init();