mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-12 05:53:51 -04:00
Some improvements to the log function.
This commit is contained in:
parent
3fb17e24b9
commit
dbbda05022
@ -86,6 +86,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
exe.addModule("harfbuzz", harfbuzzModule);
|
exe.addModule("harfbuzz", harfbuzzModule);
|
||||||
exe.addModule("freetype", freetypeModule);
|
exe.addModule("freetype", freetypeModule);
|
||||||
freetype.link(b, exe, .{ .harfbuzz = .{} });
|
freetype.link(b, exe, .{ .harfbuzz = .{} });
|
||||||
|
//exe.strip = true; // Improves compile-time
|
||||||
//exe.sanitize_thread = true;
|
//exe.sanitize_thread = true;
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
|
|
||||||
|
33
src/main.zig
33
src/main.zig
@ -60,10 +60,9 @@ pub const std_options = struct {
|
|||||||
std.log.Level.warn => "\x1b[33m",
|
std.log.Level.warn => "\x1b[33m",
|
||||||
std.log.Level.debug => "\x1b[37;44m",
|
std.log.Level.debug => "\x1b[37;44m",
|
||||||
};
|
};
|
||||||
const colorReset = "\x1b[0m";
|
const colorReset = "\x1b[0m\n";
|
||||||
const filePrefix = "[" ++ comptime level.asText() ++ "]" ++ ": ";
|
const filePrefix = "[" ++ comptime level.asText() ++ "]" ++ ": ";
|
||||||
const fileSuffix = "";
|
const fileSuffix = "\n";
|
||||||
//const advancedFormat = "{s}" ++ format ++ "{s}\n";
|
|
||||||
comptime var formatString: []const u8 = "";
|
comptime var formatString: []const u8 = "";
|
||||||
comptime var i: usize = 0;
|
comptime var i: usize = 0;
|
||||||
comptime var mode: usize = 0;
|
comptime var mode: usize = 0;
|
||||||
@ -102,7 +101,7 @@ pub const std_options = struct {
|
|||||||
sectionResults = sectionResults ++ &[_][]const u8{sectionString};
|
sectionResults = sectionResults ++ &[_][]const u8{sectionString};
|
||||||
sectionId = sectionId ++ &[_]usize {sections};
|
sectionId = sectionId ++ &[_]usize {sections};
|
||||||
sections += 1;
|
sections += 1;
|
||||||
formatString = comptime cacheString("{s}" ++ formatString ++ "{s}\n");
|
formatString = comptime cacheString("{s}" ++ formatString ++ "{s}");
|
||||||
|
|
||||||
comptime var types: []const type = &.{};
|
comptime var types: []const type = &.{};
|
||||||
comptime var i_1: usize = 0;
|
comptime var i_1: usize = 0;
|
||||||
@ -120,16 +119,9 @@ pub const std_options = struct {
|
|||||||
types = types ++ &[_]type{i64};
|
types = types ++ &[_]type{i64};
|
||||||
} else if(@TypeOf(args[i_1]) == comptime_float) {
|
} else if(@TypeOf(args[i_1]) == comptime_float) {
|
||||||
types = types ++ &[_]type{f64};
|
types = types ++ &[_]type{f64};
|
||||||
} else if(TI == .Pointer) {
|
} else if(TI == .Pointer and TI.Pointer.size == .Slice and TI.Pointer.child == u8) {
|
||||||
if(TI.Pointer.size == .Many and TI.Pointer.child == u8) {
|
|
||||||
types = types ++ &[_]type{[]const u8};
|
types = types ++ &[_]type{[]const u8};
|
||||||
} else if(TI.Pointer.size == .Slice and TI.Pointer.child == u8) {
|
} else if(TI == .Int and TI.Int.bits <= 64) {
|
||||||
types = types ++ &[_]type{[]const u8};
|
|
||||||
} else {
|
|
||||||
types = types ++ &[_]type{@TypeOf(args[i_1])};
|
|
||||||
}
|
|
||||||
} else if(TI == .Int) {
|
|
||||||
if(TI.Int.bits <= 64) {
|
|
||||||
if(TI.Int.signedness == .signed) {
|
if(TI.Int.signedness == .signed) {
|
||||||
types = types ++ &[_]type{i64};
|
types = types ++ &[_]type{i64};
|
||||||
} else {
|
} else {
|
||||||
@ -138,13 +130,9 @@ pub const std_options = struct {
|
|||||||
} else {
|
} else {
|
||||||
types = types ++ &[_]type{@TypeOf(args[i_1])};
|
types = types ++ &[_]type{@TypeOf(args[i_1])};
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
types = types ++ &[_]type{@TypeOf(args[i_1])};
|
|
||||||
}
|
|
||||||
i_1 += 1;
|
i_1 += 1;
|
||||||
}
|
}
|
||||||
types = &[_]type{[]const u8} ++ types ++ &[_]type{[]const u8};
|
types = &[_]type{[]const u8} ++ types ++ &[_]type{[]const u8};
|
||||||
// @compileLog(types);
|
|
||||||
|
|
||||||
comptime var comptimeTuple: std.meta.Tuple(types) = undefined;
|
comptime var comptimeTuple: std.meta.Tuple(types) = undefined;
|
||||||
comptime std.debug.assert(std.meta.Tuple(types) == std.meta.Tuple(types));
|
comptime std.debug.assert(std.meta.Tuple(types) == std.meta.Tuple(types));
|
||||||
@ -161,6 +149,8 @@ pub const std_options = struct {
|
|||||||
}
|
}
|
||||||
i_1 += 1;
|
i_1 += 1;
|
||||||
}
|
}
|
||||||
|
comptimeTuple[0] = filePrefix;
|
||||||
|
comptimeTuple[comptimeTuple.len - 1] = fileSuffix;
|
||||||
var resultArgs: std.meta.Tuple(types) = comptimeTuple;
|
var resultArgs: std.meta.Tuple(types) = comptimeTuple;
|
||||||
len = 0;
|
len = 0;
|
||||||
i_1 = 0;
|
i_1 = 0;
|
||||||
@ -175,20 +165,13 @@ pub const std_options = struct {
|
|||||||
resultArgs[len+1] = args[i_1];
|
resultArgs[len+1] = args[i_1];
|
||||||
i_1 += 1;
|
i_1 += 1;
|
||||||
}
|
}
|
||||||
//@compileLog(format, formatString, args, resultArgs);
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
resultArgs[0] = filePrefix;
|
|
||||||
resultArgs[resultArgs.len - 1] = fileSuffix;
|
|
||||||
logToFile(formatString, resultArgs);
|
logToFile(formatString, resultArgs);
|
||||||
}
|
|
||||||
{
|
|
||||||
resultArgs[0] = color;
|
resultArgs[0] = color;
|
||||||
resultArgs[resultArgs.len - 1] = colorReset;
|
resultArgs[resultArgs.len - 1] = colorReset;
|
||||||
logToStdErr(formatString, resultArgs);
|
logToStdErr(formatString, resultArgs);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn logToFile(comptime format: []const u8, args: anytype) void {
|
fn logToFile(comptime format: []const u8, args: anytype) void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user