Thursday, September 4, 2008

Logging using Spring Framework

Step 1:

It is simple. Just add log4j dependencies in maven pom.xml.

<dependency>

<groupId>log4j <groupId>

<artifactId>log4j<artifactId>

<version>1.2.9 <version>

<dependency>


If you are using common logging, add following dependency

<dependency>

<groupId>commons-logging <groupId>

<artifactId>commons-logging<artifactId>

<version>1.1.1<version>

<dependency>


Step 2 :


Create a log4j.properties or xml as per your requirement.

Here is sample log4j.properties


# following line defines the log level and mode of outputs. Console and rolling file

log4j.rootLogger= INFO, CONSOLE, ROLLING

log4j.logger.com= INFO, CONSOLE, ROLLING, DAILY

# Print only messages of level WARN or above in the package org.apache.

log4j.logger.org.apache=WARN

# Print only messages of level WARN or above in the package org.springframework.

log4j.logger.org.springframework=WARN

# CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender

log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p [YOURPROJECTNAME] [%t] %C{2} (%F:%L) - %m%n

# ROLLING

log4j.appender.ROLLING=org.apache.log4j.RollingFileAppender

log4j.appender.ROLLING.File=yourprojectname.log

log4j.appender.ROLLING.layout=org.apache.log4j.PatternLayout

log4j.appender.ROLLING.layout.ConversionPattern=%d %-5p [YOURPROJECTNAME] [%t] %C{2} (%F:%L) - %m%n

log4j.appender.ROLLING.MaxFileSize=10MB

log4j.appender.ROLLING.MaxBackupIndex=5

# DAILY

log4j.appender.DAILY=org.apache.log4j.DailyRollingFileAppender

log4j.appender.DAILY.layout=org.apache.log4j.PatternLayout

log4j.appender.DAILY.layout.ConversionPattern=%d %-5p [YOURPROJECTNAME] [%t] %C{2} (%F:%L) - %m%n

log4j.appender.DAILY.File=yourprojectnamedaily.log

log4j.appender.DAILY.DatePattern=yyyy-MM-dd


Step 3.


Add following line in application-context.xml

<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />

<property name="targetMethod" value="initLogging" />

<property name="arguments">

<list>

<value>classpath:log4j.properties<value>

<list>

<property>

<bean>


That’s it. You are done!!!

******************************************************************************


Change Log level without re-starting server –

If it is required that you have to change log level frequently, it would be

frustrating to restart the server every time. To avoid restarting application

server whenever you modify log4j.properties file.

Simply add one line of configuration in application-context.xml that is –


<value type="long">enter time here<value>


*Time is in millisecond.


So the configuration will look like as follows.


<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">

<property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>

<property name="targetMethod" value="initLogging" />

<property name="arguments">

<list>

<value>classpath:log4j.properties<value>

<value type="long">10000000<value>

<list>

<property>

<bean>


But you should not use above configuration in production server. Please visit the

following link for more information

http://static.springframework.org/spring/docs/1.1.5/api/org/springframework/util/Log4jConfigurer.html#initLogging(java.lang.String,%20long)


Code Assistance Tip:


Here are one useful tip if you are using Eclipse

1.1. Go to window->Perspective->Java->Editor->Templates

1.2. Create new.

1.3. Give following parameters.

Name – yourprojectnameLog

Description - it will create a logger instance for enclosing class of the project.

Pattern :

If you are using common logging then use

private static final Log logger=LogFactory.getLog(${primary_type_name}.class);

If you are using log4j then use

private static final Logger logger=Logger.getLogger(${enclosing_type}.class.getName());


To use it in java classes, simply press ‘yourproje’ and click ctrl+space and select

yourprojectnameLog.

Wednesday, June 4, 2008

A yogic way to wash your eyes

1. Fill your mouth with warm or hot water.
2. Take a deep breath.
3. Wash your eyes with fresh running water (should not be very cold or very warm) five times.
4. Breathe out then breathe in.
5. Wash again and repeat the process for five times.
6. Spit out the water from mouth.

This will help you to increase or maintain your vision power.You should do this minimum three times a day.

Tuesday, June 3, 2008

To Live Healthy and Happy Life: Everyday tips

1. Wake-up as early as possible.

2. Even before opening your eyes. Just sit on a bed and join both hands in a way Muslim do a prayer. Open your eyes and watch you palm for a moment. Think that you are very special, you born to do the best things. Rub your palm to each other and touch your face with both palms. Take a deep breath. Smile and get out of the bed.

3. Drink at least 4-5 glass of water after getting off from bed.

4. Watch sunrise. Stretch your body. Close your eyes and rapidly move your eyeballs.

5. Always do a mouthwash before brushing your teeth.

6. Keep a small book self in bathroom. Buy some self improvement or inspirational books. Read some pages while using toilet.

7. Do a light exercise before breakfast. Learn yoga or just sit and take at least 20 deep breaths. While breathing in imagine that some powerful energy is going inside your body system and while breathing out imagine all negative thoughts are going out of your mind.

8.
Eat light breakfast. Don’t eat cereals, Add dry fruits, egg, honey and a banana in milk and drink.

9.
If you are a smoker. Don’t quit. But try to increase a gap between two cigarettes. Give at least an hour gap after your coffee, lunch, snacks, dinner and increase slowly. In 4-5 years you will automatically quit.

10.
Treat yourself like king/princess. Eat rich lunch with lots of fruit and salad. Try to enjoy being vegetarian.

11.
Buy less but always buy good perfume, good clothes good shoes etc. Use best face cream. Use best shampoo. Watch yourself in mirror, smile and feel the confidence just before leaving from the house.

12.
Drink only on weekends. Avoid binge drinking. Drink in style. Wake up late. Before bath, make a drink and drink sip-by-sip . Make another drink while cooking your favorite food and have sip-by-sip and finish it before lunch. Relax, Sit in your balcony/patio. Read some book, or just close your eyes and do not think anything. Just relax and enjoy.

13.
Drink lots of water, juice.

14.
Keep blinking your eyes while reading or using computer.

15.
High pressure in work, don’t forget to rub your hand close your eyes and touch your face every hour or two. Deep breath. Stretch your body. Watch ceiling while put pressure on chin with hand.

16.
Watch movies, but don’t follow the drinking or smoking style of your favorite actor/actress. But watch their dress sense during different events in the film. Watch their communication skills and presentation skills and learn something from it.

17.
While coming back after movie. Play a game with your friends or family. Ask the name of the all actors/actresses. Ask specific locations, phone numbers, dates etc they mentioned in the movie. It is called a memory game. It will help you to remember the things person told in her/his first meeting.

18.
Play with your children. Let them play in outdoor. Let them fall, dig in the mud, let them bring themselves close to the nature. Don’t worry they have already vaccinated from any fatal diseases .If they fall sick, it is not fatal but it will improve their immune system.

19.
Don’t panic from first sign of cold to you or your children. Don’t take or give medicine for first 5 days. You can have powerful medicine only if you have a very important event next day.

20.
Discuss your day with family while having dinner. Share some jokes, events with them.

21.
Call your friends ask their advices. Ask the tips to save money.

22.
Save some money every month. All teach your kids to save money for new toy, clothes, shoes or guitar.

23.
Donate generously and anonymously and forget. The feelings you will get are priceless.

Thursday, May 29, 2008

Hello India : Some eye opener american way of living

Whenever I go back to India I feel there are so many misconceptions about USA. Here I am not going to praise USA but I felt that it is my moral duty to inform the readers of India about some very facts of this country.

1. Eighty percent of Americans wake up before 5 AM. They believe in early to bed and early to rise. Back in India every parents tell their children about this ages old mantra of good health. They don't listen.

2. Here government offices timings are 8.00-5.00. The senior officers come early in office then their employees. (Think about any government office in India). Why they are wasting your tax money?

3. Every officer here put their heart/at least show to help you with your issues and problems.

4. You don't need to give bribe to get your work done. No here also government employees get less pay then private companies employees.

5. Almost all Americans are really patriotic. I met a person here who used to visit India to get army secrets during 80s and his statement was shocking. He told me that he used to get any secrets from soldiers by paying money. He consider that it was a cake-walk. Well that was in 80s. Presently I have seen that many Indians who come here for work they simply speak about negative points of India to Americans and feel that they are becoming more friendly to Americans. In fact American don't respect such people make fun of it at their back.

6. Boys have to live separately as soon as they become 18 years and earn their own money and study. I have seen guys even above 30 years of age dependent on their parents in India.

7. Americans are very shy and conservative. They don't drink everyday as European do. In Europe it consider as a social drinking if every evening they go to local pub for few drinks after work. In America it is consider as an alcoholic.

8. Americans don't litter. They don't throw garbage on side of the road, And if they see that they pick it and throw it in trash can.

9. Here there is no concept of page three. Nudity in TV and newspaper is just out of imagination just opposite to page three of UK. Metro girls are dying in India to come on page three.

10. Americans pay their taxes.

11. Here there is respect for each other. Americans don't stare at opposite sex whereas in India so called love starts by staring each other from their balcony. Come on. Respect women.

12. There are so many volunteer in Fire department and police department. If there is news of missing person, there would be more than 500 volunteer searches the nearby areas day- and night.

13. American donate generously part of their money regularly or at least once in their lifetime.

There are so many more to come....