logging
This commit is contained in:
parent
1c49362415
commit
c499e5977c
4 changed files with 43 additions and 11 deletions
13
app/src/main/assets/OpenAPSAMA/loggerhelper.js
Normal file
13
app/src/main/assets/OpenAPSAMA/loggerhelper.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
var console = { };
|
||||||
|
console.error = function error(){
|
||||||
|
console2.error(arguments.length);
|
||||||
|
for (var i = 0, len = arguments.length; i < len; i++) {
|
||||||
|
console2.error(arguments[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log = function log(){
|
||||||
|
for (var i = 0, len = arguments.length; i < len; i++) {
|
||||||
|
console2.log(arguments[i]);
|
||||||
|
}
|
||||||
|
};
|
|
@ -85,7 +85,8 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
//register logger callback for console.log and console.error
|
//register logger callback for console.log and console.error
|
||||||
ScriptableObject.defineClass(scope, LoggerCallback.class);
|
ScriptableObject.defineClass(scope, LoggerCallback.class);
|
||||||
Scriptable myLogger = rhino.newObject(scope, "LoggerCallback", null);
|
Scriptable myLogger = rhino.newObject(scope, "LoggerCallback", null);
|
||||||
scope.put("console", scope, myLogger);
|
scope.put("console2", scope, myLogger);
|
||||||
|
rhino.evaluateString(scope, readFile("OpenAPSAMA/loggerhelper.js"), "JavaScript", 0, null);
|
||||||
|
|
||||||
//set module parent
|
//set module parent
|
||||||
rhino.evaluateString(scope, "var module = {\"parent\":Boolean(1)};", "JavaScript", 0, null);
|
rhino.evaluateString(scope, "var module = {\"parent\":Boolean(1)};", "JavaScript", 0, null);
|
||||||
|
@ -98,8 +99,6 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
Object determineBasalObj = scope.get("determine_basal", scope);
|
Object determineBasalObj = scope.get("determine_basal", scope);
|
||||||
Object setTempBasalFunctionsObj = scope.get("tempBasalFunctions", scope);
|
Object setTempBasalFunctionsObj = scope.get("tempBasalFunctions", scope);
|
||||||
|
|
||||||
Object testParam = makeParamArray(mIobData, rhino, scope);
|
|
||||||
|
|
||||||
//call determine-basal
|
//call determine-basal
|
||||||
if (determineBasalObj instanceof Function && setTempBasalFunctionsObj instanceof NativeObject) {
|
if (determineBasalObj instanceof Function && setTempBasalFunctionsObj instanceof NativeObject) {
|
||||||
Function determineBasalJS = (Function) determineBasalObj;
|
Function determineBasalJS = (Function) determineBasalObj;
|
||||||
|
@ -115,6 +114,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
setTempBasalFunctionsObj};
|
setTempBasalFunctionsObj};
|
||||||
|
|
||||||
NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params);
|
NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params);
|
||||||
|
scriptDebug = LoggerCallback.getScriptDebug();
|
||||||
|
|
||||||
// Parse the jsResult object to a JSON-String
|
// Parse the jsResult object to a JSON-String
|
||||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||||
|
|
|
@ -82,10 +82,7 @@ public class DetermineBasalAdapterMAJS {
|
||||||
Function determineBasalJS = (Function) determineBasalObj;
|
Function determineBasalJS = (Function) determineBasalObj;
|
||||||
Function setTempBasalJS = (Function) setTempBasalObj;
|
Function setTempBasalJS = (Function) setTempBasalObj;
|
||||||
|
|
||||||
Object testParam = makeParam(mIobData, rhino, scope);
|
//prepare parameters
|
||||||
|
|
||||||
|
|
||||||
//prepare parameters
|
|
||||||
Object[] params = new Object[]{
|
Object[] params = new Object[]{
|
||||||
makeParam(mGlucoseStatus, rhino, scope),
|
makeParam(mGlucoseStatus, rhino, scope),
|
||||||
makeParam(mCurrentTemp, rhino, scope),
|
makeParam(mCurrentTemp, rhino, scope),
|
||||||
|
|
|
@ -16,9 +16,14 @@ public class LoggerCallback extends ScriptableObject {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
|
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
|
||||||
|
|
||||||
|
static StringBuffer errorBuffer = new StringBuffer();
|
||||||
|
static StringBuffer logBuffer = new StringBuffer();
|
||||||
|
|
||||||
|
|
||||||
public LoggerCallback() {
|
public LoggerCallback() {
|
||||||
//empty constructor needed for Rhino
|
//empty constructor needed for Rhino
|
||||||
|
errorBuffer = new StringBuffer();
|
||||||
|
logBuffer = new StringBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,11 +35,28 @@ public class LoggerCallback extends ScriptableObject {
|
||||||
//empty constructor on JS site; could work as setter
|
//empty constructor on JS site; could work as setter
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jsFunction_log(String s) {
|
public void jsFunction_log(Object obj1) {
|
||||||
log.debug(s);
|
log.debug(obj1.toString());
|
||||||
|
logBuffer.append(obj1.toString());
|
||||||
|
logBuffer.append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jsFunction_error(String s) {
|
public void jsFunction_error(Object obj1) {
|
||||||
log.error(s);
|
log.error(obj1.toString());
|
||||||
|
errorBuffer.append(obj1.toString());
|
||||||
|
errorBuffer.append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String getScriptDebug(){
|
||||||
|
String ret = "";
|
||||||
|
if(errorBuffer.length() >= 0){
|
||||||
|
ret += "e:\n" + errorBuffer.toString();
|
||||||
|
}
|
||||||
|
if(logBuffer.length() >= 0){
|
||||||
|
ret += "d:\n" + logBuffer.toString();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue