I am getting data from log file and printing it but it was not as formated as in log file my code is,
try
{
String strpath="/var/new.log";
FileReader fr = new FileReader(strpath);
BufferedReader br = new BufferedReader(fr);
String ch;
do {
ch = br.readLine();
if (ch != null)
out.println( ch+"\n");
} while (ch != null);
fr.close();
}
catch(IOException e){
out.print(e.getMessage());
}
Data in my file is this format,
[1324649399] Nagios 3.3.1 starting... (PID=3751)
[1324649399] Local time is Fri Dec 23 09:09:59 EST 2011
[1324649399] LOG VERSION: 2.0
[1324649400] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1324649400] ndomod: Could not open data sink! I'll keep trying, but some output may get lost...
[1324649400] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
My code is printing it in this Format,
[1324649399] Nagios 3.3.1 starting… (PID=3751) [1324649399] Local
time is Fri Dec 23 09:09:59 EST 2011 [1324649399] LOG VERSION: 2.0
[1324649400] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009
Nagios Core Development Team and Community Contributors [1324649400]
ndomod: Could not open data sink! I’ll keep trying, but some output
may get lost… [1324649400] Event broker module
‘/usr/local/nagios/bin/ndomod.o’ initialized successfully.
How can I get it as it is in the log file?
If I may suggest, this is a better way for structuring the loop that outputs the log:
For solving the formatting problems, do as the other answers suggest, and output the log inside a
<pre></pre>tag