use of alma.acs.util.IsoDateFormat in project ACS by ACS-Community.
the class CacheUtils method generateLogsType.
/**
* Generate a set of logs of a given type
* Each log has
* - a different time stamp.
* - the message contains the key of the log
*
* @param numOfLogs The number of logs to put in the collection
* @return The collection with the logs
*/
public static Collection<ILogEntry> generateLogsType(int numOfLogs, LogTypeHelper logType) throws Exception {
if (logType == LogTypeHelper.OFF) {
throw new IllegalArgumentException("Cannot publish logs with level OFF");
}
Random rnd = new Random(Calendar.getInstance().getTimeInMillis());
// Yesterday
long now = Calendar.getInstance().getTimeInMillis() - 1000 * 60 * 60 * 24;
SimpleDateFormat df = new IsoDateFormat();
Vector<ILogEntry> v = new Vector<ILogEntry>(numOfLogs);
for (int t = 0; t < numOfLogs; t++) {
Date dt = new Date(now + t * 1000);
StringBuffer dateSB = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
df.format(dt, dateSB, pos);
StringBuilder logStr = new StringBuilder("<");
if (logType == LogTypeHelper.TRACE) {
logType = LogTypeHelper.INFO;
}
logStr.append(logType.logEntryType);
logStr.append(logHeaderStr);
logStr.append(dateSB.toString());
logStr.append(logBodyStr);
logStr.append(t);
logStr.append(logFooterStr);
logStr.append(logType.logEntryType);
logStr.append('>');
if (parser == null) {
parser = ACSLogParserFactory.getParser();
}
ILogEntry log = parser.parse(logStr.toString());
v.add(log);
}
return v;
}
Aggregations