Most common tool to follow the logs of the application is tail at least under unix, linux and probably mac osx operating systems. So we just need to open a console and type tail -f path/app.log. Fairly simple but it would be nice to have it inside eclipse, which turns out to be also very simple to configure it with the external tools of eclipse.
Open External Tools Configurations:
External tool configuration
Hit Run and that’s it. Windows users should install a tail for windows first!
Coming from a Java world where projects and libraries without logging are unheard, it was a big surprise to see that all django apps that I have downloaded so far do not include logging, even though Python has a very good support for logging, it was inspired by the log4j. For a reason that I do not know they choose not to log, I suppose it is a kind of situation where everyone else knows but me!
So as a java developer used to work with a lot of logging I decided to put in place a logging mechanism for my django project and fortunately python has great support for that:
1. create a logging.conf file for the logging options
2. configuring the logging module
3. using the logger in my modules
So here is my simple set up:
1. create a logging.conf file for the logging options with the following content:
args=('logs/core_logger.log', 'a', 1000000, 4)
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
2. configuring the logging module in the settings.py
LOGGING_CONFIG = 'logging.conf' # logging configuration file
3.use the logger in your modules
logger = logging.getLogger('core_view_logger');
logger.debug('This is a debug message')
logger.info('This is an info message')
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.critical('Yes it is so simple :)')
That’s all folks!
But of course this is a simple set up and you can do more much more:
- Logging to multiple destinations
- Adding contextual information to the output
- Send and receive logging information across network
- Send logging information through email
Check the python official documentation for all the options http://docs.python.org/library/logging.html