Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in alignning the text in java?

 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am using log4j to log the user details when a submit is clicked in form page. Name, Email address, company etc all details of the user. However after writing to log file, when I open the log file in notepad, the alignment is not good, but if i open the log file in wordpad, the alignment is good.

Sample code:

String htmlContent = "\t" + serverProperties.getString("mail.subject")+" "+ mailFrom + " \n"+
"-----------------------------------------------------------------------------------------" + "\n" +
"\t" + "Type " + "\t" + "|" + "\t" + "Product Info " + "\t" + "-" + "\t" + rq_type_info + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Product Demo " + "\t" + "-" + "\t" + rq_type_demo + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Product Evaluation" + "\t" + "-" + "\t" + rq_type_eval + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Services Info " + "\t" + "-" + "\t" + rq_type_services + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Newsletter " + "\t" + "-" + "\t" + rq_type_news + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Contact Sales " + "\t" + "-" + "\t" + rq_type_sales + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Login Access " + "\t" + "-" + "\t" + rq_type_login + "\n" +
"\t" + "\t \t \t \t" + "|" + "\t" + "Others " + "\t" + "-" + "\t" + rq_type_others + "\n" +
"\t" + "Name " + "\t" + "|" + "\t" + name + "\n" +
"\t" + "Company " + "\t" + "|" + "\t" + company +"\n" +
"\t" + "Job Title " + "\t" + "|" + "\t" + jobTitle + "\n" +
"\t" + "Division " + "\t" + "|" + "\t" + division +"\n" +
"\t" + "Email Id " + "\t" + "|" + "\t" + mailFrom + "\n" +
"\t" + "Work Phone " + "\t" + "|" + "\t" + workPhone + "\n" +
"\t" + "Country " + "\t" + "|" + "\t" + country +"\n" +
"\t" + "Areas of Interest " + "\t" + "|" + "\t" + productGroup +"\n" +
"\t" + "Additional Information" + "\t \t" + "|" + "\t" + additionalInfo +" \n"+
"-----------------------------------------------------------------------------------------";

I have done so, using '\t' tab space but this is not common in notepad and in wordpad.

Please let me share your ideas to do it in java, so that the alignment looks good in notepad and in wordpad.

REgards,
Prabhu.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't log4j supply log formatting mechanisms that mean you don't have to add all these white space characters to your log message?

Indeed it does. Have a read of the documentation about PatternLayouts.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alignment of plain text in text editors depends on the font you're using, tab size, etc.

Why are you calling a variable "htmlContent" when there's no HTML in it? Is this supposed to actually be an email? An HTML email?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic