diff --git a/lib/mix/tasks/ecto.migrate.ex b/lib/mix/tasks/ecto.migrate.ex index 898849a8..81f36fd5 100644 --- a/lib/mix/tasks/ecto.migrate.ex +++ b/lib/mix/tasks/ecto.migrate.ex @@ -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, @@ -77,6 +78,12 @@ defmodule Mix.Tasks.Ecto.Migrate do * `--log-migrator-sql` - log SQL generated by the migrator, such as transactions, table locks, etc + * `--log-level` (since v3.11.0) - 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. If this is not provided, no level + will be set, so that if you set it yourself before calling this task + then this won't interfere. Can be any of the `t:Logger.level/0` levels + * `--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 @@ -121,6 +128,10 @@ defmodule Mix.Tasks.Ecto.Migrate do do: Keyword.merge(opts, log: false, log_migrations_sql: false, log_migrator_sql: false), else: opts + if log_level = opts[:log_level] do + Logger.configure(level: String.to_existing_atom(log_level)) + end + # Start ecto_sql explicitly before as we don't need # to restart those apps if migrated. {:ok, _} = Application.ensure_all_started(:ecto_sql) diff --git a/lib/mix/tasks/ecto.rollback.ex b/lib/mix/tasks/ecto.rollback.ex index 41a62406..b0b7749e 100644 --- a/lib/mix/tasks/ecto.rollback.ex +++ b/lib/mix/tasks/ecto.rollback.ex @@ -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], @@ -73,6 +74,12 @@ defmodule Mix.Tasks.Ecto.Rollback do * `--log-migrator-sql` - log SQL generated by the migrator, such as transactions, table locks, etc + * `--log-level` (since v3.11.0) - 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. If this is not provided, no level + will be set, so that if you set it yourself before calling this task + then this won't interfere. Can be any of the `t:Logger.level/0` levels + * `--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 @@ -117,6 +124,10 @@ defmodule Mix.Tasks.Ecto.Rollback do do: Keyword.merge(opts, log: false, log_migrations_sql: false, log_migrator_sql: false), else: opts + if log_level = opts[:log_level] do + Logger.configure(level: String.to_existing_atom(log_level)) + end + # Start ecto_sql explicitly before as we don't need # to restart those apps if migrated. {:ok, _} = Application.ensure_all_started(:ecto_sql)