use of alma.ACSLoggingLog.NameValue in project ACS by ACS-Community.
the class AcsBinLogFormatter method formatBinary.
LogBinaryRecord formatBinary(LogRecord logRecord) {
LogBinaryRecord rLog = new LogBinaryRecord();
// log level
AcsLogLevel acsLevel = AcsLogLevel.getNativeLevel(logRecord.getLevel());
if (acsLevel == null) {
return null;
}
final AcsLogLevelDefinition acsCoreLevel = acsLevel.getAcsLevel();
// get date
Date date = new Date(logRecord.getMillis());
String TimeStamp = IsoDateFormat.formatDate(date);
LogParameterUtil logParamUtil = new LogParameterUtil(logRecord);
rLog.type = (short) acsCoreLevel.value;
rLog.TimeStamp = TimeStamp;
String file = logRecord.getSourceClassName();
if (file == null) {
if (acsCoreLevel == AcsLogLevelDefinition.DEBUG)
rLog.File = "unknown";
} else
rLog.File = file;
long line = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_LINE, -1);
if (line < 0) {
if (acsCoreLevel == AcsLogLevelDefinition.TRACE || acsCoreLevel == AcsLogLevelDefinition.DEBUG)
rLog.Line = 0;
} else
rLog.Line = (int) line;
String Routine = logRecord.getSourceMethodName();
if (Routine == null) {
if (acsCoreLevel == AcsLogLevelDefinition.TRACE) {
rLog.Routine = "unknown";
}
} else {
rLog.Routine = Routine;
}
// host name: may be different from local host if ErrorTrace gets logged
String hostName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_HOSTNAME, null);
if (hostName == null || hostName.length() == 0) {
hostName = getLocalHostName();
}
rLog.Host = hostName;
// String process = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_PROCESSNAME, null);
// if (process != null)
// rLog.Process = process;
// else{
String process = logRecord.getLoggerName();
if (process != null)
rLog.Process = "LoggerName: " + process;
else
rLog.Process = "";
// }
// source object: the container name or component name
String sourceObject = logRecord.getLoggerName();
if (sourceObject != null) {
rLog.SourceObject = sourceObject;
} else
rLog.SourceObject = "";
// add thread ID, or name if given
String threadName = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_THREAD_NAME, null);
if (threadName != null && threadName.length() > 0)
rLog.Thread = threadName;
else if (logRecord.getThreadID() >= 0)
rLog.Thread = "" + logRecord.getThreadID();
else
rLog.Thread = "";
// add context
String context = logParamUtil.extractStringProperty("Context", null);
if (context != null)
rLog.LogContext = context;
else
rLog.LogContext = "";
// add stack info
rLog.StackId = "";
rLog.StackLevel = 0;
if (acsCoreLevel.compareTo(AcsLogLevelDefinition.WARNING) >= 0) {
// add stack id
String stackId = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_STACK_ID, null);
if (stackId == null)
rLog.StackId = "unknown";
else
rLog.StackId = stackId;
// add stack idlevel
long stackLevel = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_STACK_LEVEL, -1);
if (stackLevel > 0)
rLog.StackLevel = (int) stackLevel;
}
// add log id
long logId = logRecord.getSequenceNumber();
if (logId >= 0)
rLog.LogId = "" + logId;
else
rLog.LogId = "";
// add URI
String uri = logParamUtil.extractStringProperty(LogParameterUtil.PARAM_URI, null);
if (uri != null)
rLog.Uri = uri;
else
rLog.Uri = "";
// add priority
// to be written only different as entry priority
long priority = logParamUtil.extractLongProperty(LogParameterUtil.PARAM_PRIORITY, acsCoreLevel.value);
if (priority != acsCoreLevel.value)
rLog.Priority = (int) priority;
else
rLog.Priority = -1;
// the log message becomes the text in our XML record
if (logRecord.getMessage() != null) {
rLog.MsgData = logRecord.getMessage();
} else
rLog.MsgData = "";
//add Audience, Array and Antenna, if applicable
if (logRecord instanceof AcsLogRecord) {
rLog.Audience = ((AcsLogRecord) logRecord).getAudience();
rLog.Array = ((AcsLogRecord) logRecord).getArray();
rLog.Antenna = ((AcsLogRecord) logRecord).getAntenna();
}
// <Data> elements: logged exception or error trace, and log parameters
//NameValue a;
//rLog.log_data = new NameValue[propertiesMap.size() + 1];
//TODO: see why there are not attributes here
rLog.attributes = new NameValue[0];
NameValue[] log_data = new NameValue[257];
//rLog.log_data = new NameValue[257];
int i = 0;
try {
// logged exception
Throwable loggedThrowable = logRecord.getThrown();
if (loggedThrowable != null) {
StringWriter exWriter = new StringWriter();
loggedThrowable.printStackTrace(new PrintWriter(exWriter));
log_data[i++] = new NameValue("LoggedException", exWriter.toString());
}
// log parameters (except for the special properties which were used already to set specific fields)
for (Object param : logParamUtil.getNonSpecialPropertiesMapParameters()) {
if (i >= 255)
break;
if (param instanceof Map) {
// any map that is not the special properties map we interpret as name-value pairs.
Map propertiesMap = (Map) param;
for (Object keyName : propertiesMap.keySet()) {
String value = propertiesMap.get(keyName).toString();
log_data[i++] = new NameValue(keyName.toString(), value);
}
} else {
// a single parameter was logged, but we have to fit it into our name-value scheme using a fake name
String value = param.toString();
log_data[i++] = new NameValue("LoggedParameter", value);
}
}
} catch (Exception e) {
// expected not to happen often at all, thus no try blocks inside every loop, so we may lose some <Data>
String value = e.toString();
log_data[i++] = new NameValue("DataConstructionError", value);
}
rLog.log_data = new NameValue[i];
for (int j = 0; j < i; j++) {
rLog.log_data[j] = log_data[j];
}
return rLog;
}
use of alma.ACSLoggingLog.NameValue in project ACS by ACS-Community.
the class AnyLogTest method packBinLogs.
static double packBinLogs() {
LogBinaryRecord s_log = new LogBinaryRecord();
// source info
s_log.type = (short) AcsLogLevelDefinition.INFO.value;
s_log.TimeStamp = "2007-12-12";
s_log.File = "filename";
s_log.Line = 21;
s_log.Routine = "routine";
s_log.Host = "host";
s_log.Process = "process";
s_log.Thread = "thread";
s_log.LogContext = "Context";
s_log.SourceObject = "SourceObject";
s_log.Audience = "Audience";
s_log.StackId = "Stackid";
s_log.StackLevel = 8;
s_log.LogId = "LogId";
s_log.Uri = "Uri";
s_log.Priority = 1;
NameValue[] aux = new NameValue[2];
aux[0] = new NameValue("name1", "value1");
aux[1] = new NameValue("name2", "value2");
int j;
s_log.log_data = new NameValue[2];
s_log.attributes = new NameValue[0];
for (j = 0; j < 2; j++) {
s_log.log_data[j] = aux[j];
}
s_log.MsgData = "I'm a message";
Date start = new Date();
LogBinaryRecordHelper.insert(bin_record, s_log);
Date end = new Date();
double elapsed = ((double) (end.getTime() - start.getTime()));
return elapsed;
}
use of alma.ACSLoggingLog.NameValue in project ACS by ACS-Community.
the class LogDispatcherTest method convertLogToBinary.
/**
* Convert a ILogEntry into a binary log
*
* @param The log to convert
* @return The binary log
*
*/
private LogBinaryRecord convertLogToBinary(ILogEntry log) throws Exception {
LogBinaryRecord logBin = new LogBinaryRecord();
logBin.Audience = (String) log.getField(LogField.AUDIENCE);
logBin.File = (String) log.getField(LogField.FILE);
logBin.Host = (String) log.getField(LogField.HOST);
Integer line = (Integer) log.getField(LogField.LINE);
if (line != null) {
logBin.Line = line;
} else {
logBin.Line = 0;
}
logBin.LogContext = (String) log.getField(LogField.CONTEXT);
logBin.LogId = (String) log.getField(LogField.LOGID);
logBin.MsgData = (String) log.getField(LogField.LOGMESSAGE);
Integer priority = (Integer) log.getField(LogField.PRIORITY);
if (priority != null) {
logBin.Priority = priority;
} else {
logBin.Priority = 0;
}
logBin.Process = (String) log.getField(LogField.PROCESS);
logBin.Routine = (String) log.getField(LogField.ROUTINE);
logBin.SourceObject = (String) log.getField(LogField.SOURCEOBJECT);
logBin.StackId = (String) log.getField(LogField.STACKID);
Integer stackL = (Integer) log.getField(LogField.STACKLEVEL);
if (stackL != null) {
logBin.StackLevel = stackL;
} else {
logBin.StackLevel = 0;
}
logBin.Thread = (String) log.getField(LogField.THREAD);
final Date date = new Date((Long) log.getField(LogField.TIMESTAMP));
logBin.TimeStamp = IsoDateFormat.formatDate(date);
logBin.type = (short) log.getType().ordinal();
logBin.Uri = (String) log.getField(LogField.URI);
if (log.hasDatas()) {
Vector<AdditionalData> data = log.getAdditionalData();
logBin.log_data = new NameValue[data.size()];
for (int t = 0; t < data.size(); t++) {
AdditionalData d = data.get(t);
logBin.log_data[t] = new NameValue(d.name, d.value);
}
}
return logBin;
}
Aggregations