Technical Tips, Tricks and Articles

Archive for the ‘Miscellaneous’ Category

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

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

Knol – Google Contender for WikiPedia

leave a comment »

It seems as if Google is following the same path which Microsoft did in Past. History is repeating itself but this time it’s not desktop, software or os market, this time it’s WEB and the company is Google.

Google is either buying each and everything which is making its presence on internet. Few weeks earlier, Google even bid for Digg, though the bid was not successful but Google has tried. It would not be a surprise if Google will launch its own gDigg Beta (Following Google Convetions) in near future. Anyway, Those are things that are yet to happen but now let me share with you the thing that is happening.


Google’s contender for WikiPedia. Since Google has always added nice things in it’s ventures and the convention is being followed over here as well. Up till now i have found 2 decent things in Knol.

  • You can set the permissions who should be able to edit/write the things for particular thing.
  • Every individual is allow to write his own writing for already written article and each article will be rate on the basis of author’s authenticity, history and votes by other users. For example, you might find only one page on WikiPedia on Pakistan but in Knolyou may find multiple page son Pakistan contributed by different authors and you can see which author is more authentic or whatsoever.

It is still in BETA (seems like google naming standard) let’s see when it will be officially launched.

Written by ..alee

August 15, 2008 at 1:53 pm

Posted in Miscellaneous

Tagged with , , ,