Hi All,
Here, the warm greeting from HCL to newcomers in IT field.
HCL is inviting Fresher applications from ‘08-‘09 batch with a score of min 65% from ECE, EEE, IS, CSE, IT, E&I and MCA disciplines.
Kindly update the needed information on the folloeing link
http://hcl.aspiringminds.in
Eligible candidates will be intimated, to appear for CBT test. Those qualifying after the CBT test will appear for an interview at Bangalore/Chennai/NCR.
Candidates can choose preferrable working locations for final placements and can look forward to a compensation of Rs. 18,000/- per month for the first six months and then Rs. 2.70 lakhs per annum. Cool, na?
A good chance to work with HCL. Don't miss it.
And All the very best for your future. :)
Friday, February 5, 2010
Sunday, September 13, 2009
Redirect Log Messages Of Same Class To Two Different Files
Hi Reader,
This is gonna be my first post for log4j.
Well, this is all about to log messages of a class to different log files.
Here i am giving you a good tricky way to achieve this without creating
custom logger or level.
I got this idea from my project. BA provided the given scenario--
When importing data from XML to database, if data imported successfully, then
log to success.log and if unable to import then log it to failure.log. And the
warning level must be kind of warn.
Well, here i am not going to show the actual code.
In the following illustration,
1. MainLog.java -- The main class for which we need to log messages.
2. MyLog.java -- A very simple class to trick log4j to redirct log to their own file.
3. log4j.properties -- contains the log4j configuration. created two log file
a. main.log
contains log messages of MainLog.java.
b. custom.log
contains log messages when myWarn() of MyLog is called in MainLog.java
In log4j.properties configure two log files and there appender--
log4j.logger.src.MyWarn=WARN, W
log4j.appender.W.File=C:\\_T\\custom.log
log4j.logger.src.MainLog=WARN, R
log4j.appender.R.File=C:\\_T\\main.log
In MyLog.java did two things--
1. Created logger for this class.
2. Created a static method that simply call LOG.warn(msg).
note : similarly you can create more methos that contain other level calls like info, error etc.
In this demonstration, i will show you how to log two messages of same level (here warn) into two different log files.
Here is the complete code--
------------------------------------------------------------------------------------
MyLog.java tricky class to redirect the log wherever MyLog.myWarn(msg) called
------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
MainLog.java the class for which logging is being done.
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
log4j.properties Having looging configuration
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
Hope this will help you.
Any comments/suggestion will be apprecitated.
So what do you need just write.. I am waiting.....
Thanks,
Tanzy. :)
This is gonna be my first post for log4j.
Well, this is all about to log messages of a class to different log files.
Here i am giving you a good tricky way to achieve this without creating
custom logger or level.
I got this idea from my project. BA provided the given scenario--
When importing data from XML to database, if data imported successfully, then
log to success.log and if unable to import then log it to failure.log. And the
warning level must be kind of warn.
Well, here i am not going to show the actual code.
In the following illustration,
1. MainLog.java -- The main class for which we need to log messages.
2. MyLog.java -- A very simple class to trick log4j to redirct log to their own file.
3. log4j.properties -- contains the log4j configuration. created two log file
a. main.log
contains log messages of MainLog.java.
b. custom.log
contains log messages when myWarn() of MyLog is called in MainLog.java
In log4j.properties configure two log files and there appender--
log4j.logger.src.MyWarn=WARN, W
log4j.appender.W.File=C:\\_T\\custom.log
log4j.logger.src.MainLog=WARN, R
log4j.appender.R.File=C:\\_T\\main.log
In MyLog.java did two things--
1. Created logger for this class.
2. Created a static method that simply call LOG.warn(msg).
note : similarly you can create more methos that contain other level calls like info, error etc.
In this demonstration, i will show you how to log two messages of same level (here warn) into two different log files.
Here is the complete code--
------------------------------------------------------------------------------------
MyLog.java tricky class to redirect the log wherever MyLog.myWarn(msg) called
------------------------------------------------------------------------------------
package src;
import org.apache.log4j.Logger;
public class MyLog {
private static Logger LOG = Logger.getLogger(MyLog.class);
public static void myWarn(String msg) {
LOG.warn(msg);
}
}
-------------------------------------------------------------------------------------
MainLog.java the class for which logging is being done.
-------------------------------------------------------------------------------------
package src;
import org.apache.log4j.Logger;
public class MainLog {
private static Logger LOG = Logger.getLogger(MainLog.class);
public static void main(String[] args) {
LOG.warn("Log To main.log");
MyLog.myWarn("Msg To File custom.log");
}
}
-------------------------------------------------------------------------------------
log4j.properties Having looging configuration
-------------------------------------------------------------------------------------
log4j.rootLogger=WARN
# ***** A is set to be a ConsoleAppender.
log4j.appender.A=org.apache.log4j.ConsoleAppender
# ***** A uses PatternLayout.
log4j.appender.A.layout=org.apache.log4j.PatternLayout
log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=C:\\_T\\main.log
# Control the maximum log file size
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.Append=FALSE
# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.logger.src.MyLog=WARN, W
log4j.logger.src.MainLog=WARN, R
log4j.appender.W=org.apache.log4j.RollingFileAppender
log4j.appender.W.File=C:\\_T\\custom.log
# Control the maximum log file size
log4j.appender.W.MaxFileSize=100KB
log4j.appender.W.Append=FALSE
# Archive log files (one backup file here)
log4j.appender.W.MaxBackupIndex=1
log4j.appender.W.layout=org.apache.log4j.PatternLayout
log4j.appender.W.layout.ConversionPattern=%p %t %c - %m%n
-------------------------------------------------------------------------------------
Hope this will help you.
Any comments/suggestion will be apprecitated.
So what do you need just write.. I am waiting.....
Thanks,
Tanzy. :)
Saturday, August 8, 2009
Replacing String In File
Hi Reader,
It's going to be my second post.
This post is not as a rocket science but needful.
I got idea to create this program, when i got issue with my module.
There was an xml document and i need to know the occurances of a particular string.
The file size was more than 10 mb. I used edit plus for this. First it took time for loading file in edit plus and then when i tried hit "ctrl + h" (to find and replacce dialog box) duhh! Got hanged.
Then i used my program. And felt glad.
Please have look may be it ll be helpful for you also.
This program replaces all the occurances of a given string to be replaced in the given file with the given string to be replaced by.
package src;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class ReplaceDataInFile {
public static void main(String args[]) {
ReplaceDataInFile ob = new ReplaceDataInFile();
ob.replaceStringInFile("C:\\_T_Work", "file.txt", "old", "new");
}private void replaceStringInFile(final String fileLoc, final String fileName, final String toReplace, final String replaceBy) {
File file = null;
BufferedReader br = null;
BufferedWriter bw = null;
String currentLine = "";
String oldContentOfFile = "";
int occuranceFound = 0;
int countLine = 0;
try {
file = new File(fileLoc + System.getProperty("file.separator") + fileName);
br = new BufferedReader(new FileReader(file));
while ((currentLine = br.readLine()) != null) {
countLine++;
oldContentOfFile = oldContentOfFile + currentLine + "\r\n";
System.out.println("Line " + countLine + " : " + currentLine);
if (currentLine.contains(toReplace)) {
occuranceFound++;
}
}
} catch (IOException e) {
System.out.println("Error Occured When Reading File : " + e);
System.exit(1);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
System.out.println("Error Occured When Closing Reader : " + e);
System.exit(1);
}
}
}
System.out.println();
System.out.println("Old Content of The File : ");
System.out.println(oldContentOfFile);
String latestText = oldContentOfFile.replaceAll(toReplace, replaceBy);
System.out.println("Latest Content of The File : ");
System.out.println(latestText);
try {
bw = new BufferedWriter(new FileWriter(fileLoc + System.getProperty("file.separator") + fileName));
bw.write(latestText);
System.out.println("Total [" + occuranceFound + "] Occurances of ["
+ toReplace + "] Replaced By [" + replaceBy + "].");
} catch (IOException e) {
System.out.println("Error Occured When Writtin To File : " + e);
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
System.out.println("Error Occured When Closing Writer : " + e);
System.exit(1);
}
}
}
}
}
To execute this just change the paramter of the method called in main().
Waiting for your responses.
Thanks,
Tanzy.
Sunday, July 19, 2009
Introducing The Blog With Metadata
Hi all.
This blog is for Java and J2EE related queries. Those of you who are newbie to Java and want to learn can make use of this blog. Also useful for the developer that wants solution to some problems. Here, what i post is either i learnt it by my experience or the gurus of java. If i write any code, that is well tested at my end.
So let's not much wait, and start with metadata. The graduates always learn this definition- "data about data is metadata", with vague examples. The definition really worths million. But how about understanding?
Let's understand with this simple definition --
A Data = Combination of Attributes [Attributes are column in a table]
= Unique Attributes + NonUnique Attributes
In this a particular combination of "Unique Attributes" defines a particular kind of data. Hence "Unique Attributes " are nothing but metadata.
Suppose a customer goes to a store of laptop. Now in that store there are several kind of lapy are available. Now customer says i want, laptop made by "hp", with processor "intel core duo", hard disk "320 gb', ram "4 mb". Another customer wants laptop made by "dell", with processor "intel core duo", hard disk "320 gb', ram "3 mb".
Notice the italic words. This is the main four combination that generally defines a laptop. In this if any one them gets changed that defines another new product.
I think this is fair enough to understand. If you feel more on this please write me. I ll get back to you with much detailed and better example.
Please feel free to write comments on the topic.
I think your comments will give another way to think me and to provide qualitative articles.
Thanks.
This blog is for Java and J2EE related queries. Those of you who are newbie to Java and want to learn can make use of this blog. Also useful for the developer that wants solution to some problems. Here, what i post is either i learnt it by my experience or the gurus of java. If i write any code, that is well tested at my end.
So let's not much wait, and start with metadata. The graduates always learn this definition- "data about data is metadata", with vague examples. The definition really worths million. But how about understanding?
Let's understand with this simple definition --
A Data = Combination of Attributes [Attributes are column in a table]
= Unique Attributes + NonUnique Attributes
In this a particular combination of "Unique Attributes" defines a particular kind of data. Hence "Unique Attributes " are nothing but metadata.
Suppose a customer goes to a store of laptop. Now in that store there are several kind of lapy are available. Now customer says i want, laptop made by "hp", with processor "intel core duo", hard disk "320 gb', ram "4 mb". Another customer wants laptop made by "dell", with processor "intel core duo", hard disk "320 gb', ram "3 mb".
Notice the italic words. This is the main four combination that generally defines a laptop. In this if any one them gets changed that defines another new product.
I think this is fair enough to understand. If you feel more on this please write me. I ll get back to you with much detailed and better example.
Please feel free to write comments on the topic.
I think your comments will give another way to think me and to provide qualitative articles.
Thanks.
Subscribe to:
Posts (Atom)