From 1fdff0bacde58d629a97cd889301f1dd1be76ee3 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 27 Aug 2024 11:42:07 -0700 Subject: [PATCH] include credenitals in logging control (tie to signing) --- src/aws.zig | 3 +++ src/aws_credentials.zig | 51 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/aws.zig b/src/aws.zig index 6b1b556..97d4fb9 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -16,12 +16,15 @@ const scoped_log = std.log.scoped(.aws); /// controls are insufficient (e.g. use in build script) pub fn globalLogControl(aws_level: std.log.Level, http_level: std.log.Level, signing_level: std.log.Level, off: bool) void { const signing = @import("aws_signing.zig"); + const credentials = @import("aws_credentials.zig"); logs_off = off; signing.logs_off = off; + credentials.logs_off = off; awshttp.logs_off = off; log_level = aws_level; awshttp.log_level = http_level; signing.log_level = signing_level; + credentials.log_level = signing_level; } /// Specifies logging level. This should not be touched unless the normal /// zig logging capabilities are inaccessible (e.g. during a build) diff --git a/src/aws_credentials.zig b/src/aws_credentials.zig index d22dc4d..7919118 100644 --- a/src/aws_credentials.zig +++ b/src/aws_credentials.zig @@ -11,7 +11,56 @@ const std = @import("std"); const builtin = @import("builtin"); const auth = @import("aws_authentication.zig"); -const log = std.log.scoped(.aws_credentials); +const scoped_log = std.log.scoped(.aws_credentials); +/// Specifies logging level. This should not be touched unless the normal +/// zig logging capabilities are inaccessible (e.g. during a build) +pub var log_level: std.log.Level = .debug; + +/// Turn off logging completely +pub var logs_off: bool = false; +const log = struct { + /// 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 { + if (!logs_off and @intFromEnum(std.log.Level.err) <= @intFromEnum(log_level)) + scoped_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 { + if (!logs_off and @intFromEnum(std.log.Level.warn) <= @intFromEnum(log_level)) + scoped_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 { + if (!logs_off and @intFromEnum(std.log.Level.info) <= @intFromEnum(log_level)) + scoped_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 { + if (!logs_off and @intFromEnum(std.log.Level.debug) <= @intFromEnum(log_level)) + scoped_log.debug(format, args); + } +}; pub const Profile = struct { /// Credential file. Defaults to AWS_SHARED_CREDENTIALS_FILE or ~/.aws/credentials