wip
This commit is contained in:
parent
1043710b44
commit
e944646bfb
|
|
@ -1,11 +1,89 @@
|
||||||
// file representation for the structured log
|
// file representation for the structured log
|
||||||
|
|
||||||
|
pub const LogMemDecoderOpKind = enum {
|
||||||
|
integer,
|
||||||
|
boolean,
|
||||||
|
floating,
|
||||||
|
string,
|
||||||
|
structure,
|
||||||
|
enumeration,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const StringIndex = u32;
|
||||||
|
pub const FieldListIndex = u32;
|
||||||
|
pub const DecoderOpIndex = u32;
|
||||||
|
pub const EnumTableIndex = u32;
|
||||||
|
|
||||||
|
pub const Field = struct {
|
||||||
|
name: StringIndex,
|
||||||
|
op: DecoderOpIndex,
|
||||||
|
};
|
||||||
|
|
||||||
|
// encoded form of the ArgsDecoderOp, uses indices instead of
|
||||||
|
// pointers for EnumTables, fields, and type_names
|
||||||
|
pub const LogMemDecoderOp = union(LogMemDecoderOpKind) {
|
||||||
|
integer: struct {
|
||||||
|
bits: u16 = 0,
|
||||||
|
signed: bool = false,
|
||||||
|
},
|
||||||
|
boolean: struct {
|
||||||
|
bits: u16 = 0,
|
||||||
|
},
|
||||||
|
floating: struct {},
|
||||||
|
string: StringIndex,
|
||||||
|
structure: struct {
|
||||||
|
fields: FieldListIndex,
|
||||||
|
},
|
||||||
|
enumeration: struct {
|
||||||
|
enumTable: EnumTableIndex,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const EnumEntryInfo = struct {
|
||||||
|
enums: std.ArrayList(EnumEntry) = .empty,
|
||||||
|
name: StringIndex,
|
||||||
|
};
|
||||||
|
|
||||||
// in-memory representation of a logger file
|
// in-memory representation of a logger file
|
||||||
|
// a gLoggerContext may create one of these and pass it
|
||||||
|
// no pointers- everything is intended to be serialized to disk
|
||||||
pub const LogMem = struct {
|
pub const LogMem = struct {
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
logEntries: p2.PagedVector(StructuredLog) = .empty,
|
||||||
|
loggerStates: std.AutoHashMapUnmanaged(u32, LoggerState) = .empty,
|
||||||
|
loggerSites: std.AutoHashMapUnmanaged(u32, LoggerState) = .empty,
|
||||||
|
|
||||||
logEntries: std.ArrayList(slugger.StructuredLog) = .empty,
|
enumData: std.AutoHashMapUnmanaged(u32, EnumEntriesList) = .empty,
|
||||||
|
|
||||||
|
pub fn init(gpa: std.mem.Allocator) @This() {
|
||||||
|
return .{
|
||||||
|
.allocator = gpa,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize(self: *@This(), out: std.Io.Writer) !void {
|
||||||
|
_ = self;
|
||||||
|
_ = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn addLoggerState(self: *@This(), id: u32, state: *const LoggerState) void {}
|
||||||
|
|
||||||
|
pub fn pushLog(self: *@This(), log: slugger.StructuredLog) !void {
|
||||||
|
try self.logEntries.append(log);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test "testing fileformat" {
|
||||||
|
const logmem = LogMem.init(std.testing.allocator);
|
||||||
|
|
||||||
|
for (0..5000) |i| {
|
||||||
|
try logmem.pushLog(.{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const slugger = @import("slugger.zig");
|
const slugger = @import("slugger.zig");
|
||||||
|
const StructuredLog = slugger.StructuredLog;
|
||||||
|
const LoggerState = slugger.LoggerState;
|
||||||
|
const EnumEntry = slugger.EnumEntry;
|
||||||
|
const p2 = @import("p2");
|
||||||
|
|
|
||||||
|
|
@ -576,6 +576,17 @@ pub const LoggerOptions = struct {
|
||||||
has_stdout: bool = false,
|
has_stdout: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const StructuredLogColorMode = enum {
|
||||||
|
none,
|
||||||
|
ascii_codes,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const RenderOptions = struct {
|
||||||
|
colormode: StructuredLogColorMode,
|
||||||
|
show_time: bool = false,
|
||||||
|
show_logger: bool = true,
|
||||||
|
};
|
||||||
|
|
||||||
pub const StructuredLog = struct {
|
pub const StructuredLog = struct {
|
||||||
serialized_args: []const u8, // not a string
|
serialized_args: []const u8, // not a string
|
||||||
loggerId: u32,
|
loggerId: u32,
|
||||||
|
|
@ -594,7 +605,7 @@ pub const StructuredLog = struct {
|
||||||
/// numbered arguments, escaped braces, scalar formats and constant options.
|
/// numbered arguments, escaped braces, scalar formats and constant options.
|
||||||
/// Named/dynamic options and custom Zig format methods are unsupported.
|
/// Named/dynamic options and custom Zig format methods are unsupported.
|
||||||
/// Integer schemas wider than 128 bits are unsupported.
|
/// Integer schemas wider than 128 bits are unsupported.
|
||||||
pub fn render(self: @This(), logger: *const LoggerSystem, writer: *std.Io.Writer) RenderError!void {
|
pub fn render(self: @This(), logger: *const LoggerSystem, writer: *std.Io.Writer, options: RenderOptions) RenderError!void {
|
||||||
if (self.loggerId >= logger.loggerStatesById.items.len or self.sourceId >= logger.logSites.items.len) return error.InvalidLogReference;
|
if (self.loggerId >= logger.loggerStatesById.items.len or self.sourceId >= logger.logSites.items.len) return error.InvalidLogReference;
|
||||||
const site = logger.logSites.items[self.sourceId];
|
const site = logger.logSites.items[self.sourceId];
|
||||||
const ops = site.decoder.ops;
|
const ops = site.decoder.ops;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue