Add env var for debug logs (#2292)

This commit is contained in:
Jonatan Kłosko 2023-10-23 20:01:05 +02:00 committed by GitHub
parent 93637b60f0
commit d2e875a94f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -224,6 +224,9 @@ The following environment variables can be used to configure Livebook on boot:
configuration. Defaults to "livebook" under the default user data
directory.
* LIVEBOOK_DEBUG - enables verbose logging, when set to "true". Disabled
by default.
* LIVEBOOK_DEFAULT_RUNTIME - sets the runtime type that is used by default
when none is started explicitly for the given notebook. Must be either
"standalone" (Elixir standalone), "attached:NODE:COOKIE" (Attached node)

View file

@ -91,6 +91,10 @@ defmodule Livebook do
Livebook.Config.secret!("LIVEBOOK_SECRET_KEY_BASE") ||
Base.encode64(:crypto.strong_rand_bytes(48))
if Livebook.Config.debug!("LIVEBOOK_DEBUG") do
config :logger, level: :debug
end
if port = Livebook.Config.port!("LIVEBOOK_PORT") do
config :livebook, LivebookWeb.Endpoint, http: [port: port]
end

View file

@ -420,6 +420,19 @@ defmodule Livebook.Config do
end
end
@doc """
Parses and validates debug mode from env.
"""
def debug!(env) do
if debug = System.get_env(env) do
cond do
debug in ["1", "true"] -> true
debug in ["0", "false"] -> false
true -> abort!("expected #{env} to be a boolean, got: #{inspect(debug)}")
end
end
end
@doc """
Parses and validates the port from env.
"""