How do I get Phoenix or Elixir to print more detailed logs on a crash?

Hi,

I’m attempting to fire up a new Phoenix application in a Docker container, and I’m getting a crash on application start:

palate-web-phoenix-1  | application=phoenix [info] Running PalateWeb.Endpoint with cowboy 2.10.0 at :::8080 (http)
palate-web-phoenix-1  | application=phoenix [info] Access PalateWeb.Endpoint at http://localhost:8080
palate-web-phoenix-1  | [notice] Application palate exited: shutdown
palate-web-phoenix-1  | Kernel pid terminated (application_controller) ({application_terminated,palate,shutdown})
palate-web-phoenix-1  | 
palate-web-phoenix-1  | Crash dump is being written to: erl_crash.dump...
palate-web-phoenix-1  | done
palate-web-phoenix-1 exited with code 1

I’m fine digging into find the problem on my own, but I can’t seem to find how to tell Phoenix/Elixir to print way more detailed logs than the above.

I’ve made the following changes to a completely default Phoenix 1.7.7 application:

diff --git a/README.md b/README.md
index 717ea8e..de82815 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ To start your Phoenix server:
   * Run `mix setup` to install and setup dependencies
   * Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
 
-Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
+Now you can visit [`localhost:8080`](http://localhost:8080) from your browser.
 
 Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
 
diff --git a/config/dev.exs b/config/dev.exs
index 8acfcf2..b110e6d 100644
--- a/config/dev.exs
+++ b/config/dev.exs
@@ -2,13 +2,14 @@ import Config
 
 # Configure your database
 config :palate, Palate.Repo,
-  username: "postgres",
-  password: "postgres",
-  hostname: "localhost",
-  database: "palate_dev",
+  username: System.get_env("DATABASE_USER"),
+  password: System.get_env("DATABASE_PASS"),
+  database: System.get_env("DATABASE_NAME"),
+  hostname: System.get_env("DATABASE_HOST"),
+  pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
+  database_url: System.get_env("DATABASE_URL"),
   stacktrace: true,
-  show_sensitive_data_on_connection_error: true,
-  pool_size: 10
+  show_sensitive_data_on_connection_error: true
 
 # For development, we disable any cache and enable
 # debugging and code reloading.
@@ -17,13 +18,15 @@ config :palate, Palate.Repo,
 # watchers to your application. For example, we can use it
 # to bundle .js and .css sources.
 config :palate, PalateWeb.Endpoint,
-  # Binding to loopback ipv4 address prevents access from other machines.
-  # Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
-  http: [ip: {127, 0, 0, 1}, port: 4000],
+  http: [
+    ip: {0, 0, 0, 0, 0, 0, 0, 0},
+    port: String.to_integer(System.get_env("PORT") || "8080")
+  ],
+  net: [:inet6],
   check_origin: false,
   code_reloader: true,
   debug_errors: true,
-  secret_key_base: "3l+6f8V38k/DXx6oY3PQHqdNy8iybK1YtYHFopJDNEts/ikss/c+54cSRPuGVORz",
+  secret_key_base: System.get_env("SECRET_KEY_BASE"),
   watchers: [
     esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
     tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
@@ -66,7 +69,11 @@ config :palate, PalateWeb.Endpoint,
 config :palate, dev_routes: true
 
 # Do not include metadata nor timestamps in development logs
-config :logger, :console, format: "[$level] $message\n"
+config :logger, :console,
+  format: "$metadata[$level] $message\n",
+  metadata: [:application, :request_id]
+
+config :logger, level: :debug
 
 # Set a higher stacktrace during development. Avoid configuring such
 # in production as building large stacktraces may be expensive.
@@ -77,3 +84,5 @@ config :phoenix, :plug_init_mode, :runtime
 
 # Disable swoosh api client as it is only required for production adapters.
 config :swoosh, :api_client, false
+
+config :plug_cowboy, log_exceptions_with_status_code: [400..599]
diff --git a/config/runtime.exs b/config/runtime.exs
index cb80f04..794dafc 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -49,7 +49,7 @@ if config_env() == :prod do
       """
 
   host = System.get_env("PHX_HOST") || "example.com"
-  port = String.to_integer(System.get_env("PORT") || "4000")
+  port = String.to_integer(System.get_env("PORT") || "8080")
 
   config :palate, PalateWeb.Endpoint,
     url: [host: host, port: 443, scheme: "https"],

I started down the path of erl_crash.dump debugging, but it looks rather intense and I didn’t see an obvious way to just get a stacktrace. Maybe that’s the right path and I paused on it too soon.

What’s the best way to learn more about what’s happening in Phoenix or Elixir that’s causing the crash?

Thanks!

config :logger, 
   handle_otp_reports: true, 
   handle_sasl_reports: true,
   ...
4 Likes

Try reverting all your changes first to see if it’s a setup problem, i.e. start with a plain vanilla Phoenix app. If that works, apply your changes step by step and check at which point the crash occurs – that should let you close in on the culprit.

2 Likes