1 2 12 package com.versant.core.logging; 13 14 import java.io.Serializable ; 15 16 21 public abstract class LogEvent implements Serializable { 22 23 protected int id; 24 protected String remoteClient; 25 protected String userString; 26 protected long datastoreTxId; 27 protected long start; 28 protected int totalMs; 29 protected String errorMsg; 30 31 private static int lastId; 32 33 private static ThreadLocal contextStore = new ThreadLocal (); 34 35 36 37 38 42 public static class Context { 43 public String remoteClient; 44 public String userString; 45 } 46 47 public LogEvent() { 48 id = ++lastId; 49 Context c = getContext(); 50 remoteClient = c.remoteClient; 51 userString = c.userString; 52 totalMs = -1; 53 start = System.currentTimeMillis(); 54 } 55 56 59 public static Context getContext() { 60 61 Context c = (Context)contextStore.get(); 62 if (c == null) contextStore.set(c = new Context()); 63 return c; 64 65 66 } 67 68 71 public static int getLastId() { 72 return lastId; 73 } 74 75 public long getStart() { 76 return start; 77 } 78 79 public final int getId() { 80 return id; 81 } 82 83 public long getDatastoreTxId() { 84 return datastoreTxId; 85 } 86 87 public void setDatastoreTxId(long datastoreTxId) { 88 this.datastoreTxId = datastoreTxId; 89 } 90 91 public int getTotalMs() { 92 return totalMs; 93 } 94 95 public void setTotalMs(int totalMs) { 96 this.totalMs = totalMs; 97 } 98 99 public void updateTotalMs() { 100 totalMs = (int)(System.currentTimeMillis() - start); 101 } 102 103 public void zeroTotalMs() { 104 totalMs = 0; 105 } 106 107 public String getErrorMsg() { 108 return errorMsg; 109 } 110 111 public void setErrorMsg(String errorMsg) { 112 this.errorMsg = errorMsg; 113 } 114 115 public void setErrorMsg(Throwable t) { 116 errorMsg = t.getClass().getName() + ": " + t.getMessage(); 117 } 118 119 public boolean getOk() { 120 return errorMsg == null; 121 } 122 123 public String getRemoteClient() { 124 if (remoteClient == null) { 125 return userString; 126 } else if (userString == null) { 127 return remoteClient; 128 } else { 129 return remoteClient + " - " + userString; 130 } 131 } 132 133 136 public abstract String getName(); 137 138 141 public abstract String getDescription(); 142 143 147 public void setDescription(String s) { 148 } 149 150 public String toString() { 151 String d = getDescription(); 152 if (d == null) return getName(); 153 else return getName() + " " + d; 154 } 155 156 160 public boolean isOwnTab() { 161 return false; 162 } 163 164 167 public int getType() { 168 return 0; 169 } 170 171 } 172 | Popular Tags |