-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `@setCold` builtin was removed in 0.14.0-dev.1337+d3c6f7179 and replaced with `@branchHint`. Unfortunately comptime conditional logic cannot be used to choose between `@setCold` and `@branchHint`, so separate logging modules are chosen between at build time. Other usages of `@setCold` have been removed without replacement.
- Loading branch information
Showing
9 changed files
with
124 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/// Log an error message. This log level is intended to be used | ||
/// when something has gone wrong. This might be recoverable or might | ||
/// be followed by the program exiting. | ||
pub fn err( | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
@branchHint(.cold); | ||
log(.err, format, args); | ||
} | ||
|
||
/// Log a warning message. This log level is intended to be used if | ||
/// it is uncertain whether something has gone wrong or not, but the | ||
/// circumstances would be worth investigating. | ||
pub fn warn( | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
log(.warn, format, args); | ||
} | ||
|
||
/// Log an info message. This log level is intended to be used for | ||
/// general messages about the state of the program. | ||
pub fn info( | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
log(.info, format, args); | ||
} | ||
|
||
/// Log an info message. This log level is intended to be used for | ||
/// general messages about the state of the program that are noisy | ||
/// and are turned off by default. | ||
pub fn infoVerbose( | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
if (comptime !verbose_logging) return; | ||
log(.info, format, args); | ||
} | ||
|
||
/// Log a debug message. This log level is intended to be used for | ||
/// messages which are only useful for debugging. | ||
pub fn debug( | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
log(.debug, format, args); | ||
} | ||
|
||
/// Log a debug message. This log level is intended to be used for | ||
/// messages which are only useful for debugging that are noisy and | ||
/// are turned off by default. | ||
pub fn debugVerbose( | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
if (comptime !verbose_logging) return; | ||
log(.debug, format, args); | ||
} | ||
|
||
const verbose_logging = if (@hasDecl(build_options, "verbose_logging")) | ||
build_options.verbose_logging | ||
else | ||
false; | ||
|
||
const level: std.log.Level = if (@hasDecl(build_options, "log_level")) | ||
std.enums.nameCast(std.log.Level, build_options.log_level) | ||
else | ||
.warn; | ||
|
||
fn log( | ||
comptime message_level: std.log.Level, | ||
comptime format: []const u8, | ||
args: anytype, | ||
) void { | ||
if (comptime !logEnabled(message_level)) return; | ||
|
||
const actual_fmt = "thread {d}: " ++ format; | ||
std.options.logFn(message_level, .zimalloc, actual_fmt, .{std.Thread.getCurrentId()} ++ args); | ||
} | ||
|
||
fn logEnabled(comptime message_level: std.log.Level) bool { | ||
return @intFromEnum(message_level) <= @intFromEnum(level); | ||
} | ||
|
||
const std = @import("std"); | ||
|
||
const build_options = @import("build_options"); |
File renamed without changes.