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...

It's All Mobile

In the digital era, where anything is available on finger tip and we want everything in our pocket, It will not be wrong to say that mobile devices have become our life line. These devices are impacting our lives on a daily basis. Today we have an app(as the modern world calls it) for everything. You name an application, its there on app store/play store. For any company(small or big), having a mobile application can be a smart way to connect with people and get started with their business very quickly.  I can say it has become a must first step for businesses to have mobile presence if they want to reach out to their customers easily and on time. This is high time for them to get their feet wet and jump into this App world. Today's world of technical innovation is taking business owners closer to their customers and giving them opportunity to know the customers need. This can be a good way to understand your customer instead of solving their problem. Demand for mobile software a...