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

**URL:** <https://forum.djangoproject.com/t/allow-suppressing-logs-by-emitting-to-logger-logger-instead-of-stdout-directly/20373>\
**Category:** Django Internals\
**Created:** [April 19, 2023, 2:54pm UTC](https://forum.djangoproject.com/t/allow-suppressing-logs-by-emitting-to-logger-logger-instead-of-stdout-directly/20373 "2023-04-19T14:54:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aalekhpatel07](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aalekhpatel07/32/13326_2.png) [@aalekhpatel07](https://forum.djangoproject.com/u/aalekhpatel07)\
**Post date:** [April 19, 2023, 2:54pm UTC](https://forum.djangoproject.com/t/allow-suppressing-logs-by-emitting-to-logger-logger-instead-of-stdout-directly/20373/1 "2023-04-19T14:54:49Z")

</div>

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.

```auto
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:

```python
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](https://github.com/django/django/pull/16782).

---

<div class="post-metadata">

**Author:** ![carltongibson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carltongibson/32/267_2.png) [@carltongibson](https://forum.djangoproject.com/u/carltongibson)\
**Post date:** [April 19, 2023, 3:29pm UTC](https://forum.djangoproject.com/t/allow-suppressing-logs-by-emitting-to-logger-logger-instead-of-stdout-directly/20373/2 "2023-04-19T15:29:31Z")

</div>

Is this [ticket 21429](https://code.djangoproject.com/ticket/21429)? That’s accepted and there’s previous work, so I’d review that to see what needs to be done.

---

<div class="post-metadata">

**Author:** ![aalekhpatel07](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aalekhpatel07/32/13326_2.png) [@aalekhpatel07](https://forum.djangoproject.com/u/aalekhpatel07)\
**Post date:** [April 19, 2023, 3:34pm UTC](https://forum.djangoproject.com/t/allow-suppressing-logs-by-emitting-to-logger-logger-instead-of-stdout-directly/20373/3 "2023-04-19T15:34:25Z")

</div>

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

The [changes](https://github.com/django/django/pull/16782/commits/1c5eb1f7f57f13ed5093021a085eb36a8d08b85c) I’ve proposed essentially replace the explicit `print(...)` call in `django.contrib.auth.management.create_permissions` with `logger.debug(...)`.

---

<div class="post-metadata">

**Author:** ![carltongibson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carltongibson/32/267_2.png) [@carltongibson](https://forum.djangoproject.com/u/carltongibson)\
**Post date:** [April 19, 2023, 3:55pm UTC](https://forum.djangoproject.com/t/allow-suppressing-logs-by-emitting-to-logger-logger-instead-of-stdout-directly/20373/4 "2023-04-19T15:55:19Z")

</div>

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