| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons.logging; |
| 34 | | | |
| 35 | | | import java.util.Iterator; |
| 36 | | | import java.util.List; |
| 37 | | | import java.util.Set; |
| 38 | | | |
| 39 | | | import org.jcoderz.commons.BusinessImpact; |
| 40 | | | import org.jcoderz.commons.Category; |
| 41 | | | import org.jcoderz.commons.Loggable; |
| 42 | | | import org.jcoderz.commons.LoggableImpl; |
| 43 | | | import org.jcoderz.commons.types.Date; |
| 44 | | | |
| 45 | | | |
| 46 | | | |
| 47 | | | |
| 48 | | | |
| 49 | | | |
| 50 | | | |
| 51 | | | |
| 52 | | | |
| 53 | | (1) | public class LogElement |
| 54 | | | extends LogItem |
| 55 | | | { |
| 56 | | | private static final String TRACEMSG = "TRACEMSG"; |
| 57 | | | |
| 58 | | | private Loggable mLoggable; |
| 59 | | | private final java.util.logging.LogRecord mLogRecord; |
| 60 | | | private Throwable mThrown; |
| 61 | | | |
| 62 | | | |
| 63 | | | |
| 64 | | | |
| 65 | | | @param |
| 66 | | | |
| 67 | | | LogElement (final java.util.logging.LogRecord record) |
| 68 | 100 | | { |
| 69 | 100 | | mThrown = null; |
| 70 | 100 | | mLogRecord = record; |
| 71 | 100 | | Loggable loggable = null; |
| 72 | | | |
| 73 | 100 | | if (! ((record.getParameters() == null) |
| 74 | | | || record.getParameters().length == 0)) |
| 75 | | | { |
| 76 | 100 | | if (record.getParameters()[0] instanceof Loggable) |
| 77 | | | { |
| 78 | 100 | | loggable = (Loggable) record.getParameters()[0]; |
| 79 | | | } |
| 80 | | | } |
| 81 | 100 | | if (loggable != null) |
| 82 | | | { |
| 83 | 100 | | init(loggable); |
| 84 | | | } |
| 85 | | | else |
| 86 | | | { |
| 87 | 100 | | init(); |
| 88 | | | } |
| 89 | 100 | | } |
| 90 | | | |
| 91 | | | |
| 92 | | | |
| 93 | | | |
| 94 | | | |
| 95 | | | @param |
| 96 | | | @param |
| 97 | | | @param |
| 98 | | | |
| 99 | | | private LogElement ( |
| 100 | | | final java.util.logging.LogRecord record, |
| 101 | | | final Throwable thrown, |
| 102 | | | final LogElement parent) |
| 103 | 100 | | { |
| 104 | 100 | | mLogRecord = record; |
| 105 | 100 | | setParentItem(parent); |
| 106 | 100 | | init(thrown); |
| 107 | 100 | | } |
| 108 | | | |
| 109 | | | private void init () |
| 110 | | | { |
| 111 | 100 | | mLoggable = null; |
| 112 | 100 | | initData(); |
| 113 | | | |
| 114 | 100 | | final Throwable thrown = mLogRecord.getThrown(); |
| 115 | 100 | | if (thrown != null) |
| 116 | | | { |
| 117 | 100 | | setNestedItem(new LogElement(mLogRecord, thrown, this)); |
| 118 | | | } |
| 119 | 100 | | } |
| 120 | | | |
| 121 | | | private void init (Throwable thrown) |
| 122 | | | { |
| 123 | 100 | | if (thrown instanceof Loggable) |
| 124 | | | { |
| 125 | 100 | | init((Loggable) thrown); |
| 126 | | | } |
| 127 | | | else |
| 128 | | | { |
| 129 | 100 | | final Throwable nestedThrown = thrown.getCause(); |
| 130 | 100 | | mLoggable = null; |
| 131 | 100 | | mThrown = thrown; |
| 132 | 100 | | initData(); |
| 133 | 100 | | if (nestedThrown != null) |
| 134 | | | { |
| 135 | 100 | | setNestedItem(new LogElement(mLogRecord, nestedThrown, this)); |
| 136 | | | } |
| 137 | | | } |
| 138 | 100 | | } |
| 139 | | | |
| 140 | | | private void init (Loggable loggable) |
| 141 | | | { |
| 142 | 100 | | mLoggable = loggable; |
| 143 | 100 | | mThrown = null; |
| 144 | 100 | | initData(); |
| 145 | 100 | | if (loggable.getCause() != null) |
| 146 | | | { |
| 147 | 100 | | setNestedItem(new LogElement(mLogRecord, loggable.getCause(), this)); |
| 148 | | | } |
| 149 | 100 | | } |
| 150 | | | |
| 151 | | | private void initData () |
| 152 | | | { |
| 153 | 100 | | initType(); |
| 154 | 100 | | setLoggerLevel(mLogRecord.getLevel()); |
| 155 | 100 | | setSourceClass(mLogRecord.getSourceClassName()); |
| 156 | 100 | | setSourceMethod(mLogRecord.getSourceMethodName()); |
| 157 | 100 | | if (mLoggable != null) |
| 158 | | | { |
| 159 | 100 | | setBusinessImpact(mLoggable.getLogMessageInfo().getBusinessImpact()); |
| 160 | 100 | | setCategory(mLoggable.getLogMessageInfo().getCategory()); |
| 161 | 100 | | setInstanceId(mLoggable.getInstanceId()); |
| 162 | 100 | | setMessage(mLoggable.getMessage()); |
| 163 | 100 | | setNodeId(mLoggable.getNodeId()); |
| 164 | 100 | | setSolution(mLoggable.getLogMessageInfo().getSolution()); |
| 165 | 100 | | setSymbol(mLoggable.getLogMessageInfo().getSymbol()); |
| 166 | 100 | | setSymbolId( |
| 167 | | | Integer.toHexString(mLoggable.getLogMessageInfo().toInt())); |
| 168 | 100 | | setThreadId(mLoggable.getThreadId()); |
| 169 | | | try |
| 170 | | | { |
| 171 | 100 | | setThreadName(mLoggable.getThreadName()); |
| 172 | | | } |
| 173 | 0 | | catch (AbstractMethodError ex) |
| 174 | | | { |
| 175 | | | |
| 176 | | | |
| 177 | 0 | | setThreadName(Thread.currentThread().getName()); |
| 178 | 100 | | } |
| 179 | | | |
| 180 | 100 | | setTimestamp(Date.fromUtilDate( |
| 181 | | | new java.util.Date(mLoggable.getEventTime()))); |
| 182 | 100 | | setTrackingNumber(mLoggable.getTrackingNumber()); |
| 183 | 100 | | setParameters(); |
| 184 | 100 | | if (mLoggable instanceof Throwable) |
| 185 | | | { |
| 186 | 100 | | initStackTrace((Throwable) mLoggable); |
| 187 | | | } |
| 188 | | | } |
| 189 | 100 | | else if (mThrown != null) |
| 190 | | | { |
| 191 | 100 | | setMessage(mThrown.getMessage()); |
| 192 | 100 | | initStackTrace(mThrown); |
| 193 | | | } |
| 194 | | | else |
| 195 | | | { |
| 196 | 100 | | setBusinessImpact(BusinessImpact.UNDEFINED); |
| 197 | 100 | | setCategory(Category.TECHNICAL); |
| 198 | 100 | | setInstanceId(LoggableImpl.INSTANCE_ID); |
| 199 | 100 | | setMessage(mLogRecord.getMessage()); |
| 200 | 100 | | setNodeId(LoggableImpl.NODE_ID); |
| 201 | 100 | | setSymbol(TRACEMSG); |
| 202 | 100 | | setSymbolId(TRACEMSG); |
| 203 | 100 | | setThreadId(mLogRecord.getThreadID()); |
| 204 | 100 | | setThreadName(Thread.currentThread().getName()); |
| 205 | 100 | | setTimestamp(Date.fromLong(mLogRecord.getMillis())); |
| 206 | 100 | | setTrackingNumber(Integer.toHexString( |
| 207 | | | (int) mLogRecord.getSequenceNumber())); |
| 208 | | | } |
| 209 | 100 | | } |
| 210 | | | |
| 211 | | | private void setParameters () |
| 212 | | | { |
| 213 | 100 | | if (mLoggable != null) |
| 214 | | | { |
| 215 | 100 | | final Set names = mLoggable.getParameterNames(); |
| 216 | 100 | | if (names != null && ! names.isEmpty()) |
| 217 | | | { |
| 218 | 100 | | for (final Iterator iter = names.iterator(); iter.hasNext(); ) |
| 219 | | | { |
| 220 | 100 | | final String name = (String) iter.next(); |
| 221 | 100 | | if (! name.startsWith(INTERNAL_PARAMETER_PREFIX)) |
| 222 | | | { |
| 223 | 100 | | final List parameters = mLoggable.getParameter(name); |
| 224 | 100 | | addToParameters(name, parameters); |
| 225 | | | } |
| 226 | 100 | | } |
| 227 | | | } |
| 228 | | | } |
| 229 | 100 | | } |
| 230 | | | |
| 231 | | | private void initStackTrace (final Throwable thrown) |
| 232 | | | { |
| 233 | | | |
| 234 | 100 | | } |
| 235 | | | |
| 236 | | | |
| 237 | | | private void initType () |
| 238 | | | { |
| 239 | 100 | | if (mLoggable == null) |
| 240 | | | { |
| 241 | 100 | | if (getParentItem() == null) |
| 242 | | | { |
| 243 | 100 | | if (mLogRecord.getThrown() == null) |
| 244 | | | { |
| 245 | 100 | | setType(String.valueOf( |
| 246 | | | LogLineFormat.TRACE_MESSAGE.getTypeSpecifier())); |
| 247 | | | } |
| 248 | | | else |
| 249 | | | { |
| 250 | 100 | | setType(String.valueOf( |
| 251 | | | LogLineFormat.EXCEPTION_MESSAGE.getTypeSpecifier())); |
| 252 | | | } |
| 253 | | | } |
| 254 | | | } |
| 255 | | | else |
| 256 | | | { |
| 257 | 100 | | if ((mLoggable.getCause() == null) || ( |
| 258 | | | mLoggable.getCause() instanceof Loggable)) |
| 259 | | | { |
| 260 | 100 | | setType(String.valueOf( |
| 261 | | | LogLineFormat.LOG_MESSAGE.getTypeSpecifier())); |
| 262 | | | } |
| 263 | | | else |
| 264 | | | { |
| 265 | 100 | | setType(String.valueOf( |
| 266 | | | LogLineFormat.ERROR_MESSAGE.getTypeSpecifier())); |
| 267 | | | } |
| 268 | | | } |
| 269 | 100 | | } |
| 270 | | | } |