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 vaanila.report class heirarchy mentioned in FileAppenders  example. In given example, following piece of lines were handling specific logging based on classes in .properties file

log4j.logger.com.vaannila.admin=WARN,AdminFileAppender
log4j.logger.com.vaannila.report=DEBUG,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 vaanila.report the configuration would be

01 <logger name="vaanila.report">
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>
13 
14 ...
15 
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;
3 
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;
3 
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 5 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;
2 
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;
13 
14 public class Test extends MIDlet implements CommandListener, Runnable{
15 
16     private Display mDisplay;
17     private Command mExitCommand, mFindCommand, mCancelCommand;
18 
19     private TextBox mSubmitBox;
20     private Form mProgressForm;
21     private StringItem mProgressString;
22 
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);
27 
28         mSubmitBox = new TextBox("Test", "", 32, 0);
29         mSubmitBox.addCommand(mExitCommand);
30         mSubmitBox.addCommand(mFindCommand);
31         mSubmitBox.setCommandListener(this);
32 
33         mProgressForm = new Form ("Lookup Progress");
34         mProgressString = new StringItem(null, null);
35         mProgressForm.append(mProgressString);
36     }
37 
38     protected void destroyApp(boolean arg0) throws
39                               MIDletStateChangeException {
40         // TODO Auto-generated method stub
41 
42     }
43 
44     protected void pauseApp() {
45         // TODO Auto-generated method stub
46 
47     }
48 
49     protected void startApp() throws MIDletStateChangeException {
50         mDisplay = Display.getDisplay(this);
51         mDisplay.setCurrent(mSubmitBox);
52     }
53 
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     }
69 
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);
86 
87     }
88 
89     private String lookup(String word) {
90         if (word.equalsIgnoreCase("1")){
91             throw new RuntimeException("exception thrown");
92         }
93         return "hardcoded definition";
94     }
95 
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.

toolbar-image

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

Error starting eclipse

with one comment

You might face an error while starting eclipse on a freshly installed system, or on the system which has undergone a fresh upgrade. The error message will be like

—————————
Eclipse
—————————
JVM terminated. Exit code=-1
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
-XX:MaxPermSize=256M
-Djava.class.path=D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
-os win32
-ws win32
-arch x86
-showsplash D:\eclipse-jee-ganymede-win32\eclipse\\plugins\org.eclipse.platform_3.3.100.v200806172000\splash.bmp
-launcher D:\eclipse-jee-ganymede-win32\eclipse\eclipse.exe
-name Eclipse
–launcher.library D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.100.v20080509-1800\eclipse_1114.dll
-startup D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
-framework plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
-vm C:\Program Files\Java\jre1.6.0\bin\client\jvm.dll
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m
-XX:MaxPermSize=256M
-Djava.class.path=D:\eclipse-jee-ganymede-win32\eclipse\plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
—————————
OK
—————————

Actually, eclipse is trying to get the version of java that is installed on system. you might have installed that latest one but there are possibilities that any upgradation of later softwares has replaced the java.exe files in system32 folder with older version. All you need to do is to run eclipse with clean parameters. Create a batch file in the directory where eclipse.exe is and write this line in it eclipse -clean -vmargs -Xmx256m

Written by ..alee

January 30, 2009 at 4:11 pm

Posted in java

your own personal code repository

leave a comment »

are you crazy about coding? are you the one who use to write code for others or sometime your written utilities are so good that you actually want to share them and want to release the later versions of it?

If you are one of that guy then this site is really gona rock your coding experience. The site is github social coding .

Here you can make your profile and can create your own repository. For free users, there are limits (100 mb space, no ssl etc). But even then it’s really great to get things started.

Get going coders

Written by ..alee

January 23, 2009 at 4:15 pm

Posted in code website

Manage your TODO with GMail

leave a comment »

I wonder, what was the life before GMail. Gmail was already awesome and day by day it’s getting really great. Today, I am going to write simple tips which will help you to turn your GMail into your TODO Task Manager. Actually, there are 2 ways that i find great and I am going to explain you both.

  1. This tip is going to use 2 GMail Lab (quicklinks and superstars) and ofcourse the google’s legendary search capability. First of all, enable both of these labs by going to your lab settings and selecting Enable against each of the lab. Now, make a decision about any of your favorite superstar for your todo list. I selected red-bang (don’t forget to read their names by hovering your mouse on each superstar in your mail settings > general tab).
    red-bang

    red-bang

    Now, we need to create a quickview so that it may sort out TODO for us. Type this string in GMail search box is:unread AND has:red-bang and add it to quickview and name it TODO. Now all you have to do is to mark all your TODO items with this red-bang star by click on star icon against emails and whenever you want to view your TODO, just click on the TODO linkview from your quickview.

  2. In second method, we are going to use GMail freedom of email aliases. May be you people know that in GMail youremail@gmail.com is same as youremail+anytag@gmail.com. So what we are going to do is to create a filter on TO field i.e; apply label TODO to all those emails whose TO field is youremail+todo@gmail.com. Now, whenever an email has been sent to youremail+todo@gmail.com it’ll be automatically added to your TODO label list.

The benefit of method 2 over method 1 is that you can ask your friends to email at youremail+todo@gmail.com whenever there is something pending on you and GMail will manage it as your TODO list in your inbox.

Written by ..alee

September 17, 2008 at 12:16 pm

Posted in GMail

Tagged with ,

Follow

Get every new post delivered to your Inbox.