Search in sources :

Example 21 with IsoDateFormat

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;
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) IsoDateFormat(alma.acs.util.IsoDateFormat) FieldPosition(java.text.FieldPosition) Date(java.util.Date) Random(java.util.Random) SimpleDateFormat(java.text.SimpleDateFormat) Vector(java.util.Vector)

Aggregations

IsoDateFormat (alma.acs.util.IsoDateFormat)21 Date (java.util.Date)20 SimpleDateFormat (java.text.SimpleDateFormat)15 FieldPosition (java.text.FieldPosition)10 ILogEntry (com.cosylab.logging.engine.log.ILogEntry)9 ACSLogParser (alma.acs.logging.engine.parser.ACSLogParser)5 IOException (java.io.IOException)3 Vector (java.util.Vector)3 FileHelper (alma.acs.logging.archive.zoom.FileHelper)2 LogField (com.cosylab.logging.engine.log.LogField)2 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Random (java.util.Random)2 ParserTypes (alma.acs.logging.engine.parser.ACSLogParserFactory.ParserTypes)1 DataItem (cl.utfsm.samplingSystemUI.core.DataItem)1 LogParseException (com.cosylab.logging.engine.ACS.LogParseException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 JFileChooser (javax.swing.JFileChooser)1