Skip to content

Commit 5ec5de5

Browse files
committed
Add --level to 'encore run', tweak log levels
1 parent 888f65e commit 5ec5de5

File tree

15 files changed

+58
-17
lines changed

15 files changed

+58
-17
lines changed

cli/cmd/encore/run.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ var (
3232
}
3333
watch bool
3434
listen string
35+
logLevel = cmdutil.Oneof{
36+
Value: "",
37+
Allowed: []string{"trace", "debug", "info", "warn", "error"},
38+
Flag: "level",
39+
FlagShort: "l",
40+
Desc: "Minimum log level to display",
41+
TypeDesc: "string",
42+
}
3543
port uint
3644
jsonLogs bool
3745
browser = cmdutil.Oneof{
@@ -46,7 +54,7 @@ var (
4654

4755
func init() {
4856
runCmd := &cobra.Command{
49-
Use: "run [--debug] [--watch=true] [--port=4000] [--listen=<listen-addr>]",
57+
Use: "run [--debug] [--watch=true] [--level=TRACE] [--port=4000] [--listen=<listen-addr>]",
5058
Short: "Runs your application",
5159
Args: cobra.NoArgs,
5260
Run: func(cmd *cobra.Command, args []string) {
@@ -71,6 +79,7 @@ func init() {
7179
runCmd.Flags().BoolVar(&color, "color", isTerm, "Whether to display colorized output")
7280
runCmd.Flags().BoolVar(&noColor, "no-color", false, "Equivalent to --color=false")
7381
runCmd.Flags().MarkHidden("no-color")
82+
logLevel.AddFlag(runCmd)
7483
debug.AddFlag(runCmd)
7584
browser.AddFlag(runCmd)
7685
}
@@ -124,6 +133,7 @@ func runApp(appRoot, wd string) {
124133
TraceFile: root.TraceFile,
125134
Namespace: nonZeroPtr(nsName),
126135
Browser: browserMode,
136+
LogLevel: nonZeroPtr(logLevel.Value),
127137
})
128138
if err != nil {
129139
fatal(err)

cli/daemon/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"encr.dev/internal/userconfig"
1818
"encr.dev/internal/version"
1919
"encr.dev/pkg/fns"
20+
"encr.dev/pkg/option"
2021
daemonpb "encr.dev/proto/encore/daemon"
2122
)
2223

@@ -147,6 +148,7 @@ func (s *Server) Run(req *daemonpb.RunRequest, stream daemonpb.Daemon_RunServer)
147148
OpsTracker: ops,
148149
Browser: browser,
149150
Debug: run.DebugModeFromProto(req.DebugMode),
151+
LogLevel: option.FromPointer(req.LogLevel),
150152
})
151153
if err != nil {
152154
s.mu.Unlock()

cli/daemon/run/run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ type StartParams struct {
101101

102102
// Debug specifies to compile the application for debugging.
103103
Debug builder.DebugMode
104+
105+
// LogLevel overrides the default log level for the run.
106+
LogLevel option.Option[string]
104107
}
105108

106109
// BrowserMode specifies how to open the browser when starting 'encore run'.
@@ -582,6 +585,7 @@ func (r *Run) StartProcGroup(params *StartProcGroupParams) (p *ProcGroup, err er
582585
IncludeMeta: r.Builder.NeedsMeta(),
583586
MetaPath: metaPath,
584587
RuntimeConfigPath: runtimeConfigPath,
588+
LogLevel: r.Params.LogLevel,
585589
},
586590
Experiments: params.Experiments,
587591
Meta: params.Meta,

cli/daemon/run/runtime_config2.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ type RuntimeConfigGenerator struct {
8787
// instead of including it as an environment variable.
8888
RuntimeConfigPath option.Option[string]
8989

90+
// Minimum log level, if any.
91+
LogLevel option.Option[string]
92+
9093
// The values of defined secrets.
9194
DefinedSecrets map[string]string
9295
// The configs, per service.
@@ -153,10 +156,16 @@ func (g *RuntimeConfigGenerator) initialize() error {
153156
if err != nil {
154157
return errors.Wrap(err, "failed to get app's build settings")
155158
}
159+
160+
logLevel := appFile.LogLevel
161+
if level, ok := g.LogLevel.Get(); ok {
162+
logLevel = level
163+
}
164+
156165
for _, svc := range g.md.Svcs {
157166
cfg := &runtimev1.HostedService{
158167
Name: svc.Name,
159-
LogConfig: ptrOrNil(appFile.LogLevel),
168+
LogConfig: ptrOrNil(logLevel),
160169
}
161170

162171
if appFile.Build.WorkerPooling {

docs/go/how-to/debug.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $ encore run --debug
7878
API Base URL: http://localhost:4000
7979
Dev Dashboard URL: http://localhost:9400/hello-world-cgu2
8080
Process ID: 51894
81-
1:48PM INF registered endpoint path=/hello/:name service=hello endpoint=Hello
81+
1:48PM TRC registered endpoint path=/hello/:name service=hello endpoint=Hello
8282
```
8383

8484
(Your process id will differ).
@@ -115,4 +115,3 @@ it has completed, click `Run | Attach to Process` again. In the dialog that appe
115115
process ID from above.
116116

117117
That's it. You should be able to set breakpoints and have the Encore application pause when they’re hit like you would expect.
118-

docs/go/quick-start.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ The output where you're running your app will look something like this:
191191
```output
192192
Changes detected, recompiling...
193193
Reloaded successfully.
194-
INF registered endpoint endpoint=World path=/hello/:name service=hello
195-
INF listening for incoming HTTP requests
194+
TRC registered endpoint endpoint=World path=/hello/:name service=hello
195+
TRC listening for incoming HTTP requests
196196
```
197197

198198
🥐 Test your change by calling your API again.

docs/go/tutorials/rest-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ You should see this:
8585
```output
8686
Your API is running at: http://localhost:4000
8787
Development Dashboard URL: http://localhost:9400
88-
4:19PM INF registered endpoint path=/url service=url endpoint=Shorten
88+
4:19PM TRC registered endpoint path=/url service=url endpoint=Shorten
8989
```
9090

9191
🥐 Next, call your endpoint from the Local Development Dashboard at [http://localhost:9400](http://localhost:9400) and view a trace of the response.

docs/ts/quick-start.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ The output where you're running your app will look something like this:
191191
```output
192192
Changes detected, recompiling...
193193
Reloaded successfully.
194-
INF registered endpoint endpoint=World path=/hello/:name service=hello
195-
INF listening for incoming HTTP requests
194+
TRC registered endpoint endpoint=World path=/hello/:name service=hello
195+
TRC listening for incoming HTTP requests
196196
```
197197

198198
🥐 Test your change by calling your API again.

e2e-tests/app_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func RunApp(c testing.TB, appRoot string, logger RunLogger, env []string) *RunAp
8888
ResourceManager: rm,
8989
Mgr: mgr,
9090
Builder: bld,
91+
Params: &StartParams{},
9192
}
9293

9394
parse, build, configs := testBuild(c, appRoot, env)

e2e-tests/echo_app_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ func TestProcClosedOnCtxCancel(t *testing.T) {
591591
ListenAddr: "127.0.0.1:34212",
592592
SvcProxy: svcProxy,
593593
Builder: v2builder.New(),
594+
Params: &StartParams{},
594595
}
595596

596597
parse, build, _ := testBuild(c, appRoot, append(os.Environ(), "ENCORE_EXPERIMENT=v2"))

0 commit comments

Comments
 (0)