Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbbbc6b4

Browse files
mirkoCrobumirkoCrobulucarin91
authored
make level log configurable by cli flag
Co-authored-by: mirkoCrobu <mirkocrobu@NB-0531.localdomain>Co-authored-by: Luca Rinaldi <lucarin@protonmail.com>
1 parentd7e520b commitbbbc6b4

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

‎cmd/arduino-app-cli/app/restart.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package app
22

33
import (
4-
"fmt"
5-
64
"github.com/spf13/cobra"
75

86
"github.com/arduino/arduino-app-cli/cmd/arduino-app-cli/completion"
@@ -25,7 +23,7 @@ func newRestartCmd(cfg config.Configuration) *cobra.Command {
2523
returnnil
2624
}
2725
iferr:=stopHandler(cmd.Context(),app);err!=nil {
28-
feedback.Warning(fmt.Sprintf("failed to stop app: %s",err.Error()))
26+
feedback.Warnf("failed to stop app: %s",err.Error())
2927
}
3028
returnstartHandler(cmd.Context(),cfg,app)
3129
},

‎cmd/arduino-app-cli/main.go‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"cmp"
54
"context"
65
"fmt"
76
"log/slog"
@@ -28,17 +27,11 @@ import (
2827
// Version will be set a build time with -ldflags
2928
varVersionstring="0.0.0-dev"
3029
varformatstring
30+
varlogLevelStrstring
3131

3232
funcrun(configuration cfg.Configuration)error {
3333
servicelocator.Init(configuration)
3434
deferfunc() {_=servicelocator.CloseDockerClient() }()
35-
36-
logLevel,err:=ParseLogLevel(cmp.Or(os.Getenv("ARDUINO_APP_CLI__LOG_LEVEL"),"INFO"))
37-
iferr!=nil {
38-
returnerr
39-
}
40-
slog.SetLogLoggerLevel(logLevel)
41-
4235
rootCmd:=&cobra.Command{
4336
Use:"arduino-app-cli",
4437
Short:"A CLI to manage the Python app",
@@ -47,13 +40,18 @@ func run(configuration cfg.Configuration) error {
4740
if!ok {
4841
feedback.Fatal(i18n.Tr("Invalid output format: %s",format),feedback.ErrBadArgument)
4942
}
50-
feedback.SetFormat(format)
43+
logLevel,err:=ParseLogLevel(logLevelStr)
44+
iferr!=nil {
45+
feedback.FatalError(err,feedback.ErrBadArgument)
46+
}
47+
slog.SetLogLoggerLevel(logLevel)
5148
},
5249
SilenceUsage:true,
5350
SilenceErrors:true,
5451
}
5552

5653
rootCmd.PersistentFlags().StringVar(&format,"format","text","Output format (text, json)")
54+
rootCmd.PersistentFlags().StringVar(&logLevelStr,"log-level","error","Set the log level (debug, info, warn, error)")
5755

5856
rootCmd.AddCommand(
5957
app.NewAppCmd(configuration),

‎cmd/feedback/feedback.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"log/slog"
89
"os"
910

1011
"github.com/arduino/arduino-app-cli/cmd/i18n"
11-
12-
"github.com/sirupsen/logrus"
1312
)
1413

1514
// OutputFormat is an output format
@@ -140,13 +139,14 @@ func Print(v string) {
140139
}
141140

142141
// Warning outputs a warning message.
143-
funcWarning(msgstring) {
142+
funcWarnf(msgstring,args...interface{}) {
143+
msg=fmt.Sprintf(msg,args...)
144144
ifformat==Text {
145145
fmt.Fprintln(feedbackErr,msg)
146146
}else {
147147
bufferWarnings=append(bufferWarnings,msg)
148148
}
149-
logrus.Warning(msg)
149+
slog.Warn(msg)
150150
}
151151

152152
// FatalError outputs the error and exits with status exitCode.

‎debian/arduino-app-cli/etc/systemd/system/arduino-app-cli.service‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ Wants=network-online.target docker.service arduino-router.service
55
Requires=docker.service arduino-router.service
66

77
[Service]
8-
ExecStart=/usr/bin/arduino-app-cli daemon --port 8800
8+
ExecStart=/usr/bin/arduino-app-cli daemon --port 8800 --log-level error
99
User=arduino
1010
Group=arduino
11-
Environment="ARDUINO_APP_CLI__LOG_LEVEL=ERROR"
1211
Environment="ARDUINO_ROUTER_SOCKET=/var/run/arduino-router.sock"
1312
StandardOutput=journal
1413
StandardError=journal

‎internal/orchestrator/system.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func pullImage(ctx context.Context, stdout io.Writer, docker dockerClient.APICli
8080
returnallErr// Non-retryable error
8181
}
8282

83-
feedback.Printf("Warning:received 'toomanyrequests' error from Docker registry, retrying in %s ...",delay)
83+
feedback.Warnf("received 'toomanyrequests' error from Docker registry, retrying in %s ...",delay)
8484

8585
select {
8686
case<-ctx.Done():
@@ -217,19 +217,19 @@ func SystemCleanup(ctx context.Context, cfg config.Configuration, staticStore *s
217217
// Remove running app and dangling containers
218218
runningApp,err:=getRunningApp(ctx,docker.Client())
219219
iferr!=nil {
220-
feedback.Printf("Warning:failed to get running app - %v",err)
220+
feedback.Warnf("failed to get running app - %v",err)
221221
}
222222
ifrunningApp!=nil {
223223
foritem:=rangeStopAndDestroyApp(ctx,*runningApp) {
224224
ifitem.GetType()==ErrorType {
225-
feedback.Printf("Warning:failed to stop and destroy running app - %v",item.GetError())
225+
feedback.Warnf("failed to stop and destroy running app - %v",item.GetError())
226226
break
227227
}
228228
}
229229
result.RunningAppRemoved=true
230230
}
231231
ifcount,err:=removeDanglingContainers(ctx,docker.Client());err!=nil {
232-
feedback.Printf("Warning:failed to remove dangling containers - %v",err)
232+
feedback.Warnf("failed to remove dangling containers - %v",err)
233233
}else {
234234
result.ContainersRemoved=count
235235
}
@@ -250,7 +250,7 @@ func SystemCleanup(ctx context.Context, cfg config.Configuration, staticStore *s
250250
for_,image:=rangeimagesToRemove {
251251
imageSize,err:=removeImage(ctx,docker.Client(),image)
252252
iferr!=nil {
253-
feedback.Printf("Warning:failed to remove image %s - %v",image,err)
253+
feedback.Warnf("failed to remove image %s - %v",image,err)
254254
continue
255255
}
256256
result.SpaceFreed+=imageSize
@@ -263,7 +263,7 @@ func SystemCleanup(ctx context.Context, cfg config.Configuration, staticStore *s
263263
funcremoveImage(ctx context.Context,docker dockerClient.APIClient,imageNamestring) (int64,error) {
264264
varsizeint64
265265
ifinfo,err:=docker.ImageInspect(ctx,imageName);err!=nil {
266-
feedback.Printf("Warning:failed to inspect image %s - %v",imageName,err)
266+
feedback.Warnf("failed to inspect image %s - %v",imageName,err)
267267
}else {
268268
size=info.Size
269269
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp