# Django Logging custom messages!

**URL:** <https://forum.djangoproject.com/t/django-logging-custom-messages/10469>\
**Category:** Using Django\
**Created:** [November 10, 2021, 3:25pm UTC](https://forum.djangoproject.com/t/django-logging-custom-messages/10469 "2021-11-10T15:25:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![goncaloLopesMarques](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goncalolopesmarques/32/4207_2.png) [@goncaloLopesMarques](https://forum.djangoproject.com/u/goncaloLopesMarques)\
**Post date:** [November 10, 2021, 3:25pm UTC](https://forum.djangoproject.com/t/django-logging-custom-messages/10469/1 "2021-11-10T15:25:36Z")

</div>

Hi guys,

Problem: I need to log some actions to a file when they are performed, but only this specific messages and nothing else.

I create the settings to log to a file and it worked, but write my messages and a bunch of trash.

**Settings.py**

```auto
LOGGING = {
    # Define the logging version
    'version': 1,
    # Enable the existing loggers
    'disable_existing_loggers': False,

    # Define the handlers
    'handlers': {
        'file': {
            'class': 'logging.FileHandler',
            'filename': 'djangoapp.log',
        },
        'console': {
            'class': 'logging.StreamHandler',
        },
    },

    # Define the loggers
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'INFO',
            'propagate': False,
        },
    },
}

```

**and in my function a call**

```auto
logger = logging.getLogger('django')
logger.info("Test!!")

```

this solution write the string “Test!!” but write all level info stuff to.  
It is the wrong approach? or something is missing me?

Gonçalo Marques

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 10, 2021, 7:02pm UTC](https://forum.djangoproject.com/t/django-logging-custom-messages/10469/2 "2021-11-10T19:02:08Z")

</div>

Well, it’s _kinda_ the right approach.

Your `getLogger` statement gets an instance of a Logger associated with a name. That name is used to find the appropriate entry in the `loggers` configuration dict.

However, the name you picked happens to be the name that Django itself uses as well.

If you want an isolated log with _just_ _your_ data, change the name of the `loggers` entry in your settings and change your `getLogger` call to get a logger for that name. (Make it unique!) You can then use that `getLogger` call (with that same name) across multiple apps / files to have it all logged to the same destination.

If you’re also going to leave existing loggers active, you might also want to assign a different handler for your custom log. (different log file name, etc)

---

<div class="post-metadata">

**Author:** ![goncaloLopesMarques](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/goncalolopesmarques/32/4207_2.png) [@goncaloLopesMarques](https://forum.djangoproject.com/u/goncaloLopesMarques)\
**Post date:** [November 10, 2021, 9:42pm UTC](https://forum.djangoproject.com/t/django-logging-custom-messages/10469/3 "2021-11-10T21:42:57Z")

</div>

Oohh i thought i wqw close. Thanks you very mutch!!
