I need to generate CSV files. I tried using Log4j by keeping the pattern as log4j.appender.file.layout.ConversionPattern=%m%n its writing fine
my doubt here is, is it good to write the CSV file using log 4j or is it good to write CSV files using FileWriter Performance related i dont think there is much difference because its normal file writing but is there any safety mechanisms or any other operations log 4j will be performing which we will not do while writing a file using FileWriter?
I prefer to go using FileWriter because its simple but if there are any advantages over FileWriter if we use log4j i will go for log4j need your advices
log4j is not for general file output. It is for logging. If the file you are writing is not logging--that is, if it is part of the normal business output of your app--then you should not be using a logging tool to write it.
Thanks for the quick response and thanks for the welcome, could you please let me know the reason why we should not use log4j for writing normal files other than log files, the file i am writing is not a log its an output file of the app
The thing is, when somebody else looks at your code three years from now, their first question is going to be "Why is this logging going on here?" And after a while (the length of which depending on how good of a programmer they are) they will say "Ohhhh... now I get it".
So, using logging for that task is a Clever Idea™. The trouble with that is, not all programmers are clever people. So sometimes it's not a good idea to be too clever in your programming.
You could perhaps fix that problem by a block of comments, though.
venkata vinay bysani wrote:Thanks for the quick response and thanks for the welcome, could you please let me know the reason why we should not use log4j for writing normal files other than log files,
Because that's not its job. It can be made to work for that purpose, but 1) You'll probably have to do some non-standard stuff to make it happen, 2) By simply changing your app's log configuation you can change its business beahvior (not a good thing), and 3) It violates the Principle Of Least Surprise. Somebody looking at your code and your log4j.properties or log4j.xml--whether it's a coworker maintaining the app, a customer configuring it for use, or even you yourself a few months down the line--will have to spend time figuring out what you're doing and wondering why you're doing it.
venkata vinay bysani
Joined: Feb 09, 2010
Thanks for your explanations Jeff Verdegan and Paul Clapham, the explanations you have given are like a very good examples to understand the rule Principle Of Least Surprise. I will stick to FileWriter then thanks once again...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Writing CSV file using LOG 4J is good or using FileWriter is good