| 1116 | } |
| 1117 | |
| 1118 | private static void log(Level level, String msg) { |
| 1119 | if (OSPRuntime.dontLog) |
| 1120 | return; |
| 1121 | LogRecord record = new LogRecord(level, msg); |
| 1122 | |
| 1123 | String className = null, methodName = null; |
| 1124 | if (OSPRuntime.isJS) { |
| 1125 | |
| 1126 | OSPRuntime.showStatus("OSPLog[" + level + "] " + msg); |
| 1127 | |
| 1128 | try { |
| 1129 | /** |
| 1130 | * @j2sNative var o = arguments.callee.caller.caller; methodName = o && |
| 1131 | * o.exName; className = o && o.exClazz && o.exClazz.__CLASS_NAME__; |
| 1132 | */ |
| 1133 | } catch (Throwable t) { |
| 1134 | // ignore -- something went wrong |
| 1135 | } |
| 1136 | } else { |
| 1137 | StackTraceElement stack[] = (new Throwable()).getStackTrace(); |
| 1138 | // find the first method not in class OSPLog |
| 1139 | for(int i = 0; i<stack.length; i++) { |
| 1140 | StackTraceElement el = stack[i]; |
| 1141 | className = el.getClassName(); |
| 1142 | if(!className.equals("org.opensourcephysics.controls.OSPLog")) { //$NON-NLS-1$ |
| 1143 | // set the source class and method |
| 1144 | methodName = el.getMethodName(); |
| 1145 | break; |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | if (methodName != null) { |
| 1150 | record.setSourceClassName(className); |
| 1151 | record.setSourceMethodName(methodName); |
| 1152 | } |
| 1153 | |
| 1154 | if(OSPLOG!=null) { |
| 1155 | OSPLOG.getLogger().log(record); |
| 1156 | } else { |
| 1157 | messageStorage[messageIndex++] = record; |
| 1158 | messageIndex = messageIndex%messageStorage.length; |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * A class that formats a record as if this were the console. |