How to add logs in django - django

I am new to django I want to print log information in my console how to do that. and also what is the use of that things in django, why we need that one.

If you want to log stuff to your console, javascript's console.log() would be the way to do that. With Django, print statements will show up in your terminal window where the server is running.

Related

Why I always getting logs Auth::user() on null in my blade template?

I use {{ Auth::user()->name }} on all of my blade templates. It successfully shown the user's name though, but why in my logs it written Auth::user()->name is Trying to get property 'name' of non-object. These logs just make things go crazy.
What am I doing wrong? Thanks for your help!
Your code might fail on below code since you don't have a check here if you are logged in or not!
{{ auth()->user()->name }}
First clear out the log file empty it. Assuming its storage/logs/laravel.log
In terminal use following command to look for the live changes in your log file.
{project_root} > tail -f storage/logs/laravel.log
if above doesn't work use following:
{project_root} > sudo tail -f storage/logs/laravel.log
Now, you can keep taps on the log file if anything is logged in it.
Open your browser and terminal/console side by side and go through your App and look for the trigger point when the Exception is logged and shown on the terminal and start debugging from there.
Did you login your application. when you login then only you can get info from auth.
you don't worry about login sign up process in laravel.
just run php artisan make:auth. laravel scaffolding working for you.
this is simple template. you can customize what ever you want.

Django example for a web app that show git logs

I am looking for an example about how to display git log data about a commit.
I get the commit via shell script; then retrieve the info about this commit and make it pretty. Now I would like to add on a web app in Django, the capability to pass hash and project repo name, so I can display thee info in a nice way.
Altho I can't find tutorial that show how to build a web app for django, that display a page in this way. I just start with the tutorials today, so I don't know much. I also need to read from file, so I don't need a database nor the model, right?
IS this too complicate for a first Django app?

How to set up logging on Django + Heroku?

I know heroku has its own built-in logging system but before heroku, my django already set up a logging system where I saved logs into a different file. And everytime I used the logging module it wouold be saved into that new file.
How do I set this up for heroku? All the "logging.debug(message)" and other logging messages have disappeared. They don't show up on heroku.
EDIT: so far, it looks like I have to stream that logging output to the console for stdout stderr... but it looks like I have to replace logging.debug(message) with ' print "message"'? or there should be another way to output that stream
Sorry for the stupid question due to my lack of understanding of Django logging in the first place.
I just need to redirect my logging "logger" to point its handler to the console rather than the logfile handler that I created.
It was simply a mistake of me rushing through the documentation and not viewing that all outputs were logged.

Running a script through Django admin interface button/url

I am kinda new to python and Django as well so many things still confuse me!I have my Django admin interface with a database on it!
The thing i want to do now is the following:
I want to be able to run a script from my Djano admin interface either by pushing a "Start" button or clicking on a URL!
Thanks for your time,any small example would be so great!
Have a nice day!
I would personally look at something like http://www.celeryproject.org/.
You also need to think about what would happen in the following instances.
Someone else logs into the system and clicks run
Is there any output? How will you handle this?
User clicks refresh whilst waiting for the task to complete.
Will the task complete?
Use Javascript in your template to call the view once a button is clicked, and in your view, call the script. This question's very similar to this one.

django social auth error after completing pipeline

I am using django social auth to power facebook connect in my app (admittedly with a little complicated user model and legacy database).
I was redirected to error page and seem to be running into an error AFTER completion of pipeline( redirect as last step of pipeline still redirects me).
Can someone tell me where to look to debug this?
Thanks,
A good place to start would be to look in social-auth's views.py, at the few places where the redirect to LOGIN_ERROR_URL happens (the variable url is set to LOGIN_ERROR_URL and then HttpResponseRedirect(url) is called). Add some print statements, or better, set breakpoints using the python debugger. If you run your app in the Django development server, the print statements will show up in the terminal in which you ran the server. Otherwise, they may show up in your server logs, depending on your configuration. You may also find django-debug-toolbar helpful.
Using print statements or the debugger, my workflow would be:
Figure out what line in views.py the redirect is triggered from
Figure out what condition causes that line to be reached
Inspect the variables leading to that condition
Sorry this is so general. Happy to help more if you can provide some more specific information.
Aaron