<tbody id="bov9t"></tbody>
<bdo id="bov9t"></bdo>
<track id="bov9t"></track>
  • <menuitem id="bov9t"><dfn id="bov9t"></dfn></menuitem>

    <track id="bov9t"></track>

    Support Logging setup

    Django Logging

    Django Logging

    You can send Django logs to Loggly over syslog. This will send them from Django to a local rsyslog daemon which will forward them to Loggly. It assumes you use rsyslog 1.19 or higher in the standard directory, TCP over port 514, and you have sudo permissions. For alternatives, please see the Advanced Options section below.

    Django Logging Setup

    1. Configure syslog daemon

    Run our automatic configure-linux script below to setup logging and send the Django logs to Loggly through your syslog daemon.

    curl -O http://www.erzf7.cn/install/configure-linux.sh
    sudo bash configure-linux.sh -a SUBDOMAIN -u USERNAME


    • SUBDOMAIN: your account subdomain that you created when you signed up for Loggly
    • USERNAME: your Loggly username

    2. Configure rsyslog to forward Django logs to Loggly

    Open your Django configuration file for rsyslog or create a new one:

    sudo vim /etc/rsyslog.d/21-django.conf

    Paste this configuration into the file then save it.

    #provides UDP syslog reception
    $ModLoad imudp
    $UDPServerRun 514
    #Add a tag for Django events
    $template LogglyFormatDjango,"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [TOKEN@41058 tag=\"Django\"] %msg%\n"
    local7.* @@logs-01.loggly.com:514;LogglyFormatDjango
    local7.* ~ #discards the messages so they don't end up in /var/log/syslog


    Then restart rsyslog so the changes take effect

    sudo service rsyslog restart

    3. Configure Django to send logs

    Open settings.py file of your application.

    vim settings.py

    Copy the following code in the file to configure your Django application to send logs to Loggly

    LOGGING = {
       'version': 1,
       'disable_existing_loggers': False,
       'formatters': {
          'django': { 
             'format':'django: %(message)s',
       'handlers': {
          'logging.handlers.SysLogHandler': {
             'level': 'DEBUG',
             'class': 'logging.handlers.SysLogHandler',
             'facility': 'local7',
             'formatter': 'django',
             'address' : '/dev/log',
       'loggers': {
             'handlers': ['logging.handlers.SysLogHandler'],
             'propagate': True,
             'format':'django: %(message)s',
             'level': 'DEBUG',

    4. Send A Test Event

    Now call the defined logger in the Django files. In our case it is loggly_logs. Run your application with this code to send a test event to Loggly.

    import logging
    logger = logging.getLogger('loggly_logs')
    logger.info('Hi, Welcome to Loggly.')

    5. Verify Events

    Search Loggly for events with the?logtype as django over the past 20 minutes. It may take few minutes to index the event. If it doesn’t work, see the Django Logging Troubleshooting section below.

    Django Example


    Advanced Django Logs Options

    Django Logging Troubleshooting

    If you don’t see any data show up in the verification step, then check for these common problems.

    • Wait a few minutes in case indexing needs to catch up
    • Check if you are using the same logger name as mentioned in the settings.py file.
    • Troubleshooting Rsyslog
    • Search or post your own questions around Django logging, Python logging, Django error logs, plus logging messages and default and custom logging configuration in the community forum.
    Thanks for the feedback! We'll use it to improve our support documentation.