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 all commits
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
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