Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make loglevel pub and only alloc when needed #38

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Conversation

nilslice
Copy link
Member

@nilslice nilslice commented Nov 4, 2024

Fixes #37
Fixes #32

& relates to dylibso/xtp-zig-bindgen#10

Comment on lines +235 to +247
fn loggingEnabled(level: LogLevel) bool {
const currentLevelInt = extism.get_log_level();
if (currentLevelInt == std.math.maxInt(i32)) {
return false;
}

const levelInt = @intFromEnum(level);
if (levelInt >= currentLevelInt) {
return true;
}

return false;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zshipko, just a second set of eyes on the logic here would be helpful :)

@nilslice nilslice requested a review from zshipko November 4, 2024 19:59
pub fn setErrorFmt(self: Plugin, comptime fmt: []const u8, args: anytype) !void {
const data = try std.fmt.allocPrint(self.allocator, fmt, args);
self.setError(data);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quality of life improvement (relates to #32)

if (loggingEnabled(level)) {
const data = try std.fmt.allocPrint(self.allocator, fmt, args);
self.log(level, data);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quality of life improvement (relates to #32)

@nilslice nilslice merged commit d25f594 into main Nov 4, 2024
2 checks passed
@nilslice nilslice deleted the logging branch November 4, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mark LogLevel pub, add Trace, and re-order according to get_log_level quality of life improvements
2 participants