Changed some print to log
This commit is contained in:
parent
c5f931cf04
commit
e5f2f7c5e5
@ -23,6 +23,8 @@ const BUFFER_SIZE = @import("config.zig").BUFFER_SIZE;
|
|||||||
const MAX_FILE_SIZE = @import("config.zig").MAX_FILE_SIZE;
|
const MAX_FILE_SIZE = @import("config.zig").MAX_FILE_SIZE;
|
||||||
const CSV_DELIMITER = @import("config.zig").CSV_DELIMITER;
|
const CSV_DELIMITER = @import("config.zig").CSV_DELIMITER;
|
||||||
|
|
||||||
|
const log = std.log.scoped(.fileEngine);
|
||||||
|
|
||||||
/// Manage everything that is relate to read or write in files
|
/// Manage everything that is relate to read or write in files
|
||||||
/// Or even get stats, whatever. If it touch files, it's here
|
/// Or even get stats, whatever. If it touch files, it's here
|
||||||
pub const FileEngine = struct {
|
pub const FileEngine = struct {
|
||||||
@ -288,7 +290,7 @@ pub const FileEngine = struct {
|
|||||||
|
|
||||||
file.close(); // Do I need to close ? I think so
|
file.close(); // Do I need to close ? I think so
|
||||||
file = std.fs.cwd().openFile(path_buff, .{}) catch {
|
file = std.fs.cwd().openFile(path_buff, .{}) catch {
|
||||||
std.debug.print("Error trying to open {s}\n", .{path_buff});
|
log.err("Error trying to open {s}\n", .{path_buff});
|
||||||
@panic("Can't open file to update a data iterator");
|
@panic("Can't open file to update a data iterator");
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -954,7 +956,7 @@ pub const FileEngine = struct {
|
|||||||
continue;
|
continue;
|
||||||
}, // file read till the end
|
}, // file read till the end
|
||||||
else => {
|
else => {
|
||||||
std.debug.print("Error while reading file: {any}\n", .{err});
|
log.err("Error while reading file: {any}", .{err});
|
||||||
break;
|
break;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
12
src/main.zig
12
src/main.zig
@ -70,13 +70,13 @@ pub fn myLog(
|
|||||||
|
|
||||||
// TODO: If an argument is given when starting the binary, it is the db path
|
// TODO: If an argument is given when starting the binary, it is the db path
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var state: State = .expect_main_command;
|
errdefer log.warn("Main function ended with an error", .{});
|
||||||
|
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
const allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
defer switch (gpa.deinit()) {
|
defer switch (gpa.deinit()) {
|
||||||
.ok => {},
|
.ok => {},
|
||||||
.leak => std.log.debug("We fucked it up bro...\n", .{}),
|
.leak => log.debug("We fucked it up bro...\n", .{}),
|
||||||
};
|
};
|
||||||
|
|
||||||
var file_engine = try initFileEngine.init(allocator, null);
|
var file_engine = try initFileEngine.init(allocator, null);
|
||||||
@ -86,7 +86,7 @@ pub fn main() !void {
|
|||||||
defer allocator.free(line_buf);
|
defer allocator.free(line_buf);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
std.debug.print("> ", .{});
|
std.debug.print("> ", .{}); // TODO: Find something better than just std.debug.print
|
||||||
const line = try std.io.getStdIn().reader().readUntilDelimiterOrEof(line_buf, '\n');
|
const line = try std.io.getStdIn().reader().readUntilDelimiterOrEof(line_buf, '\n');
|
||||||
|
|
||||||
if (line) |line_str| {
|
if (line) |line_str| {
|
||||||
@ -97,7 +97,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
var toker = cliTokenizer.init(null_term_line_str);
|
var toker = cliTokenizer.init(null_term_line_str);
|
||||||
var token = toker.next();
|
var token = toker.next();
|
||||||
state = .expect_main_command;
|
var state = State.expect_main_command;
|
||||||
|
|
||||||
while ((state != .end) and (state != .quit)) : (token = toker.next()) switch (state) {
|
while ((state != .end) and (state != .quit)) : (token = toker.next()) switch (state) {
|
||||||
.expect_main_command => switch (token.tag) {
|
.expect_main_command => switch (token.tag) {
|
||||||
@ -333,7 +333,7 @@ const initFileEngine = struct {
|
|||||||
if (!file_engine.isSchemaFileInDir()) {
|
if (!file_engine.isSchemaFileInDir()) {
|
||||||
try initSchema(allocator, &file_engine);
|
try initSchema(allocator, &file_engine);
|
||||||
} else {
|
} else {
|
||||||
std.debug.print("Database has a schema.\n", .{});
|
log.info("Database has a schema.\n", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
return file_engine;
|
return file_engine;
|
||||||
@ -359,7 +359,7 @@ const initFileEngine = struct {
|
|||||||
if (schema) |s| {
|
if (schema) |s| {
|
||||||
log.debug("Found environment variable ZIPPONDB_SCHEMA: {s}.", .{s});
|
log.debug("Found environment variable ZIPPONDB_SCHEMA: {s}.", .{s});
|
||||||
file_engine.initDataFolder(s) catch {
|
file_engine.initDataFolder(s) catch {
|
||||||
std.debug.print("Couldn't use {s} as schema.\n", .{s});
|
log.warn("Couldn't use {s} as schema.\n", .{s});
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
log.debug("No environment variable ZIPPONDB_SCHEMA found.", .{});
|
log.debug("No environment variable ZIPPONDB_SCHEMA found.", .{});
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const ZipponError = @import("errors.zig").ZipponError;
|
const ZipponError = @import("errors.zig").ZipponError;
|
||||||
|
|
||||||
|
const log = std.log.scoped(.utils);
|
||||||
|
|
||||||
pub fn getEnvVariable(allocator: std.mem.Allocator, variable: []const u8) ?[]const u8 {
|
pub fn getEnvVariable(allocator: std.mem.Allocator, variable: []const u8) ?[]const u8 {
|
||||||
var env_map = std.process.getEnvMap(allocator) catch return null;
|
var env_map = std.process.getEnvMap(allocator) catch return null;
|
||||||
defer env_map.deinit();
|
defer env_map.deinit();
|
||||||
@ -31,28 +33,12 @@ pub fn getDirTotalSize(dir: std.fs.Dir) !u64 {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getArgsString(allocator: std.mem.Allocator) std.ArrayList(u8) {
|
|
||||||
const args = try std.process.argsAlloc(allocator);
|
|
||||||
defer std.process.argsFree(allocator, args);
|
|
||||||
|
|
||||||
var buffer = std.ArrayList(u8).init(allocator);
|
|
||||||
var writer = buffer.writer();
|
|
||||||
|
|
||||||
for (args) |arg| {
|
|
||||||
writer.print("{s} ", .{arg});
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.append(0);
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
|
|
||||||
// Maybe create a struct for that
|
// Maybe create a struct for that
|
||||||
pub fn send(comptime format: []const u8, args: anytype) void {
|
pub fn send(comptime format: []const u8, args: anytype) void {
|
||||||
stdout.print(format, args) catch |err| {
|
stdout.print(format, args) catch |err| {
|
||||||
std.log.err("Can't send: {any}", .{err});
|
log.err("Can't send: {any}", .{err});
|
||||||
stdout.print("\x03\n", .{}) catch {};
|
stdout.print("\x03\n", .{}) catch {};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,6 +77,8 @@ pub fn printError(message: []const u8, err: ZipponError, query: ?[]const u8, sta
|
|||||||
writer.print(" \n", .{}) catch {}; // Align with the message
|
writer.print(" \n", .{}) catch {}; // Align with the message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("Parsing error: {s}", .{buffer.items});
|
||||||
|
|
||||||
send("{s}", .{buffer.items});
|
send("{s}", .{buffer.items});
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user