h3h

h3h

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!

Marked As Solved

cmo

cmo

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

Also Liked

frerich

frerich

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.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement