Skip to content

Commit

Permalink
Update startup message formatting (#2847)
Browse files Browse the repository at this point in the history
* Update listen.go (unform INFO prints at startip + cosmetics)

BEFORE:
```
    _______ __             
   / ____(_) /_  ___  _____
  / /_  / / __ \/ _ \/ ___/
 / __/ / / /_/ /  __/ /    
/_/   /_/_.___/\___/_/     v3.0.0-beta.1
--------------------------------------------------
INFO Server started on http://127.0.0.1:8003 (bound on host 0.0.0.0 and port 8003)
INFO Application name: TEST APP
INFO Total handlers count: 5
INFO Prefork: Disabled
INFO PID: 2342
INFO Total process count: 1
20:49:50 | 200 |     593.769µs |   123.123.123.123 | GET     | / 
```

AFTER:
```
    _______ __             
   / ____(_) /_  ___  _____
  / /_  / / __ \/ _ \/ ___/
 / __/ / / /_/ /  __/ /    
/_/   /_/_.___/\___/_/     v3.0.0-beta.1
--------------------------------------------------
INFO Server started on:      http://127.0.0.1:8003 (bound on host 0.0.0.0 and port 8003)
INFO Application name:       TEST APP
INFO Total handlers count:   5
INFO Prefork:                Disabled
INFO PID:                    2342
INFO Total process count:    1

20:49:50 | 200 |     593.769µs |   123.123.123.123 | GET     | /
```

* fix spacer

* fix indentation for fiber version

* fix linting

* fix linting #2

* fix listen_test.go to match newly expected output.

* fix test again

---------

Co-authored-by: root <root@clicon.hosting-hotmann.de>
Co-authored-by: Martin <martin@hotmann.de>
  • Loading branch information
3 people committed Feb 10, 2024
1 parent 389e63d commit 573afb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var figletFiberText = `
/ ____(_) /_ ___ _____
/ /_ / / __ \/ _ \/ ___/
/ __/ / / /_/ / __/ /
/_/ /_/_.___/\___/_/ %s`
/_/ /_/_.___/\___/_/ %s`

const (
globalIpv4Addr = "0.0.0.0"
Expand Down Expand Up @@ -354,27 +354,27 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC

if host == "0.0.0.0" {
_, _ = fmt.Fprintf(out,
"%sINFO%s Server started on %s%s://127.0.0.1:%s%s (bound on host 0.0.0.0 and port %s)\n",
"%sINFO%s Server started on: \t%s%s://127.0.0.1:%s%s (bound on host 0.0.0.0 and port %s)\n",
colors.Green, colors.Reset, colors.Blue, scheme, port, colors.Reset, port)
} else {
_, _ = fmt.Fprintf(out,
"%sINFO%s Server started on %s%s%s\n",
"%sINFO%s Server started on: \t%s%s%s\n",
colors.Green, colors.Reset, colors.Blue, fmt.Sprintf("%s://%s:%s", scheme, host, port), colors.Reset)
}

if app.config.AppName != "" {
_, _ = fmt.Fprintf(out, "%sINFO%s Application name: %s%s%s\n", colors.Green, colors.Reset, colors.Blue, app.config.AppName, colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s Application name: \t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, app.config.AppName, colors.Reset)
}
_, _ = fmt.Fprintf(out,
"%sINFO%s Total handlers count: %s%s%s\n",
"%sINFO%s Total handlers count: \t%s%s%s\n",
colors.Green, colors.Reset, colors.Blue, strconv.Itoa(int(app.handlersCount)), colors.Reset)
if isPrefork == "Enabled" {
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: %s%s%s\n", colors.Green, colors.Reset, colors.Blue, isPrefork, colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, isPrefork, colors.Reset)
} else {
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: %s%s%s\n", colors.Green, colors.Reset, colors.Red, isPrefork, colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s Prefork: \t\t\t%s%s%s\n", colors.Green, colors.Reset, colors.Red, isPrefork, colors.Reset)
}
_, _ = fmt.Fprintf(out, "%sINFO%s PID: %s%v%s\n", colors.Green, colors.Reset, colors.Blue, os.Getpid(), colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s Total process count: %s%s%s\n", colors.Green, colors.Reset, colors.Blue, procs, colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s PID: \t\t\t%s%v%s\n", colors.Green, colors.Reset, colors.Blue, os.Getpid(), colors.Reset)
_, _ = fmt.Fprintf(out, "%sINFO%s Total process count: \t%s%s%s\n", colors.Green, colors.Reset, colors.Blue, procs, colors.Reset)

if cfg.EnablePrefork {
// Turn the `pids` variable (in the form ",a,b,c,d,e,f,etc") into a slice of PIDs
Expand All @@ -385,7 +385,7 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
}
}

_, _ = fmt.Fprintf(out, "%sINFO%s Child PIDs: %s", colors.Green, colors.Reset, colors.Blue)
_, _ = fmt.Fprintf(out, "%sINFO%s Child PIDs: \t\t%s", colors.Green, colors.Reset, colors.Blue)
totalPids := len(pidSlice)
rowTotalPidCount := 10
for i := 0; i < totalPids; i += rowTotalPidCount {
Expand All @@ -403,6 +403,9 @@ func (app *App) startupMessage(addr string, isTLS bool, pids string, cfg ListenC
_, _ = fmt.Fprintf(out, "\n%s", colors.Reset)
}
}

// add new Line as spacer
_, _ = fmt.Fprintf(out, "\n%s", colors.Reset)
}

// printRoutesMessage print all routes with method, path, name and handlers
Expand Down
4 changes: 2 additions & 2 deletions listen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func Test_Listen_Master_Process_Show_Startup_Message(t *testing.T) {
require.Contains(t, startupMessage, "(bound on host 0.0.0.0 and port 3000)")
require.Contains(t, startupMessage, "Child PIDs")
require.Contains(t, startupMessage, "11111, 22222, 33333, 44444, 55555, 60000")
require.Contains(t, startupMessage, fmt.Sprintf("Prefork: %sEnabled%s", colors.Blue, colors.Reset))
require.Contains(t, startupMessage, fmt.Sprintf("Prefork: \t\t\t%sEnabled%s", colors.Blue, colors.Reset))
}

// go test -run Test_Listen_Master_Process_Show_Startup_MessageWithAppName
Expand Down Expand Up @@ -402,7 +402,7 @@ func Test_Listen_Master_Process_Show_Startup_MessageWithDisabledPreforkAndCustom
require.Contains(t, startupMessage, fmt.Sprintf("%sINFO%s", colors.Green, colors.Reset))
require.Contains(t, startupMessage, fmt.Sprintf("%s%s%s", colors.Blue, appName, colors.Reset))
require.Contains(t, startupMessage, fmt.Sprintf("%s%s%s", colors.Blue, "https://server.com:8081", colors.Reset))
require.Contains(t, startupMessage, fmt.Sprintf("Prefork: %sDisabled%s", colors.Red, colors.Reset))
require.Contains(t, startupMessage, fmt.Sprintf("Prefork: \t\t\t%sDisabled%s", colors.Red, colors.Reset))
}

// go test -run Test_Listen_Print_Route
Expand Down

0 comments on commit 573afb9

Please sign in to comment.