0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Echoで起動時のログを抑止する

0
Posted at

GoのWebフレームワークであるEchoはデフォルトだと起動時にログを出力します。これを出力されないようにします。
デフォルトだと次のようなログが起動時に出力されます。

> go run main.go
{"time":"2026-05-05T19:40:02.443009331+09:00","level":"INFO","msg":"Echo (v5.1.1). High performance, minimalist Go web framework https://echo.labstack.com","version":"5.1.1"}
{"time":"2026-05-05T19:40:02.443027181+09:00","level":"INFO","msg":"http(s) server started","address":"[::]:1323"}

修正内容

StartConfigで出力有無を設定できます。

公式の例に設定を追加してみます。

func main() {
    e := echo.New()

    ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) // start shutdown process on signal
    defer cancel()

    sc := echo.StartConfig{
        Address:         ":1323",
        GracefulTimeout: 5 * time.Second, // defaults to 10 seconds
        HideBanner: true, // 追加 `High performance, minimalist Go web framework` が出力されなくなる
        HidePort: true, // 追加 `http(s) server started`が出力されなくなる
    }
    if err := sc.Start(ctx, e); err != nil {
        e.Logger.Error("failed to start server", "error", err)
    }
}

これで上述のログは2行とも出力されなくなります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?