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

A couple std.log conveniences #9224

Merged
merged 2 commits into from Aug 20, 2021
Merged

A couple std.log conveniences #9224

merged 2 commits into from Aug 20, 2021

Conversation

marler8997
Copy link
Contributor

@marler8997 marler8997 commented Jun 24, 2021

  1. Expose default std.log implementation

This allows root.log implementations to capture log messages, process them, and forward them to the default implementation if desired.

  1. Expose mechanism to convert log levels to string literals

This makes it easier to reproduce and customize the default log message style with the level prefix. This can be seen by the test cases in compare_output.zig.

This allows root.log implementations to capture log messages, process them, and forward them to the default implementation if desired.
@marler8997 marler8997 changed the title Expose default std.log implementation A couple std.log conveniences Jun 24, 2021
@@ -100,6 +100,23 @@ pub const Level = enum {
info,
/// Debug: messages only useful for debugging.
debug,

/// Returns a string literal of the given level in full text form.
pub fn asText(comptime self: Level) switch (self) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not implement a custom format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used to append the level "text" to other comptime strings, i.e.

level.asText() ++ ": " ++ fmt ++ "\n"

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. The repetition in the return type and the function body is not that nice but I can't think of a way to DRY it up.

@marler8997 marler8997 marked this pull request as ready for review June 24, 2021 13:07
@Vexu Vexu merged commit b3d3e93 into ziglang:master Aug 20, 2021
@marler8997 marler8997 deleted the defaultLog branch July 9, 2022 14:09
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.

None yet

3 participants