Skip to content

Commit

Permalink
Ensure compile_time_application is set for code reloader.
Browse files Browse the repository at this point in the history
This is a bug in Elixir that will be fixed in v1.17+. For now we can
set the logger compile app ourselves before invoking the mix compilers.
  • Loading branch information
chrismccord committed Feb 27, 2024
1 parent 2ae9d98 commit 3c5993e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/phoenix/code_reloader/server.ex
Expand Up @@ -257,7 +257,11 @@ defmodule Phoenix.CodeReloader.Server do
# assets in priv are copied to the build directory.
Mix.Project.build_structure(config)
args = ["--purge-consolidation-path-if-stale", consolidation_path | compile_args]
result = run_compilers(compilers, args, [])

result =
with_logger_app(config, fn ->
run_compilers(compilers, args, [])
end)

cond do
result == :error ->
Expand Down Expand Up @@ -320,4 +324,17 @@ defmodule Phoenix.CodeReloader.Server do
:noop
end
end

# TODO: remove once we depend on Elixir 1.17
defp with_logger_app(config, fun) do
app = Keyword.fetch!(config, :app)
logger_config_app = Application.get_env(:logger, :compile_time_application)

try do
Logger.configure(compile_time_application: app)
fun.()
after
Logger.configure(compile_time_application: logger_config_app)
end
end
end

0 comments on commit 3c5993e

Please sign in to comment.