Skip to content

Commit

Permalink
Log.write
Browse files Browse the repository at this point in the history
for logging
  • Loading branch information
janvitek committed Apr 26, 2013
1 parent c297738 commit 2ee6bf9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
20 changes: 1 addition & 19 deletions src/main/java/water/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ private static long getPid() {
}
}

public static void write(String s) {
write(s, null);
}

public static void write(Throwable t) {
write(null, t);
}

public static void write(String s, Throwable t) {
String stack = "";
if( t != null ) {
Writer result = new StringWriter();
PrintWriter printWriter = new PrintWriter(result);
t.printStackTrace(printWriter);
stack = result.toString();
}
System.out.println(s != null ? s + " " + stack : stack);
}

// Print to the original STDERR & die
public static void die(String s) {
Expand Down Expand Up @@ -106,7 +88,7 @@ public static void unwrap(PrintStream stream, String s) {
stream.println(s);
}

public static void log(File file, PrintStream stream) throws Exception {
private static void log(File file, PrintStream stream) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(file));
try {
for( ;; ) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/water/api/RReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import water.*;
import water.H2O.H2OCountedCompleter;
import water.util.L;
import water.util.RString;

import com.google.gson.JsonObject;
Expand Down Expand Up @@ -36,13 +37,12 @@ protected Response serve() {
try {
final Value source_ = source;
final Key dest_ = dest;

H2O.submitTask(new H2OCountedCompleter() {
@Override public void compute2() {
try {
water.RReader.run(dest_, source_.openStream());
} catch( IOException e ) {
Log.write(e);
L.err(e);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/water/sys/NodeHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.Arrays;

import water.Boot;
import water.Log;
import water.sys.VM.Watchdog;
import water.util.L;

/**
* Creates a node on a host.
Expand Down Expand Up @@ -103,7 +103,7 @@ public void run() {
SSH.this.start();
SSH.this.waitFor();
} catch( Exception ex ) {
Log.write(ex);
L.err(ex);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/water/sys/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.lang.ArrayUtils;

import water.Log;
import water.util.L;

/**
* Executes code in a separate VM.
Expand Down Expand Up @@ -89,8 +90,7 @@ public boolean isAlive() {
} catch( IllegalThreadStateException _ ) {
return true;
} catch( Exception ex ) {
Log.write(ex);
throw new RuntimeException(ex);
throw new RuntimeException(L.err(ex));
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public void run() {
b = -1;
}
if( b < 0 ) {
Log.write("Assuming parent done, exit(0)");
L.info("Assuming parent done, exit(0)");
System.exit(0);
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/hex/KMeansTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package hex;

import java.util.Arrays;
import java.util.Random;

import org.junit.*;

import water.*;
import water.util.L;
import water.util.L.Tag.Sys;

public class KMeansTest extends TestUtil {
@BeforeClass public static void stall() { stall_till_cloudsize(3); }
Expand Down Expand Up @@ -51,11 +54,9 @@ public void testGaussian(int rows) {
cols[i] = i;

ValueArray va = va_maker(source, (Object[]) array);
long start = System.currentTimeMillis();
Timer t = new Timer();
KMeans.run(target, va, goals.length, 1e-6, cols);

long stop = System.currentTimeMillis();
Log.write("KMeansTest.testGaussian rows:" + rows + ", ms:" + (stop - start));
L.info(this,Sys.KMEAN," testGaussian rows:" + rows + ", ms:" + t);
KMeans.KMeansModel res = UKV.get(target);
double[][] clusters = res.clusters();

Expand Down Expand Up @@ -115,10 +116,9 @@ public void testAirline() {
Key k1 = loadAndParseKey("h.hex","smalldata/airlines/allyears2k.zip");
Key target = Key.make("air.kmeans");
ValueArray va = UKV.get(k1);
long start = System.currentTimeMillis();
Timer t = new Timer();
KMeans.run(target, va, 8, 1e-2, 0);
long stop = System.currentTimeMillis();
Log.write("KMeansTest.airlines: ms:" + (stop - start));
L.info(this,Sys.KMEAN,"ms= " + t);
KMeans.KMeansModel res = UKV.get(target);
double[][] clusters = res.clusters();
UKV.remove(k1);
Expand Down

0 comments on commit 2ee6bf9

Please sign in to comment.