A.1 Reporting
We have already introduced the StatisticReporter
class. Beside the ability to create a string representation of a half-width summary statistical report, the class has the ability to create a string representation of the report as a LaTeX table. Also found in the jsl.utilities.reporting
package is the JSL
class. This class provide ready access to methods to create text files and to write to text files. It has a static field called out
that is a PrintWriter
. Thus, the field can be used globally to write out to a text file called jslOutput.txt
that is written into the jslOutput
directory.
// write string to file jslOutput.txt found in directory jslOutput
// JSL.out can be used just like System.out except text goes to a file
.out.println("Hello World!"); JSL
One nice feature of using JSL.out
is that the output can be turned off. The field out
is actually an instance of LogPrintWriter
, which provides very simple logging capabilities. By setting out.OUTPUT_ON = false
all writing via JSL.out
will not happen. When doing small programs, this can be useful for debugging and tracing; however, this is no substitute for using a full logger. The JSL supports logging through the SL4J logging facade. While SL4J loggers can and should be used anywhere in your code, if you want a simple global logger that is already set up, you can used the JSL.LOGGER
field.
In addition, the JSL
class facilitates the creation of files and instances of PrintWriter
that automatically catch the I/O exceptions through various static methods.
// make a file and write some data to it, file will be directory jslOutput, by default
PrintWriter writer = JSL.makePrintWriter("data", "csv");
There are methods to make instances of java’s File
class, make PrintWriter
instances, get a path to the working directory and cause JSL.out
to be redirected to the console. Please see the java docs for additional details.