Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --log-level to ecto.migrate and ecto.rollback #543

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/mix/tasks/ecto.migrate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Mix.Tasks.Ecto.Migrate do
quiet: :boolean,
prefix: :string,
pool_size: :integer,
log_level: :string,
log_migrations_sql: :boolean,
log_migrator_sql: :boolean,
strict_version_order: :boolean,
Expand Down Expand Up @@ -77,6 +78,11 @@ defmodule Mix.Tasks.Ecto.Migrate do
* `--log-migrator-sql` - log SQL generated by the migrator, such as
transactions, table locks, etc

* `--log-level` - the level to set for `Logger`. This task does not
start your application, so whatever level you have configured in
your config files will not be used. Defaults to `debug`. Can be
any of the `t:Logger.level/0` levels. *Available since v3.11.0*
whatyouhide marked this conversation as resolved.
Show resolved Hide resolved

* `--migrations-path` - the path to load the migrations from, defaults to
`"priv/repo/migrations"`. This option may be given multiple times in which
case the migrations are loaded from all the given directories and sorted
Expand Down Expand Up @@ -121,6 +127,9 @@ defmodule Mix.Tasks.Ecto.Migrate do
do: Keyword.merge(opts, log: false, log_migrations_sql: false, log_migrator_sql: false),
else: opts

log_level = String.to_existing_atom(Keyword.get(opts, :log_level, "debug"))
Logger.configure(level: log_level)
whatyouhide marked this conversation as resolved.
Show resolved Hide resolved

# Start ecto_sql explicitly before as we don't need
# to restart those apps if migrated.
{:ok, _} = Application.ensure_all_started(:ecto_sql)
Expand Down
9 changes: 9 additions & 0 deletions lib/mix/tasks/ecto.rollback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule Mix.Tasks.Ecto.Rollback do
quiet: :boolean,
prefix: :string,
pool_size: :integer,
log_level: :string,
log_migrations_sql: :boolean,
log_migrator_sql: :boolean,
repo: [:keep, :string],
Expand Down Expand Up @@ -73,6 +74,11 @@ defmodule Mix.Tasks.Ecto.Rollback do
* `--log-migrator-sql` - log SQL generated by the migrator, such as
transactions, table locks, etc

* `--log-level` - the level to set for `Logger`. This task does not
start your application, so whatever level you have configured in
your config files will not be used. Defaults to `debug`. Can be
any of the `t:Logger.level/0` levels. *Available since v3.11.0*

* `--migrations-path` - the path to load the migrations from, defaults to
`"priv/repo/migrations"`. This option may be given multiple times in which
case the migrations are loaded from all the given directories and sorted
Expand Down Expand Up @@ -117,6 +123,9 @@ defmodule Mix.Tasks.Ecto.Rollback do
do: Keyword.merge(opts, log: false, log_migrations_sql: false, log_migrator_sql: false),
else: opts

log_level = String.to_existing_atom(Keyword.get(opts, :log_level, "debug"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do it conditionally, as above, in case the user does call it after their application is started.

Logger.configure(level: log_level)
josevalim marked this conversation as resolved.
Show resolved Hide resolved

# Start ecto_sql explicitly before as we don't need
# to restart those apps if migrated.
{:ok, _} = Application.ensure_all_started(:ecto_sql)
Expand Down