Locate the error
Introduction
In open edx it is very difficult to identify the error sometimes. Different types of error could occur these could be syntax error, logical or runtime error, So for a developer it is difficult to locate and identify the error. To locate and discover the error in a server we use loggers and logs and how they work is defined as below.
Using Logs
In edx we use logs to provides a detailed, typically time-based record that serves both as verification that a set of commands were executed, and provides information relating to the success of those commands. Logs also provides details for the errors, exceptions and other type of things that interrupts execution of a command.
In Open edx we use the below command to check the logs.
sudo tail -f /edx/var/log/{lms,cms,edx,supervisor,nginx}/*log
The above command will show you the logs related to lms,cms,edx,supervisor and nginx as well.
Using Loggers
When something goes wrong inside an open edx, it becomes easier to debug if we know the source of the error. When an exception is raised, we can log the required information to track down the issue. Python provides a simple and powerful logging library.
Lets see how we can use loggers.
import logging
def function(request):
if(name in request.POST):
logging.info("name exist")
#do something
else:
logging.info("name doesnot exit")
#do something else
Now when you will check the logs either one of the above condition will be executed and due to the use of logging.info you will know which of the above condition was executed.