use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class LogEntry method toXMLString.
/**
* @return an XML string representing this log
*/
public String toXMLString() {
StringBuilder sb = new StringBuilder();
String logType = type.logEntryType;
sb.append("<" + logType);
for (LogField t : LogField.values()) {
if (t == LogField.LOGMESSAGE || t == LogField.ENTRYTYPE) {
continue;
}
Object attrValue = getField(t);
if (attrValue != null) {
if (t == LogField.TIMESTAMP) {
SimpleDateFormat df = new IsoDateFormat();
Date dt = new Date((Long) attrValue);
StringBuffer dateSB = new StringBuffer();
java.text.FieldPosition pos = new java.text.FieldPosition(0);
df.format(dt, dateSB, pos);
attrValue = dateSB.toString();
}
String attrValStr = attrValue.toString();
attrValStr = attrValStr.replaceAll("<", "<");
attrValStr = attrValStr.replaceAll(">", ">");
sb.append(" " + t.getTagAttribute() + "=\"" + attrValStr + "\"");
}
}
if (type == LogTypeHelper.TRACE && !hasDatas() && logMessage != null && logMessage.trim().isEmpty()) {
sb.append("/>");
} else {
sb.append(">");
if (logMessage != null) {
sb.append("<![CDATA[" + logMessage + "]]>");
}
if (hasDatas()) {
sb.append(getXMLDatas());
}
sb.append("</" + logType + ">");
}
return sb.toString();
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class LogEntryTable method getCellStringContent.
/**
* Get a string representing the content of a cell
*
* @param row The table row of the cell
* @param col The table column of the cell
*
* @return A string representing the content of the cell
*/
private String getCellStringContent(int row, int col) {
Object value = getValueAt(row, col);
if (value == null) {
return "";
}
String tempStr = "";
if (value instanceof Date) {
IsoDateFormat sdf = new IsoDateFormat();
tempStr = sdf.format(value);
} else if (value instanceof Integer) {
if (getColumnName(col).compareTo(LogField.ENTRYTYPE.getName()) == 0) {
tempStr = LogTypeHelper.values()[((Integer) value).intValue()].logEntryType;
} else {
tempStr = value.toString();
}
} else {
tempStr = value.toString();
}
return tempStr;
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class CSVConverter method convert.
/**
* Convert a log in a CSV string
*
* @param log The log to convert
* @return The CSV string representing the log
*/
public String convert(ILogEntry log) {
if (log == null) {
throw new IllegalArgumentException("Impossible to convert a null log");
}
StringBuilder str = new StringBuilder();
SimpleDateFormat df = new IsoDateFormat();
for (int t = 0; t < colIndex.length(); t++) {
if (t > 0) {
str.append(separator);
}
Character c = Character.toUpperCase(colIndex.charAt(t));
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= Character.toUpperCase(LogField.values()[LogField.values().length - 1].id))) {
LogField field = LogField.fromID(c);
Object obj = log.getField(field);
if (obj == null) {
appendField(null, str);
} else if (field == LogField.TIMESTAMP) {
// Write the date in the right format
Date dt = new Date(((Long) obj).longValue());
StringBuffer dateSB = new StringBuffer();
java.text.FieldPosition pos = new java.text.FieldPosition(0);
df.format(dt, dateSB, pos);
appendField(dateSB.toString(), str);
} else if (field == LogField.ENTRYTYPE) {
appendField(LogTypeHelper.fromLogTypeDescription(obj.toString()).logEntryType, str);
} else {
appendField(obj.toString(), str);
}
} else {
// DATA
if (log.hasDatas()) {
appendField(formatData(log.getAdditionalData()), str);
} else {
appendField(null, str);
}
}
}
str.append('\n');
return str.toString();
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class FileHelperTest method testLoadFilterAll.
/**
* Test the loading of logs between a defined time interval
* and a definit log level interval
*/
public void testLoadFilterAll() throws Exception {
IsoDateFormat dateFormat = new IsoDateFormat();
Date startDate = dateFormat.parse("2008-09-19T11:21:49.500");
Date endDate = dateFormat.parse("2008-09-19T11:21:49.600");
fileHelper = new FileHelper(testFile, startDate.getTime(), endDate.getTime(), LogTypeHelper.DEBUG, LogTypeHelper.NOTICE);
numOfLogsRead = 0;
assertTrue(fileHelper.loadLogs(this, this, this));
assertEquals(15, numOfLogsRead);
}
use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class CacheTest method fillCache.
/**
* Fill the cache with dynamically generated logs
* The number of logs inserted in the list is greater than the
* memory cache size to stress the disk cache also.
*
* @return The number of logs inserted in the cache
*
* @throws Exception
*/
private long fillCache() throws Exception {
ACSLogParser parser = ACSLogParserFactory.getParser();
String logMsg = "Test log nr. ";
// Yesterday
long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
SimpleDateFormat df = new IsoDateFormat();
cache.clear();
long logToInsert = 2 * cache.getCacheSize();
for (int t = 0; t < logToInsert; t++) {
Date dt = new Date(now + t * 1000);
StringBuffer dateSB = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
df.format(dt, dateSB, pos);
String newLogMsg = logMsg + "t";
StringBuilder logStr = new StringBuilder("<Info TimeStamp=\"");
logStr.append(dateSB.toString());
logStr.append("\" Routine=\"CacheTest::testGet\" Host=\"this\" Process=\"test\" Thread=\"main\" Context=\"\"><![CDATA[");
logStr.append(newLogMsg);
logStr.append("]]></Info>");
ILogEntry newLog = parser.parse(logStr.toString());
cache.add(newLog);
}
return logToInsert;
}
Aggregations