Home
Analytics
using PrintWriter in BIRT
neetira
Hi
I have used the following in the initialize function of a BIRT report:
importPackage(Packages.java.io);
fos = FileOutputStream("C:logFile1.txt");
printWriter = PrintWriter(fos);
printWriter.println("ReportDesign.Initialize");
the file "logFile1.txt" is created, but nothing is written in it.
I saw in a lot of examples that "ReportDesign.Initialize" should be present in it.
Is this the right way to use PrintWriter?
I have :
var myid = request.getAttribute("a1");
printWriter.println(myid) ; OR printWriter.println("myid);
I want the value present in "myid" to be written in the logFile1.txt.
How do I do this?
thanks
Neeti
Find more posts tagged with
Comments
cypherdj
Try the following instead:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.io);
logFileName = "c:/Work/tools/apache-tomcat-5.5.25/logs/birt.log";
out = new PrintWriter(new FileWriter(logFileName, true)); // creates a new print writer to output log statements to
out.println("Entering myReport.initialise");
var myid = request.getAttribute("a1");
out.println(myid);
out.close();
</pre>
<br />
Regards,<br />
Cedric
neetira
thanks a lot, cypherdj . it worked....
do you know why it didnt work when i used FileOutputStream?
neeti
cypherdj
Hi Neeti,<br />
<br />
from the code you posted, you missed the keyword "new" when creating the FileOutputStream and PrintWriter. Your code would probably work if you added them like :<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.io);
fos = new FileOutputStream("C:logFile1.txt");
printWriter = new PrintWriter(fos);
printWriter.println("ReportDesign.Initialize");
</pre>
neetira
hi cypherdj
I tried the code which you showed. It still didnt work.
neeti
dingdong
write this at the end.. it shud work:
printWriter.flush();
gowtham
<p>How to get the entire query in a text file after running the report?</p>
<p> </p>
<p>I am using some replace script in my query which ends with error.. I need to validate the query.</p>
<p>If i get its output after execution i can validate.</p>
JFreeman
<p>You can output the final this.queryText in the beforeOpen of the Data Set.</p>
<p> </p>
<p>I believe the FileOutputStream code from earlier in this thread should work for that. Otherwise, you could also implement a java logger from java.util.logging.</p>
gowtham
<p>Hi Freeman,</p>
<p> </p>
<p>I tried the code mentioned above. its not working. </p>
<p>Could you please guide me what exactly to be placed in before open.</p>
<p> </p>
<p>Thanks in advance.</p>
JFreeman
<p>In the beforeOpen of the Data Set you can use code like the following to write to a file.</p>
<pre class="_prettyXprint _lang-js">
importClass(java.io.File);
importClass(java.io.FileOutputStream);
var logFileLocation = new File("c:/temp/bdoutputlog.log");
var outputStream = new FileOutputStream(logFileLocation);
if (!logFileLocation.exists()) {
logFileLocation.createNewFile();
}
var contentInBytes = this.queryText.getBytes();
outputStream.write(contentInBytes);
outputStream.flush();
outputStream.close();</pre>
gowtham
<p><span style="color:#8b4513;">Thanks <span style="font-family:arial, helvetica, sans-serif;">Jesse.. It's working fine.</span></span></p>
JFreeman
<p>You're welcome.</p>
<p> </p>
<p>Let us know if you have any additional questions.</p>