added shortcut for logging to any file directly from test scripts

This commit is contained in:
fros4943 2010-02-03 09:32:25 +00:00
parent 8e11e600ec
commit 26e15fe4f1

View file

@ -26,11 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: LogScriptEngine.java,v 1.21 2009/10/28 15:34:34 fros4943 Exp $ * $Id: LogScriptEngine.java,v 1.22 2010/02/03 09:32:25 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.lang.reflect.UndeclaredThrowableException; import java.lang.reflect.UndeclaredThrowableException;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Observable; import java.util.Observable;
@ -361,6 +364,16 @@ public class LogScriptEngine {
scriptLogObserver.update(null, msg); scriptLogObserver.update(null, msg);
} }
} }
public void append(String filename, String msg) {
try{
FileWriter fstream = new FileWriter(filename, true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(msg);
out.close();
} catch (Exception e) {
logger.warn("Test append failed: " + filename + ": " + e.getMessage());
}
}
public void testOK() { public void testOK() {
log("TEST OK\n"); log("TEST OK\n");