Allow suppressing logs by emitting to `logger.Logger` instead of stdout directly.

I’ve noticed that django.contrib.auth’s management.create_permissions is too noisy on stdout without allowing any way to suppress it at runtime.

Loading environment 'development'
...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying app.0001_initial... OK
  ...
  Applying app.0002_enable_user_permissions... OK
Adding content type 'app | user'
Adding content type 'app | foo'
Adding content type 'app | bar'
...
Adding permission 'app | user | Can add user'
Adding permission 'app | user | Can change user'
... // More logs of the same format.

I’m not sure if this is the intended behaviour (and please correct me if it is), but I’d imagine emitting to a logging.Logger instead would allow them to be suppressed with a custom logging configuration such as the following:

logging.config.dictConfig({
    ...,
    'loggers': {
        ...,
        'django.contrib.auth': {
            'level': 'ERROR',
            'handlers': ['console']
        }

    }
})

I was advised to bring this up here and garner any feedback/concerns about landing django#16782.

Is this ticket 21429? That’s accepted and there’s previous work, so I’d review that to see what needs to be done.

I’m not too sure if there’s sufficient overlap between these tickets to identify them as one.

The changes I’ve proposed essentially replace the explicit print(...) call in django.contrib.auth.management.create_permissions with logger.debug(...).

I think you’ll need to tie into the existing output methods for management commands…