Skip to content

Commit ae2a0f4

Browse files
authored
Merge pull request #1025 from synfinatic/new-logger-v2
New logger v2
2 parents 172f1c3 + 9956c65 commit ae2a0f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+380
-365
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: golangci/golangci-lint-action@v6
3131
with:
3232
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
33-
version: v1.54.2
33+
version: v${{ vars.GOLANGCI_LINT_VERSION }}
3434

3535
# Optional: working directory, useful for monorepos
3636
# working-directory: somedir

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* `tags` command no longer supports the `--force-update` option
2626
* Change default log level from `warn` to `info`
2727
* Remove mention from docs that Firefox Multi-Account Containers plugin is supported #1021
28+
* Switch from logrus to log/slog #1001
2829

2930
### New Features
3031

cmd/aws-sso/cache_cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func (c CacheCmd) AfterApply(runCtx *RunContext) error {
3939
func (cc *CacheCmd) Run(ctx *RunContext) error {
4040
s, err := ctx.Settings.GetSelectedSSO(ctx.Cli.SSO)
4141
if err != nil {
42-
log.Fatalf("%s", err.Error())
42+
log.Fatal("unable to select SSO instance", "sso", ctx.Cli.SSO, "error", err.Error())
4343
}
4444

4545
ssoName, err := ctx.Settings.GetSelectedSSOName(ctx.Cli.SSO)
4646
if err != nil {
47-
log.Fatalf(err.Error())
47+
log.Fatal("unable to get name for SSO instance", "sso", ctx.Cli.SSO, "error", err.Error())
4848
}
4949

5050
added, deleted, err := ctx.Settings.Cache.Refresh(AwsSSO, s, ssoName, ctx.Cli.Cache.Threads)
@@ -59,13 +59,13 @@ func (cc *CacheCmd) Run(ctx *RunContext) error {
5959
}
6060

6161
if added > 0 || deleted > 0 {
62-
log.Infof("Updated cache: %d added, %d deleted", added, deleted)
62+
log.Info("Updated cache", "added", added, "deleted", deleted)
6363
// should we update our config??
6464
if !ctx.Cli.Cache.NoConfigCheck && ctx.Settings.AutoConfigCheck {
6565
if ctx.Settings.ConfigProfilesUrlAction != url.ConfigProfilesUndef {
6666
err := awsconfig.UpdateAwsConfig(ctx.Settings, "", true, false)
6767
if err != nil {
68-
log.Errorf("Unable to auto-update aws config file: %s", err.Error())
68+
log.Error("Unable to auto-update aws config file", "error", err.Error())
6969
}
7070
}
7171
}

cmd/aws-sso/console_cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func openConsole(ctx *RunContext, accountid int64, role string) error {
241241

242242
ctx.Settings.Cache.AddHistory(utils.MakeRoleARN(accountid, role))
243243
if err := ctx.Settings.Cache.Save(false); err != nil {
244-
log.WithError(err).Warnf("Unable to update cache")
244+
log.Warn("Unable to update cache", "error", err.Error())
245245
}
246246

247247
creds := GetRoleCredentials(ctx, AwsSSO, ctx.Cli.Console.STSRefresh, accountid, role)
@@ -263,7 +263,7 @@ func openConsoleAccessKey(ctx *RunContext, creds *storage.RoleCredentials,
263263

264264
resp, err := http.Get(signin.GetUrl())
265265
if err != nil {
266-
log.Debugf(err.Error())
266+
log.Debug("http get", "url", signin.GetUrl(), "error", err.Error())
267267
// sanitize error and remove sensitive URL from normal output
268268
r := regexp.MustCompile(`Get "[^"]+": `)
269269
e := r.ReplaceAllString(err.Error(), "")
@@ -279,7 +279,7 @@ func openConsoleAccessKey(ctx *RunContext, creds *storage.RoleCredentials,
279279
loginResponse := LoginResponse{}
280280
err = json.Unmarshal(body, &loginResponse)
281281
if err != nil {
282-
log.Tracef("LoginResponse body: %s", body)
282+
log.Trace("LoginResponse", "body", body)
283283
return fmt.Errorf("Error parsing Login response: %s", err.Error())
284284
}
285285

@@ -298,7 +298,7 @@ func openConsoleAccessKey(ctx *RunContext, creds *storage.RoleCredentials,
298298

299299
action, err := url.NewAction(ctx.Cli.Console.UrlAction)
300300
if err != nil {
301-
log.Fatalf("Invalid --url-action %s", ctx.Cli.Console.UrlAction)
301+
log.Fatal("Invalid --url-action", "action", ctx.Cli.Console.UrlAction)
302302
}
303303
if action == "" {
304304
action = ctx.Settings.UrlAction

cmd/aws-sso/ecs_client_cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ func ecsLoadCmd(ctx *RunContext, accountId int64, role string) error {
112112
// save history
113113
ctx.Settings.Cache.AddHistory(utils.MakeRoleARN(rFlat.AccountId, rFlat.RoleName))
114114
if err := ctx.Settings.Cache.Save(false); err != nil {
115-
log.WithError(err).Warnf("Unable to update cache")
115+
log.Warn("Unable to update cache", "error", err.Error())
116116
}
117117

118-
log.Debugf("%s", spew.Sdump(rFlat))
118+
log.Debug("role", "dump", spew.Sdump(rFlat))
119119
return c.SubmitCreds(creds, rFlat.Profile, ctx.Cli.Ecs.Load.Slotted)
120120
}
121121

@@ -184,11 +184,11 @@ func listProfiles(profiles []ecs.ListProfilesResponse) error {
184184
func newClient(server string, ctx *RunContext) *client.ECSClient {
185185
certChain, err := ctx.Store.GetEcsSslCert()
186186
if err != nil {
187-
log.Fatalf("Unable to get ECS SSL cert: %s", err)
187+
log.Fatal("Unable to get ECS SSL cert", "error", err.Error())
188188
}
189189
bearerToken, err := ctx.Store.GetEcsBearerToken()
190190
if err != nil {
191-
log.Fatalf("Unable to get ECS bearer token: %s", err)
191+
log.Fatal("Unable to get ECS bearer token", "error", err)
192192
}
193193
return client.NewECSClient(server, bearerToken, certChain)
194194
}

cmd/aws-sso/ecs_server_cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (cc *EcsServerCmd) Run(ctx *RunContext) error {
6060
// fetch the creds from our temporary file mounted in the docker container
6161
f, err := ecs.OpenSecurityFile(ecs.READ_ONLY)
6262
if err != nil {
63-
log.Warnf("Failed to open ECS credentials file: %s", err.Error())
63+
log.Warn("Failed to open ECS credentials file", "error", err.Error())
6464
} else {
6565
creds, err := ecs.ReadSecurityConfig(f)
6666
if err != nil {
@@ -100,15 +100,15 @@ func (cc *EcsServerCmd) Run(ctx *RunContext) error {
100100
}
101101

102102
if bearerToken == "" {
103-
log.Warnf("HTTP Auth: disabled. Use 'aws-sso ecs bearer-token' to enable")
103+
log.Warn("HTTP Auth: disabled. Use 'aws-sso ecs bearer-token' to enable")
104104
} else {
105105
log.Info("HTTP Auth: enabled")
106106
}
107107

108108
if privateKey != "" && certChain != "" {
109-
log.Infof("SSL/TLS: enabled")
109+
log.Info("SSL/TLS: enabled")
110110
} else {
111-
log.Warnf("SSL/TLS: disabled. Use 'aws-sso ecs cert' to enable")
111+
log.Warn("SSL/TLS: disabled. Use 'aws-sso ecs cert' to enable")
112112
}
113113

114114
s, err := server.NewEcsServer(context.TODO(), bearerToken, l, privateKey, certChain)

cmd/aws-sso/exec_cmd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (e ExecCmd) AfterApply(runCtx *RunContext) error {
5252
func (cc *ExecCmd) Run(ctx *RunContext) error {
5353
err := checkAwsEnvironment()
5454
if err != nil {
55-
log.WithError(err).Fatalf("Unable to continue")
55+
log.Fatal("Unable to continue", "error", err.Error())
5656
}
5757

5858
if runtime.GOOS == "windows" && ctx.Cli.Exec.Cmd == "" {
@@ -78,7 +78,7 @@ func execCmd(ctx *RunContext, accountid int64, role string) error {
7878

7979
ctx.Settings.Cache.AddHistory(utils.MakeRoleARN(accountid, role))
8080
if err := ctx.Settings.Cache.Save(false); err != nil {
81-
log.WithError(err).Warnf("Unable to update cache")
81+
log.Warn("Unable to update cache", "error", err.Error())
8282
}
8383

8484
// ready our command and connect everything up
@@ -91,7 +91,7 @@ func execCmd(ctx *RunContext, accountid int64, role string) error {
9191
// add the variables we need for AWS to the executor without polluting our
9292
// own process
9393
for k, v := range execShellEnvs(ctx, accountid, role, region) {
94-
log.Debugf("Setting %s = %s", k, v)
94+
log.Debug("Setting", "variable", k, "value", v)
9595
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
9696
}
9797
// just do it!
@@ -128,11 +128,11 @@ func execShellEnvs(ctx *RunContext, accountid int64, role, region string) map[st
128128
var roleInfo *sso.AWSRoleFlat
129129
if roleInfo, err = cache.Roles.GetRole(accountid, role); err != nil {
130130
// this error should never happen
131-
log.Errorf("Unable to find role in cache. Unable to set AWS_SSO_PROFILE")
131+
log.Error("Unable to find role in cache. Unable to set AWS_SSO_PROFILE")
132132
} else {
133133
shellVars["AWS_SSO_PROFILE"], err = roleInfo.ProfileName(ctx.Settings)
134134
if err != nil {
135-
log.Errorf("Unable to generate AWS_SSO_PROFILE: %s", err.Error())
135+
log.Error("Unable to generate AWS_SSO_PROFILE", "error", err.Error())
136136
}
137137

138138
// and any EnvVarTags

cmd/aws-sso/interactive.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (ctx *RunContext) PromptExec(exec CompleterExec) error {
4141
return err
4242
}
4343
if err = ctx.Settings.Cache.Expired(sso); err != nil {
44-
log.Infof(err.Error())
44+
log.Info("cache has expired", "error", err.Error())
4545
c := &CacheCmd{}
4646
if err = c.Run(ctx); err != nil {
4747
return err
@@ -138,21 +138,21 @@ func (tc *TagsCompleter) Executor(args string) {
138138

139139
ssoRoles := tc.roleTags.GetMatchingRoles(argsMap)
140140
if len(ssoRoles) == 0 {
141-
log.Fatalf("Invalid selection: No matching roles.")
141+
log.Fatal("Invalid selection: No matching roles.")
142142
} else if len(ssoRoles) > 1 {
143-
log.Fatalf("Invalid selection: Too many roles match selected values.")
143+
log.Fatal("Invalid selection: Too many roles match selected values.")
144144
}
145145
roleArn = ssoRoles[0]
146146
}
147147

148148
aId, rName, err := utils.ParseRoleARN(roleArn)
149149
if err != nil {
150-
log.Fatalf("Unable to parse %s: %s", roleArn, err.Error())
150+
log.Fatal("Unable to parse", "arn", roleArn, "error", err.Error())
151151
}
152152

153153
err = tc.exec(tc.ctx, aId, rName)
154154
if err != nil {
155-
log.Fatalf("Unable to exec: %s", err.Error())
155+
log.Fatal("Unable to exec TagsCompleter", "error", err.Error())
156156
}
157157
}
158158

cmd/aws-sso/list_cmd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (cc *ListCmd) Run(ctx *RunContext) error {
8383
if err = ctx.Settings.Cache.Expired(s); err != nil {
8484
c := &CacheCmd{}
8585
if err = c.Run(ctx); err != nil {
86-
log.WithError(err).Errorf("Unable to refresh local cache")
86+
log.Error("Unable to refresh local cache", "error", err.Error())
8787
}
8888
}
8989

@@ -120,7 +120,7 @@ func (cc *DefaultCmd) Run(ctx *RunContext) error {
120120
if err = ctx.Settings.Cache.Expired(s); err != nil {
121121
c := &CacheCmd{}
122122
if err = c.Run(ctx); err != nil {
123-
log.WithError(err).Errorf("Unable to refresh local cache")
123+
log.Error("Unable to refresh local cache", "error", err.Error())
124124
}
125125
}
126126

@@ -201,10 +201,10 @@ func printRoles(ctx *RunContext, fields []string, csv bool, prefixSearch []strin
201201
expires := ""
202202
ctr := storage.CreateTokenResponse{}
203203
if err := ctx.Store.GetCreateTokenResponse(AwsSSO.StoreKey(), &ctr); err != nil {
204-
log.Debugf("Unable to get SSO session expire time: %s", err.Error())
204+
log.Debug("Unable to get SSO session expire time", "error", err.Error())
205205
} else {
206206
if exp, err := utils.TimeRemain(ctr.ExpiresAt, true); err != nil {
207-
log.Errorf("Unable to determine time remain for %d: %s", ctr.ExpiresAt, err)
207+
log.Error("Unable to determine time remain", "expiresAt", ctr.ExpiresAt, "error", err.Error())
208208
} else {
209209
expires = fmt.Sprintf(" [Expires in: %s]", strings.TrimSpace(exp))
210210
}
@@ -249,7 +249,7 @@ func listAllFields() {
249249

250250
fields := []string{"Field", "Description"}
251251
if err := gotable.GenerateTable(ts, fields); err != nil {
252-
log.WithError(err).Fatalf("Unable to generate report")
252+
log.Fatal("Unable to generate report", "error", err.Error())
253253
}
254254
fmt.Printf("\n")
255255
}

cmd/aws-sso/list_sso_roles_cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ func (cc *ListSSORolesCmd) Run(ctx *RunContext) error {
4444
tr := []gotable.TableStruct{}
4545

4646
for _, account := range accounts {
47-
log.Debugf("Fetching roles for %s | %s (%s)...", account.AccountName, account.AccountId, account.EmailAddress)
47+
log.Debug("Fetching roles for", "accountName", account.AccountName, "accountID", account.AccountId, "email", account.EmailAddress)
4848
roles, err := AwsSSO.GetRoles(account)
49-
log.Debugf("AWS returned %d roles", len(roles))
49+
log.Debug("AWS returned roles", "count", len(roles))
5050
if err != nil {
5151
return nil
5252
}

cmd/aws-sso/logger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ package main
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
import "github.com/synfinatic/aws-sso-cli/internal/logger"
21+
import "github.com/synfinatic/flexlog"
2222

23-
var log *logger.Logger
23+
var log flexlog.FlexLogger
2424

2525
func init() {
26-
log = logger.GetLogger()
26+
log = flexlog.GetLogger()
2727
}

cmd/aws-sso/login_cmd.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func checkAuth(ctx *RunContext) bool {
4646
if AwsSSO == nil {
4747
s, err := ctx.Settings.GetSelectedSSO(ctx.Cli.SSO)
4848
if err != nil {
49-
log.Fatalf("%s", err.Error())
49+
log.Fatal("unable to select SSO", "sso", ctx.Cli.SSO, err.Error())
5050
}
5151

5252
AwsSSO = sso.NewAWSSSO(s, &ctx.Store)
@@ -59,44 +59,44 @@ func checkAuth(ctx *RunContext) bool {
5959
func doAuth(ctx *RunContext) {
6060
if checkAuth(ctx) {
6161
// nothing to do here
62-
log.Infof("You are already logged in. :)")
62+
log.Info("You are already logged in. :)")
6363
return
6464
}
6565

6666
action, err := url.NewAction(ctx.Cli.Login.UrlAction)
6767
if err != nil {
68-
log.Fatalf("Invalid --url-action %s", ctx.Cli.Login.UrlAction)
68+
log.Fatal("Invalid --url-action", "action", ctx.Cli.Login.UrlAction)
6969
}
7070
if action == "" {
7171
action = ctx.Settings.UrlAction
7272
}
7373
err = AwsSSO.Authenticate(action, ctx.Settings.Browser)
7474
if err != nil {
75-
log.WithError(err).Fatalf("Unable to authenticate")
75+
log.Fatal("Unable to authenticate", "error", err.Error())
7676
}
7777

7878
s, err := ctx.Settings.GetSelectedSSO(ctx.Cli.SSO)
7979
if err != nil {
80-
log.Fatalf("%s", err.Error())
80+
log.Fatal("unable to select SSO", "sso", ctx.Cli.SSO, "error", err.Error())
8181
}
8282

8383
if err = ctx.Settings.Cache.Expired(s); err != nil {
8484
ssoName, err := ctx.Settings.GetSelectedSSOName(ctx.Cli.SSO)
85-
log.Infof("Refreshing AWS SSO role cache for %s, please wait...", ssoName)
8685
if err != nil {
87-
log.Fatalf(err.Error())
86+
log.Fatal("unable to GetSelectedSSOName", "sso", ctx.Cli.SSO, "error", err.Error())
8887
}
88+
log.Info("Refreshing AWS SSO role cache, please wait...", "sso", ssoName)
8989
added, deleted, err := ctx.Settings.Cache.Refresh(AwsSSO, s, ssoName, ctx.Cli.Login.Threads)
9090
if err != nil {
91-
log.WithError(err).Fatalf("Unable to refresh cache")
91+
log.Fatal("Unable to refresh cache", "error", err.Error())
9292
}
9393

9494
if added > 0 || deleted > 0 {
95-
log.Infof("Updated cache: %d added, %d deleted", added, deleted)
95+
log.Info("Updated cache", "added", added, "deletd", deleted)
9696
}
9797

9898
if err = ctx.Settings.Cache.Save(true); err != nil {
99-
log.WithError(err).Errorf("Unable to save cache")
99+
log.Error("Unable to save cache", "error", err.Error())
100100
}
101101
}
102102
}

cmd/aws-sso/logout_cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ func flushSts(ctx *RunContext, awssso *sso.AWSSSO) {
5050
for _, role := range cache.Roles.GetAllRoles() {
5151
if !role.IsExpired() {
5252
if err := ctx.Store.DeleteRoleCredentials(role.Arn); err != nil {
53-
log.WithError(err).Errorf("Unable to delete STS token for %s", role.Arn)
53+
log.Error("Unable to delete STS token", "arn", role.Arn)
5454
}
5555
}
5656
}
5757
if err := ctx.Settings.Cache.MarkRolesExpired(); err != nil {
58-
log.Errorf(err.Error())
58+
log.Error("failed to mark roles expired", "error", err.Error())
5959
} else {
60-
log.Infof("Deleted cached AWS STS credentials for %s", awssso.StoreKey())
60+
log.Info("Deleted cached AWS STS credentials", "sso", awssso.StoreKey())
6161
}
6262
}

0 commit comments

Comments
 (0)