Skip to content

Commit

Permalink
Add --log-level to ecto.migrate and ecto.rollback (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide authored Jul 27, 2023
1 parent 66e38e9 commit 1b97dfc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 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,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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 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,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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1b97dfc

Please sign in to comment.