use zig-glib-log for playtwitch

This commit is contained in:
LordMZTE 2022-07-18 17:34:22 +02:00
parent 75f953c6b6
commit 2f65edf3c1
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
5 changed files with 13 additions and 43 deletions

View file

@ -23,7 +23,7 @@ install-scripts target=(`echo $HOME` + "/.local/bin"): build-scripts
build-scripts:
cd scripts/randomwallpaper && zig build -Drelease-fast
cd scripts/playtwitch && zig build -Drelease-fast
cd scripts/playtwitch && gyro build -Drelease-fast
install-lsps-paru:
#!/bin/sh

View file

@ -1,2 +1,5 @@
zig-cache/
zig-out/
deps.zig
gyro.lock
.gyro

View file

@ -1,4 +1,5 @@
const std = @import("std");
const pkgs = @import("deps.zig").pkgs;
pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose
@ -17,6 +18,7 @@ pub fn build(b: *std.build.Builder) void {
exe.linkLibC();
exe.linkSystemLibrary("gtk4");
pkgs.addAllTo(exe);
exe.strip = mode != .Debug;

View file

@ -0,0 +1,6 @@
deps:
glib-log:
git:
url: "https://mzte.de/git/LordMZTE/zig-glib-log.git"
ref: master
root: src/main.zig

View file

@ -3,48 +3,7 @@ const ffi = @import("ffi.zig");
const c = ffi.c;
const gui = @import("gui.zig");
pub fn log(
comptime level: std.log.Level,
comptime scope: @TypeOf(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) void {
const Buf = struct {
pub threadlocal var fmt_buf: [512]u8 = undefined;
};
const g_level = switch (level) {
.err => c.G_LOG_LEVEL_ERROR,
.warn => c.G_LOG_LEVEL_WARNING,
.info => c.G_LOG_LEVEL_INFO,
.debug => c.G_LOG_LEVEL_DEBUG,
};
const s = std.fmt.bufPrintZ(
&Buf.fmt_buf,
format,
args,
) catch return;
var fields = [_]c.GLogField{
c.GLogField{
.key = "GLIB_DOMAIN",
.value = "playtwitch-" ++ @tagName(scope),
.length = -1,
},
c.GLogField{
.key = "MESSAGE",
.value = @ptrCast(*const anyopaque, s),
.length = -1,
},
};
c.g_log_structured_array(
g_level,
&fields,
fields.len,
);
}
pub const log = @import("glib-log").log(c, "playtwitch", 512);
pub fn main() !u8 {
var udata_arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);