django - outputting console to log file
NickName:whoisearth Ask DateTime:2015-12-02T10:29:17

django - outputting console to log file

I'm got the following logging config -

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': '/home/svc_itamapi_dev/itam/logs/debug.log',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler'
        },
    },
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['file', 'console'],
            'filters': ['require_debug_true'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
}

When I hit my api I see the following on the console -

[02/Dec/2015 02:27:01] "GET /api/applications/?name=zabbix HTTP/1.1" 200 8232

But it's not generating it in my log file.

Copyright Notice:Content Author:「whoisearth」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34033862/django-outputting-console-to-log-file

Answers
shellbye 2015-12-02T08:05:41

I think you've miss understand the use of django.request. Based on the doc\n\n\n Log messages related to the handling of requests. 5XX responses are raised as ERROR messages; 4XX responses are raised as WARNING messages.\n\n\nI think the django.request only log info when 5XX or 4XX happened.\n\nYou can try http://127.0.0.1:8000/no/where/ to see if the logger worked.",


More about “django - outputting console to log file” related questions

django - outputting console to log file

I'm got the following logging config - LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'level': '

Show Detail

extraArgs outputting to console log with NaN

I'm following a tutorial and the code below is outputting Extra Arg: NaN. I'm not sure why that's the case and I even tried extraArgs[i].toString(). let myFunc = function (name, weather,...

Show Detail

Outputting HDF5 file using Django framework

I'm making a website using the Django framework. I've successfully gotten a web app that takes user data, uses that to make a query, and the outputs a CSV file. However, what I'd really like is to ...

Show Detail

Getting Django to log errors to a file and everything else to the console

Given the following logging config: settings.py LOGGING = { "version": 1, "disable_existing_loggers": False, "filters": { "require_debug_false...

Show Detail

Log all errors to console or file on Django site

How can I get Django 1.0 to write all errors to the console or a log file when running runserver in debug mode? I've tried using a middleware class with process_exception function as described i...

Show Detail

Log all errors to console or file on Django site

How can I get Django 1.0 to write all errors to the console or a log file when running runserver in debug mode? I've tried using a middleware class with process_exception function as described i...

Show Detail

Django HttpResponse result outputting in console but None on site

I got three numbers, that I'm randomly outputting. Django returns me a random number just fine in console but when checking the app through browser, it's returning 'None'. The GET is returning a 200

Show Detail

Django Logging not outputting to log file on nginx server

My Django Logger works fine on my local machine but does not work when I deploy it to the server. Local: OS X 10.9.5, Python 2.7, Django 1.10.5 AWS Server: Ubuntu, Nginx, Gunicorn, Django On my...

Show Detail

Django Structlog is not printing or writing log message to console or file

I have installed django-structlog 1.4.1 for my Django project. I have followed all the steps which has been described in that link. In my settings.py file: import structlog MIDDLEWARE = [ 'd...

Show Detail

Simple log to console in Django 1.7.11

I've been breaking my head over creating a simple logfile within my django application. I've tried applying this question, as well as the examples on the docs, but it simply doesn't seem to work an...

Show Detail