Changed a bit how log work
This commit is contained in:
parent
a6a3c092cc
commit
34688a0180
@ -3,5 +3,7 @@ pub const MAX_FILE_SIZE = 5e+4; // 50kb TODO: Put in config file
|
||||
pub const CSV_DELIMITER = ';';
|
||||
|
||||
// Testing
|
||||
|
||||
pub const TEST_DATA_DIR = "test_data/v0.1.2"; // Maybe put that directly in the build
|
||||
|
||||
// Debug
|
||||
pub const DONT_SEND = true;
|
||||
|
@ -115,6 +115,13 @@ pub const FileEngine = struct {
|
||||
_ = std.fs.cwd().createFile(path, .{}) catch return;
|
||||
}
|
||||
|
||||
pub fn createLog(self: FileEngine, file_name: []const u8) void {
|
||||
const path = std.fmt.allocPrint(self.allocator, "{s}/LOG/{s}.log", .{ self.path_to_ZipponDB_dir, file_name }) catch return;
|
||||
defer self.allocator.free(path);
|
||||
|
||||
_ = std.fs.cwd().createFile(path, .{}) catch return;
|
||||
}
|
||||
|
||||
pub fn log(self: FileEngine, file_name: []const u8, level: Level, comptime format: []const u8, args: anytype) void {
|
||||
const path = std.fmt.allocPrint(self.allocator, "{s}/LOG/{s}.log", .{ self.path_to_ZipponDB_dir, file_name }) catch return;
|
||||
defer self.allocator.free(path);
|
||||
@ -127,6 +134,7 @@ pub const FileEngine = struct {
|
||||
const writer = file.writer();
|
||||
const now = DateTime.now();
|
||||
|
||||
// TODO: Use a format to add the 0 to be 00:00 and not 0:0
|
||||
writer.print("Time: {d}/{d}/{d}-{d}:{d}:{d}.{d} - ", .{ now.years, now.months, now.days, now.hours, now.minutes, now.seconds, now.ms }) catch return;
|
||||
switch (level) {
|
||||
.Debug => writer.print("Debug - ", .{}) catch return,
|
||||
@ -1150,12 +1158,14 @@ pub const FileEngine = struct {
|
||||
}
|
||||
|
||||
// Return true if the map have all the member name as key and not more
|
||||
pub fn checkIfAllMemberInMap(self: *FileEngine, struct_name: []const u8, map: *std.StringHashMap([]const u8)) FileEngineError!bool {
|
||||
pub fn checkIfAllMemberInMap(self: *FileEngine, struct_name: []const u8, map: *std.StringHashMap([]const u8), error_message_buffer: *std.ArrayList(u8)) FileEngineError!bool {
|
||||
const all_struct_member = try self.structName2structMembers(struct_name);
|
||||
var count: u16 = 0;
|
||||
|
||||
const writer = error_message_buffer.writer();
|
||||
|
||||
for (all_struct_member) |mn| {
|
||||
if (map.contains(self.locToSlice(mn))) count += 1 else std.debug.print("Missing: {s}\n", .{self.locToSlice(mn)}); // TODO: Handle missing print better
|
||||
if (map.contains(self.locToSlice(mn))) count += 1 else writer.print(" {s},", .{self.locToSlice(mn)}) catch return FileEngineError.WriteError; // TODO: Handle missing print better
|
||||
}
|
||||
|
||||
return ((count == all_struct_member.len) and (count == map.count()));
|
||||
|
@ -48,7 +48,7 @@ pub fn main() !void {
|
||||
if (to_init) {
|
||||
file_engine = FileEngine.init(allocator, path);
|
||||
try file_engine.checkAndCreateDirectories();
|
||||
file_engine.resetLog("main");
|
||||
//file_engine.createLog("main");
|
||||
file_engine.log("main", .Info, "Found envirionment variable ZIPPONDB_PATH: {s}", .{path});
|
||||
}
|
||||
} else {
|
||||
|
5
src/stuffs/queue.zig
Normal file
5
src/stuffs/queue.zig
Normal file
@ -0,0 +1,5 @@
|
||||
pub const Node = struct {
|
||||
prev: ?*Node = null,
|
||||
next: ?*Node = null,
|
||||
query: []const u8,
|
||||
};
|
@ -336,12 +336,19 @@ pub const Parser = struct {
|
||||
defer data_map.deinit();
|
||||
try self.parseNewData(&data_map);
|
||||
|
||||
var error_message_buffer = std.ArrayList(u8).init(self.allocator);
|
||||
defer error_message_buffer.deinit();
|
||||
const error_message_buffer_writer = error_message_buffer.writer();
|
||||
error_message_buffer_writer.writeAll("Error missing: ") catch return ZipponError.WriteError;
|
||||
|
||||
// TODO: Print the entire list of missing
|
||||
if (!(self.file_engine.checkIfAllMemberInMap(self.struct_name, &data_map) catch {
|
||||
if (!(self.file_engine.checkIfAllMemberInMap(self.struct_name, &data_map, &error_message_buffer) catch {
|
||||
return ZiQlParserError.StructNotFound;
|
||||
})) {
|
||||
_ = error_message_buffer.pop();
|
||||
_ = error_message_buffer.pop();
|
||||
return printError(
|
||||
"Error: Missing member",
|
||||
error_message_buffer.items,
|
||||
ZiQlParserError.MemberMissing,
|
||||
self.toker.buffer,
|
||||
token.loc.start,
|
||||
|
Loading…
x
Reference in New Issue
Block a user