1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

Zap: remove newline for Zig's default log fn

This commit is contained in:
QSmally 2025-05-08 15:30:54 +02:00
parent ec7cac6f6a
commit fd567f3c29
No known key found for this signature in database
GPG key ID: 0ECB315650D4A8E4
6 changed files with 29 additions and 29 deletions

View file

@ -25,7 +25,7 @@ const Handler = struct {
}; };
if (r.body) |body| { if (r.body) |body| {
std.log.info("Body length is {any}\n", .{body.len}); std.log.info("Body length is {any}", .{body.len});
} }
// parse potential query params (for ?terminate=true) // parse potential query params (for ?terminate=true)
@ -43,7 +43,7 @@ const Handler = struct {
for (params.items) |kv| { for (params.items) |kv| {
if (kv.value) |v| { if (kv.value) |v| {
std.debug.print("\n", .{}); std.debug.print("\n", .{});
std.log.info("Param `{s}` in owned list is {any}\n", .{ kv.key, v }); std.log.info("Param `{s}` in owned list is {any}", .{ kv.key, v });
switch (v) { switch (v) {
// single-file upload // single-file upload
zap.Request.HttpParam.Hash_Binfile => |*file| { zap.Request.HttpParam.Hash_Binfile => |*file| {
@ -51,9 +51,9 @@ const Handler = struct {
const mimetype = file.mimetype orelse "(no mimetype)"; const mimetype = file.mimetype orelse "(no mimetype)";
const data = file.data orelse ""; const data = file.data orelse "";
std.log.debug(" filename: `{s}`\n", .{filename}); std.log.debug(" filename: `{s}`", .{filename});
std.log.debug(" mimetype: {s}\n", .{mimetype}); std.log.debug(" mimetype: {s}", .{mimetype});
std.log.debug(" contents: {any}\n", .{data}); std.log.debug(" contents: {any}", .{data});
}, },
// multi-file upload // multi-file upload
zap.Request.HttpParam.Array_Binfile => |*files| { zap.Request.HttpParam.Array_Binfile => |*files| {
@ -62,9 +62,9 @@ const Handler = struct {
const mimetype = file.mimetype orelse "(no mimetype)"; const mimetype = file.mimetype orelse "(no mimetype)";
const data = file.data orelse ""; const data = file.data orelse "";
std.log.debug(" filename: `{s}`\n", .{filename}); std.log.debug(" filename: `{s}`", .{filename});
std.log.debug(" mimetype: {s}\n", .{mimetype}); std.log.debug(" mimetype: {s}", .{mimetype});
std.log.debug(" contents: {any}\n", .{data}); std.log.debug(" contents: {any}", .{data});
} }
files.*.deinit(); files.*.deinit();
}, },
@ -79,7 +79,7 @@ const Handler = struct {
// check if we received a terminate=true parameter // check if we received a terminate=true parameter
if (r.getParamSlice("terminate")) |str| { if (r.getParamSlice("terminate")) |str| {
std.log.info("?terminate={s}\n", .{str}); std.log.info("?terminate={s}", .{str});
if (std.mem.eql(u8, str, "true")) { if (std.mem.eql(u8, str, "true")) {
zap.stop(); zap.stop();
} }
@ -110,9 +110,9 @@ pub fn main() !void {
); );
try listener.listen(); try listener.listen();
std.log.info("\n\nURL is http://localhost:3000\n", .{}); std.log.info("\n\nURL is http://localhost:3000", .{});
std.log.info("\ncurl -v --request POST -F img=@test012345.bin http://127.0.0.1:3000\n", .{}); std.log.info("\ncurl -v --request POST -F img=@test012345.bin http://127.0.0.1:3000", .{});
std.log.info("\n\nTerminate with CTRL+C or by sending query param terminate=true\n", .{}); std.log.info("\n\nTerminate with CTRL+C or by sending query param terminate=true", .{});
zap.start(.{ zap.start(.{
.threads = 1, .threads = 1,

View file

@ -87,8 +87,8 @@ pub fn main() !void {
std.log.info("Cookie ZIG_ZAP not found!", .{}); std.log.info("Cookie ZIG_ZAP not found!", .{});
} }
} else |err| { } else |err| {
std.log.err("ERROR!\n", .{}); std.log.err("ERROR!", .{});
std.log.err("cannot check for `ZIG_ZAP` cookie: {any}\n", .{err}); std.log.err("cannot check for `ZIG_ZAP` cookie: {any}", .{err});
} }
r.setCookie(.{ r.setCookie(.{
@ -101,8 +101,8 @@ pub fn main() !void {
// //
// check out other params: domain, path, secure, http_only // check out other params: domain, path, secure, http_only
}) catch |err| { }) catch |err| {
std.log.err("ERROR!\n", .{}); std.log.err("ERROR!", .{});
std.log.err("cannot set cookie: {any}\n", .{err}); std.log.err("cannot set cookie: {any}", .{err});
}; };
r.sendBody("Hello") catch unreachable; r.sendBody("Hello") catch unreachable;

View file

@ -86,5 +86,5 @@ pub fn main() !void {
// show potential memory leaks when ZAP is shut down // show potential memory leaks when ZAP is shut down
const has_leaked = gpa.detectLeaks(); const has_leaked = gpa.detectLeaks();
std.log.debug("Has leaked: {}\n", .{has_leaked}); std.log.debug("Has leaked: {}", .{has_leaked});
} }

View file

@ -111,7 +111,7 @@ pub fn main() !void {
std.log.info("Param one not found!", .{}); std.log.info("Param one not found!", .{});
} }
} else |err| { } else |err| {
std.log.err("cannot check for `one` param: {any}\n", .{err}); std.log.err("cannot check for `one` param: {any}", .{err});
} }
// check if we received a terminate=true parameter // check if we received a terminate=true parameter
@ -137,7 +137,7 @@ pub fn main() !void {
); );
try listener.listen(); try listener.listen();
std.log.info("\n\nTerminate with CTRL+C or by sending query param terminate=true\n", .{}); std.log.info("\n\nTerminate with CTRL+C or by sending query param terminate=true", .{});
const thread = try makeRequestThread(allocator, "http://127.0.0.1:3000/?one=1&two=2&string=hello+world&float=6.28&bool=true"); const thread = try makeRequestThread(allocator, "http://127.0.0.1:3000/?one=1&two=2&string=hello+world&float=6.28&bool=true");
defer thread.join(); defer thread.join();

View file

@ -440,9 +440,9 @@ pub fn UserPassSession(comptime Lookup: type, comptime lockedPwLookups: bool) ty
.value = "invalid", .value = "invalid",
.max_age_s = -1, .max_age_s = -1,
})) { })) {
zap.debug("logout ok\n", .{}); zap.debug("logout ok", .{});
} else |err| { } else |err| {
zap.debug("logout cookie setting failed: {any}\n", .{err}); zap.debug("logout cookie setting failed: {any}", .{err});
} }
r.parseCookies(false); r.parseCookies(false);

View file

@ -137,24 +137,24 @@ fn parseBinfilesFrom(a: Allocator, o: fio.FIOBJ) !HttpParam {
fio.FIOBJ_T_DATA => { fio.FIOBJ_T_DATA => {
if (fio.is_invalid(data) == 1) { if (fio.is_invalid(data) == 1) {
data_slice = "(zap: invalid data)"; data_slice = "(zap: invalid data)";
zap.log.warn("HTTP param binary file is not a data object\n", .{}); zap.log.warn("HTTP param binary file is not a data object", .{});
} else { } else {
// the data // the data
const data_len = fio.fiobj_data_len(data); const data_len = fio.fiobj_data_len(data);
var data_buf = fio.fiobj_data_read(data, data_len); var data_buf = fio.fiobj_data_read(data, data_len);
if (data_len < 0) { if (data_len < 0) {
zap.log.warn("HTTP param binary file size negative: {d}\n", .{data_len}); zap.log.warn("HTTP param binary file size negative: {d}", .{data_len});
zap.log.warn("FIOBJ_TYPE of data is: {d}\n", .{fio.fiobj_type(data)}); zap.log.warn("FIOBJ_TYPE of data is: {d}", .{fio.fiobj_type(data)});
} else { } else {
if (data_buf.len != data_len) { if (data_buf.len != data_len) {
zap.log.warn("HTTP param binary file size mismatch: should {d}, is: {d}\n", .{ data_len, data_buf.len }); zap.log.warn("HTTP param binary file size mismatch: should {d}, is: {d}", .{ data_len, data_buf.len });
} }
if (data_buf.len > 0) { if (data_buf.len > 0) {
data_slice = data_buf.data[0..data_buf.len]; data_slice = data_buf.data[0..data_buf.len];
} else { } else {
zap.log.warn("HTTP param binary file buffer size negative: {d}\n", .{data_buf.len}); zap.log.warn("HTTP param binary file buffer size negative: {d}", .{data_buf.len});
data_slice = "(zap: invalid data: negative BUFFER size)"; data_slice = "(zap: invalid data: negative BUFFER size)";
} }
} }
@ -379,7 +379,7 @@ pub fn setContentType(self: *const Request, c: ContentType) HttpError!void {
.JSON => "application/json", .JSON => "application/json",
else => "text/html", else => "text/html",
}; };
zap.log.debug("setting content-type to {s}\n", .{s}); zap.log.debug("setting content-type to {s}", .{s});
return self.setHeader("content-type", s); return self.setHeader("content-type", s);
} }
@ -511,7 +511,7 @@ pub fn setHeader(self: *const Request, name: []const u8, value: []const u8) Http
// FIXME without the following if, we get errors in release builds // FIXME without the following if, we get errors in release builds
// at least we don't have to log unconditionally // at least we don't have to log unconditionally
if (ret == -1) { if (ret == -1) {
zap.log.debug("***************** zap.zig:274\n", .{}); zap.log.debug("***************** zap.zig:274", .{});
} }
if (ret == 0) return; if (ret == 0) return;
@ -680,7 +680,7 @@ pub fn setCookie(self: *const Request, args: CookieArgs) HttpError!void {
// TODO: still happening? // TODO: still happening?
const ret = fio.http_set_cookie(self.h, c); const ret = fio.http_set_cookie(self.h, c);
if (ret == -1) { if (ret == -1) {
zap.log.err("fio.http_set_cookie returned: {}\n", .{ret}); zap.log.err("fio.http_set_cookie returned: {}", .{ret});
return error.SetCookie; return error.SetCookie;
} }
} }