Technical Tips, Tricks and Articles

Quickstart – log4j

leave a comment »

There are like 100 of log4j tutorials on the internet. I am not going to put another one, just a compilation of few resources which are good to go and will add couple of notes, which I wasn’t able to find online or they took forever.

This particular link is pretty decent. It talks about basics, MulitpleAppenders, FileAppenders and then log4j xml configurations.

One of the thing that is missed in above tutorial is configuring your XML based configurations for specific class hierarchy. Lets talk about vaanila.admin and class heirarchy mentioned in FileAppenders  example. In given example, following piece of lines were handling specific logging based on classes in .properties file,AdminFileAppender,ReportFileAppender

What would be their equvialent in XML ?

01 <logger name="vaanila.admin">
02 	<level value="WARN"/>
03 	<appender-ref ref="AdminFileAppender"/>
04 </logger>

and similarly, for the configuration would be

01 <logger name="">
02 	<level value="WARN"/>
03 	<appender-ref ref="ReportFileAppender"/>
04 </logger>

One of the thing, that these tutorials didn’t help me was how can I log specific logging based on application modules i.e. if I have multiple .ear files, then how can I separate the loggings for each .ear file? Definitely, the class level logging wouldn’t help me because there could be a scenario where there are “shared” classes. The solution to this question is log4j version 3.2.4 and higher. Using that log4j you can use following configuration to log based on ear files.

Assuming I have an application and one of the ear module is named as some.ear. The settings would look like something

01 <appender name="some" class="org.apache.log4j.FileAppender">
02 	<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler>
03 	<param name="Append" value="false"/>
04 	<param name="File" value="./log/some.log"/>
05 	<layout class="org.apache.log4j.PatternLayout">
06 		<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
07 	</layout>
08 	<filter class="org.jboss.logging.filter.TCLFilter">
09 		<param name="AcceptOnMatch" value="true"/>
10 		<param name="DeployURL" value="some.ear"/>
11 	</filter>
12 </appender>
14 ...
16 <root>
17 	<appender-ref ref="CONSOLE"></appender-ref>
18 	<appender-ref ref="FILE"></appender-ref>
19 	<appender-ref ref="some"></appender-ref>
20 </root>

I hope that will be helpful.

Written by ..alee

April 29, 2011 at 4:12 pm

Text messages Time Issue

leave a comment »

I have been using FIDO for almost a year. Earlier, I was using it with Nokia N97 mini and recently I got HTC Desire. FIDO/Rogers and I guess T-Mobile as well, have an issue in which incoming messages are 4 hours behind from the given time. If you are not using threaded view SMS then this would not be an issue but if you are using iOS/Andriod then you will not be able to see threaded conversation.

The incoming messages will pile up on top of the screen and your outgoing messages will stack up at the bottom of the screen. It will get worst when you have 20-30+ text messages.

Few people suggested to adjust the time zone to GMT 0 and the issue would be resolved. But this will mess up with your calendar entries. An easies solution that I found is to use the SMS Time Fix for Andriod. After installation, set the application to add +4:00 hours to incoming messages in order to adjust the time and your conversation will be visible in threaded view.

Written by ..alee

September 3, 2010 at 8:04 am

Google Chrome OS

leave a comment »

Way back, I posted series of articles (article 1, article 2) about the future of OS and now Google is about to take it’s initial steps towards it. The news isn’t surprising for me since the hype of Google OS was in market from quite a while.

As stated on Google blog, Google is redefining the concepts of OS. Their focus is “Speed, simplicity and security”. One of the thing that really got my attention is that Google isn’t focusing on some high-end hi-fi kind OS. Their “initial” focus is to provide a platform which should be secure and simple enough to help the user to leverage from web applications. Google had made this point quite clear in post

All web-based applications will automatically work and new applications can be written using your favorite web technologies. And of course, these apps will run not only on Google Chrome OS, but on any standards-based browser on Windows, Mac and Linux thereby giving developers the largest user base of any platform.

This does make sense, since there are almost every kind of applications available on internet now, all you need is web browser and a decent internet connection. Google knows that it’s time for RIA and Google is providing almost every possible medium to make as much as user friendly and accessible.

Written by ..alee

July 8, 2009 at 2:30 pm

Posted in Google, OS

Tagged with , ,

Comparing Wrapper objects values in range –128 to 127

leave a comment »

While debugging through a bug that I encountered in one of my ongoing project. I came to know a strange behavior of Java. Consider the following code segment

1 Integer a = 10;
2 Integer b = 10;
4 if (a == b){
5 	System.out.println("Two values are equal");
6 	}

If you look closely at line no 4, then you would realize that the code is actually comparing “Java objects”. Since “a” and “b” are not wrapper classes not primitive types.  But even then the condition is being true. Ok, some how this makes sense (at least till now unless you read this code segment)

1 Integer a = 150;
2 Integer b = 150;
4 if (a == b){
5 	System.out.println("Two values are equal");
6 	}

Astonishingly, for the above code, the if statement would not execute true. Why?

Well, ever since Java has introduced “auto-boxing” feature, you’ll face this issue. Why is it so? Actually, compiler try to optimize things as much it can. For this, Java has a pool of values from –128 to 127. Whenever, there is some auto-boxing between these values, the reference object for the wrapper class will get the same memory location. In both cases, we are comparing “object references” but in first case, since the value was in the range for both objects hence, Java assigned the same reference location to both objects, making the condition “true” on comparing memory location for two objects.

Now, the question is why between –128 to 127?. Well, the smallest range of values for smallest wrapper class is between –128 to 127 i.e. Byte.

Written by ..alee

July 5, 2009 at 1:06 pm

Posted in code, interview, java, programming

Tagged with , ,

How to retrieve MSN Messenger display pictures

with 6 comments

One of my friend asked me that he needs to copy the display picture he had in his MSN Messenger display. He has tried searching but could not located it. Here is some detail about MSN way of storing display pictures.

Please browse to the following path

%userprofile%\Local Settings\Application Data\Microsoft\Messenger

Here you will see folders against each email id that signed in to the msn messenger on that particular machine. Follow the steps to retrieve the display picture.

  • Browse to the desired email id whose DP you want to retrieve
  • Open ObjectStore and then open UserTile folder.
  • You’ll see some files in it with some weird  names ending with either DT2 extension or ID2. (notice the file size of both files. the DT2 will be slightly larger than ID2).

The DT2 is actually that thumbnail of your display picture. You have to open it using any photo viewer software:

  • Right click on the file
  • Select open
  • A pop up will come up asking you to search for the desired program from internet or choose
  • Select on choose and then use any photo editing software
    • For basic users select “windows pictures and fax viewer”
  • Now you can save this picture at your favorite location.

Written by ..alee

July 1, 2009 at 11:07 am

Posted in msn

Tagged with , ,

Syntax highlighting on blogs

leave a comment »

Syntax highlighting is always been a desired things on blogs, specially for those who post their code so often on blogs. Not only it adds to the look of the blog but also, it makes the code more readable.  From quite a few days, i was trying to search for something by which i can paste my codes in formatted highlighted form on the blog, but whatever plug-in i found was not integrateable into wordpress free service.

The earlier solutions that came to my mind was taking a snapshot of the code window and post here. But it includes few extra steps for me (taking a snapshopt, croping it and the uploading it) and for reader, they just can’t COPY-PASTE the code if they want to.

highlightSo if you are one of those who are looking for some syntax highlighting thing for your blog, here is some great tool, named Highlight. The tools come with some default styles, including eclipse, emacs and other well know editors. You can configure the style if you wish so and the you can export it in your desired format i.e (html – with inline CSS, RTF, XHTML, LaTeX, SVG, XML etc).  See the below snippet that I formatted/highlighted using the it. it’s pretty clean and easy to incorporate 🙂

1 package com.e2e.test;
3 import javax.microedition.lcdui.Alert;
4 import javax.microedition.lcdui.Command;
5 import javax.microedition.lcdui.CommandListener;
6 import javax.microedition.lcdui.Display;
7 import javax.microedition.lcdui.Displayable;
8 import javax.microedition.lcdui.Form;
9 import javax.microedition.lcdui.StringItem;
10 import javax.microedition.lcdui.TextBox;
11 import javax.microedition.midlet.MIDlet;
12 import javax.microedition.midlet.MIDletStateChangeException;
14 public class Test extends MIDlet implements CommandListener, Runnable{
16     private Display mDisplay;
17     private Command mExitCommand, mFindCommand, mCancelCommand;
19     private TextBox mSubmitBox;
20     private Form mProgressForm;
21     private StringItem mProgressString;
23     public Test() {
24         mExitCommand = new Command("Exit", Command.EXIT, 0);
25         mFindCommand = new Command ("Find", Command.SCREEN, 0);
26         mCancelCommand = new Command ("Cancel", Command.CANCEL, 0);
28         mSubmitBox = new TextBox("Test", "", 32, 0);
29         mSubmitBox.addCommand(mExitCommand);
30         mSubmitBox.addCommand(mFindCommand);
31         mSubmitBox.setCommandListener(this);
33         mProgressForm = new Form ("Lookup Progress");
34         mProgressString = new StringItem(null, null);
35         mProgressForm.append(mProgressString);
36     }
38     protected void destroyApp(boolean arg0) throws
39                               MIDletStateChangeException {
40         // TODO Auto-generated method stub
42     }
44     protected void pauseApp() {
45         // TODO Auto-generated method stub
47     }
49     protected void startApp() throws MIDletStateChangeException {
50         mDisplay = Display.getDisplay(this);
51         mDisplay.setCurrent(mSubmitBox);
52     }
54     public void commandAction(Command c, Displayable d) {
55         if (c == mExitCommand){
56             try {
57                 destroyApp(false);
58             } catch (MIDletStateChangeException e) {
59                 System.out.println("exception @ destroyApp(false);");
60             }
61             notifyDestroyed();
62         }
63         else if (c == mFindCommand){
64             mDisplay.setCurrent(mProgressForm);
65             Thread t = new Thread(this);
66             t.start();
67         }
68     }
70     public void run() {
71         String word = mSubmitBox.getString();
72         String definition;
73         try{
74             definition = lookup(word);
75         }
76         catch (Exception ie){
77             Alert report = new Alert("Sorry", "Something went wrong", null,
78                            null);
79             report.setTimeout(Alert.FOREVER);
80             mDisplay.setCurrent(report, mSubmitBox);
81             return;
82         }
83         Alert report = new Alert ("Definition", definition, null, null);
84         report.setTimeout(Alert.FOREVER);
85         mDisplay.setCurrent(report, mSubmitBox);
87     }
89     private String lookup(String word) {
90         if (word.equalsIgnoreCase("1")){
91             throw new RuntimeException("exception thrown");
92         }
93         return "hardcoded definition";
94     }
96 }

Written by ..alee

March 13, 2009 at 9:15 am

Posted in Miscellaneous

Tagged with , , , ,

Postbox – an awesome mail client

with 2 comments

When it comes to email, I am stick to GMail. There is nothing else that i like more than GMail.

But sometime, you just need a desktop application when you are in professional environment. Microsoft Outlook is a big choice, however, i was using Mozilla Thunderbird from quite a while. Which is light weight, have option to subscribe to the newsgroups, global address book. But still there were lot of things missing which i found in postbox.

The software has really nice features, besides having all those features of thunderbird, it has integration with GMail (POP3, IMAP). You can have very easy TODO management, Threaded emails (even for GMail).

One of the really impressing feature of this software is that it manages your attachments, images at one place.


Clicking on the image button will open a new tab name images. It will index the images of your configured mail account once and then your images will be accessible at one place. Same goes to attachments.

Anyone, who is using Mozilla ThunderBird should try this one. You’ll definitely love it.

Written by ..alee

February 12, 2009 at 4:24 pm

Posted in Application, Review