@@ -40,6 +40,8 @@ public class PrismFileLog extends PrismPrintStreamLog
4040 protected String filename ;
4141 /** Are we writing to stdout? */
4242 protected boolean stdout ;
43+ /** Are we using native code to write to the file? */
44+ protected boolean nativeCode ;
4345
4446 /**
4547 * Create a {@link PrismLog} which will write to {@code filename}, overwriting any previous contents.
@@ -61,7 +63,7 @@ public PrismFileLog(String filename) throws PrismException
6163 */
6264 public PrismFileLog (String filename , boolean append ) throws PrismException
6365 {
64- this (filename , append , true );
66+ this (filename , append , false );
6567 }
6668
6769 /**
@@ -87,6 +89,7 @@ private void createLogStream(String filename, boolean append, boolean nativeCode
8789 {
8890 this .filename = filename ;
8991 this .stdout = "stdout" .equals (filename );
92+ this .nativeCode = nativeCode ;
9093 try {
9194 if (nativeCode ) {
9295 setPrintStream (new PrismFileLogNative (filename , append ));
@@ -102,6 +105,20 @@ private void createLogStream(String filename, boolean append, boolean nativeCode
102105 }
103106 }
104107
108+ /**
109+ * Ensure the log is using native code to write to the file.
110+ * If this is currently not the case, this method will {@code close()}
111+ * the current log and open a new equivalent one using native code.
112+ * Throw a PRISM exception if there is a problem opening the file for writing.
113+ */
114+ public void useNative () throws PrismException
115+ {
116+ if (!nativeCode ) {
117+ close ();
118+ createLogStream (filename , true , true );
119+ }
120+ }
121+
105122 /**
106123 * Get the filename (or "stdout" if writing to standard output)
107124 **/
@@ -110,6 +127,14 @@ public String getFileName()
110127 return stdout ? "stdout" : filename ;
111128 }
112129
130+ /**
131+ * Is this log using native code to write to the file?
132+ */
133+ public boolean isNative ()
134+ {
135+ return nativeCode ;
136+ }
137+
113138 // Methods for PrismLog
114139
115140 @ Override
@@ -161,6 +186,19 @@ public static PrismFileLog create(String filename, boolean append) throws PrismE
161186 return new PrismFileLog (filename , append );
162187 }
163188
189+ /**
190+ * Create a {@link PrismLog} which will write to {@code filename}, appending to an existing file if requested.
191+ * If {@code filename} is "stdout", then output will be written to standard output.
192+ * Throw a PRISM exception if there is a problem opening the file for writing.
193+ * @param filename Filename of log file
194+ * @param append Append to the existing file?
195+ * @param nativeCode Use native code to write to the file?
196+ */
197+ public static PrismFileLog create (String filename , boolean append , boolean nativeCode ) throws PrismException
198+ {
199+ return new PrismFileLog (filename , append , nativeCode );
200+ }
201+
164202 /**
165203 * Create a {@link PrismLog} which will write to standard output.
166204 */
0 commit comments