Skip to main content

Application Logging on your way

Development and Debug are two most important phase in Software developers life. Whenever we talk about debugging we come across so many tools, best practices, coding styles etc. Logging is one of the most popular and mandatory concept of debugging the application. I will say that this is one of the most crucial elements for monitoring and analyzing the application. Using proper logging mechanism, we can not only find out the description about errors but also could take certain decisions for improving system performance. It helps in identifying the issue and their cause. Sometimes we can also generate metrics based on current logs to set the target for future road map for the application.

Types of Logging:

Use Log for Debug - To know the issue, for recording request and responses, for knowing system performance and many more. Logs could contain the end to end session for an user. 

Use Log for Knowing Stats - You can log for counting number of visitor came to the site, for voice application, it can be used to know the call details of the user, database hits and/or anything that could be used for audits etc.


Based on my work experience and knowledge I would outline some of the best practices that we should follow for Logging:

#1- Use categories - Use the severity values like INFO, WARN, ERROR, and DEBUG for each message.

#2- Proper Name inclusion - Include the Name of Method,Function,Class etc.

#3- Use Time information - Timing information and context information can be very useful.

#4- Log the messages to some Local Files

#5- Try to log events for all possible resources. For example 
Application logs
DB logs
Any Network logs
All Configuration files details
Performance data details (example - iostat, vmstat, ps, etc.)
Any other time component

#6- Use user friendly messages

#7- Use time-stamps for every log messages

#8- For DB debugging, use some log table to store the activity from DB procedure, functions etc. It will help to determine if everything worked well during DB processing. Some Autonomous function/procedure for logging will also be good to design to have.

#9- Try to log the end to end flow for a request. Try not to log unnecessary stuff, for example some details may be duplicate/redundant.

#10- Do not use sysout for showing messages in console.

#11- You can log messages in XML format as well, but you have take some extra care for this.

#12- Log both errors and behavior of the application.

#13- As it takes too much space, it is advisable to Keep the time limit for storage of Log file in local system.

#14- In case of try-catch, use as follows:
Do not use the following, it is an anti-pattern:
  try {
    toDBOperations();
  } catch (SQLException cnce) {
    log("Exception in toDBOperations()");
  }
Following ussae is good to go:
  try {
    toDBOperations();
  } catch (SQLException cnce) {
    log("Exception in toDBOperations()");
    rollbackDBData();
  }


Hope you enjoyed reading the blog!!!

Comments

Popular posts from this blog

Know your Repository Statistics

Being in software development, everyone of us must be using some or the other repository to save our work( popularly know as check-in check-out :) ). Recently while working on one of my project I thought of finding out the statistics of our project repository for some management reports. While there are so many tools available in the market to explore the stats, I chose to go with Tortoise SVN tool with some plugins. Following are other tools that can be very useful based on scenarios: -Commit Monitor -Winmerge -Visual SVN -SVN Monitor -CM Synergy from Telelogic -Many more are there If you are using Tortoise SVN and want to know the details(for example : no of java classes checked-in, lines of codes written, developers name, total code base details and many more ) about your repository You can use the following steps to find the details: 1-check if the SVN has been installed and working properly or not by using following command: C:\>svn help It will output something ...

Testing your Webservice Applications using SOAP UI

SOAP UI is a standard desktop application for testing the Web Services projects. It provides full support for debugging, developing and testing of your web services applications. The tool support data driven development and also provides platform for creating test suites where you can create services for regression testing. For example if you want to test the complete flow of your SOA application, you can create Test Suites using SOAP UI and can perform end to end testing of your applications. The test suits can be configured to run in multiple environments (dev, sit, uat or production). Okay, let’s start the working on SOAPUI. I will show you the simple webservice testing that I developed in my last blog. Prerequisites: -You have developed your webservices -Webservice is ready and running on your local server -Installed SOAP UI tool Step-1 Download the SOAPUI tool Step-2 Open the soap UI Tool Setp-3 Right click on the project and choose New SOAP Pro...

Web Services for Java Developers

Hello All and Welcome back. Today, we will take some time to discuss on Web services implementations. When ever we hit the Google button to search the Web Services implementation, we find many flavours of web services available on internet. Sometimes it becomes difficult to decide which implementation should we follow. There are bunch of services already present in the market which have gained so much popularity in terms of simplicity and their clear implementation.  To deploy a successful Java based web service project, it needs end to end knowledge of the technology and the artifices that are used behind the scene to make your software run without any heck. When I started working on SOAP based service I had very minimal knowledge on the supporting specification and standards that are required for consume/expose the service. I have worked on both SOAP based Service as well as Restful service.  In my up-coming blogs, I will be posting my understanding on implementati...