JavaScript logging to a local file
Options
Hello!<br />
<br />
I was wondering if anyone could provide some feedback on an issue I have come across regarding log output inside the JavaScript editor. I did alot of searching around and found some great resources, the latest being <a class='bbc_url' href='http://wiki.eclipse.org/Logging_The_Events_-_Show_the_Typical_Log_Stack_(BIRT)'>http://wiki.eclipse.org/Logging_The_Events_-_Show_the_Typical_Log_Stack_(BIRT)</a>. I am able to get everything in the example to work except the call to fileHandler.setFormatter(new BirtEventFormatter()). If I comment this call out I get the output but in a fully bloated xml format.<br />
<br />
Here is a quick snippet of what I am working with now:<br />
~~ Inside initialize ~~<br />
// INTIALIZE THE LOGGER WITH A FILE BASED LOGGER<br />
importPackage(Packages.java.util.logging);<br />
importPackage(Packages.logging);<br />
<br />
var fileHandler = new FileHandler("c:/temp/javascript.log", false);<br />
<br />
try {<br />
fileHandler.setFormatter(new BirtEventFormatter());<br />
} catch (err) {}<br />
<br />
var rootLogger = Logger.getLogger("");<br />
rootLogger.addHandler(fileHandler);<br />
<br />
<br />
function log ( str ){<br />
Logger.getAnonymousLogger().info(str);<br />
}<br />
<br />
reportContext.setPersistentGlobalVariable("log", log);<br />
log("Initialize");<br />
<br />
~~ Inside afterFactory ~~<br />
log("after factory");<br />
<br />
var hdls = Logger.getLogger("").getHandlers();<br />
for (i = 0; i < hdls.length; i++) <br />
{<br />
Logger.getLogger("").removeHandler(hdls);<br />
hdls.close();<br />
}<br />
<br />
My current project is running inside BIRT 2.1 and the example is a 2.2 project which may have something to do with it. How ever it feels like I'm simply not linking to the Java file correctly, or that my report simply doesn't 'see' my BirtEventFormatter class. If anyone has any feedback on the issue I would greatly appreciate it
<br />
I was wondering if anyone could provide some feedback on an issue I have come across regarding log output inside the JavaScript editor. I did alot of searching around and found some great resources, the latest being <a class='bbc_url' href='http://wiki.eclipse.org/Logging_The_Events_-_Show_the_Typical_Log_Stack_(BIRT)'>http://wiki.eclipse.org/Logging_The_Events_-_Show_the_Typical_Log_Stack_(BIRT)</a>. I am able to get everything in the example to work except the call to fileHandler.setFormatter(new BirtEventFormatter()). If I comment this call out I get the output but in a fully bloated xml format.<br />
<br />
Here is a quick snippet of what I am working with now:<br />
~~ Inside initialize ~~<br />
// INTIALIZE THE LOGGER WITH A FILE BASED LOGGER<br />
importPackage(Packages.java.util.logging);<br />
importPackage(Packages.logging);<br />
<br />
var fileHandler = new FileHandler("c:/temp/javascript.log", false);<br />
<br />
try {<br />
fileHandler.setFormatter(new BirtEventFormatter());<br />
} catch (err) {}<br />
<br />
var rootLogger = Logger.getLogger("");<br />
rootLogger.addHandler(fileHandler);<br />
<br />
<br />
function log ( str ){<br />
Logger.getAnonymousLogger().info(str);<br />
}<br />
<br />
reportContext.setPersistentGlobalVariable("log", log);<br />
log("Initialize");<br />
<br />
~~ Inside afterFactory ~~<br />
log("after factory");<br />
<br />
var hdls = Logger.getLogger("").getHandlers();<br />
for (i = 0; i < hdls.length; i++) <br />
{<br />
Logger.getLogger("").removeHandler(hdls);<br />
hdls.close();<br />
}<br />
<br />
My current project is running inside BIRT 2.1 and the example is a 2.2 project which may have something to do with it. How ever it feels like I'm simply not linking to the Java file correctly, or that my report simply doesn't 'see' my BirtEventFormatter class. If anyone has any feedback on the issue I would greatly appreciate it
0
Comments
-
The reference to BirtEventFormatter is to a class that implements java.util.logging.Formatter to format a java.util.logging.LogRecord
Here is an example:
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class BirtEventFormatter extends Formatter{
public String format(LogRecord record) {
StringBuffer sb = new StringBuffer();
sb.append(record.getSourceClassName());
sb.append("t=>tt");
sb.append(record.getSourceMethodName());
if (!"".equals(record.getMessage())){
sb.append(" : ");
sb.append(record.getMessage());
}
sb.append("n");
return sb.toString();
}
}
Rob0 -
Heya!
Thanks for the reply I have a similarily (wow, is that spelled right??) defined java class that is in the project, I just can't seem to get my .rptdesign file to recognize it. When I pass in the BirtEventFormatter to the setFormatter method it doesn't know what the BirtEventFormatter is.
Anyway...0
Categories
- All Categories
- 111 Developer Announcements
- 49 Articles
- 103 General Questions
- 123 IM Services
- 40 OpenText Hackathon
- 31 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 897 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 123 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 1 XM Fax