Search in sources :

Example 1 with PwmLogEvent

use of password.pwm.util.logging.PwmLogEvent in project pwm by pwm-project.

the class LocalDBLoggerTest method makeEvents.

private Collection<PwmLogEvent> makeEvents(final RandomValueMaker randomValueMaker) {
    final int count = settings.batchSize;
    final Collection<PwmLogEvent> events = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        final String description = randomValueMaker.next();
        PwmLogEvent event = PwmLogEvent.createPwmLogEvent(Instant.now(), LocalDBLogger.class.getName(), description, "", "", null, null, PwmLogLevel.TRACE);
        events.add(event);
    }
    return events;
}
Also used : LocalDBLogger(password.pwm.util.logging.LocalDBLogger) ArrayList(java.util.ArrayList) PwmLogEvent(password.pwm.util.logging.PwmLogEvent)

Example 2 with PwmLogEvent

use of password.pwm.util.logging.PwmLogEvent in project pwm by pwm-project.

the class ExportLogsCommand method doCommand.

@Override
void doCommand() throws Exception {
    final LocalDB localDB = this.cliEnvironment.getLocalDB();
    final LocalDBStoredQueue logQueue = LocalDBStoredQueue.createLocalDBStoredQueue(null, localDB, LocalDB.DB.EVENTLOG_EVENTS);
    if (logQueue.isEmpty()) {
        out("no logs present");
        return;
    }
    final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
    out("outputting " + logQueue.size() + " log events to " + outputFile.getAbsolutePath() + "....");
    try (Writer outputWriter = new OutputStreamWriter(new FileOutputStream(outputFile), PwmConstants.DEFAULT_CHARSET)) {
        for (final Iterator<String> iter = logQueue.descendingIterator(); iter.hasNext(); ) {
            final String loopString = iter.next();
            final PwmLogEvent logEvent = PwmLogEvent.fromEncodedString(loopString);
            if (logEvent != null) {
                outputWriter.write(logEvent.toLogString());
                outputWriter.write("\n");
            }
        }
    }
    out("output complete");
}
Also used : LocalDBStoredQueue(password.pwm.util.localdb.LocalDBStoredQueue) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) LocalDB(password.pwm.util.localdb.LocalDB) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PwmLogEvent(password.pwm.util.logging.PwmLogEvent)

Aggregations

PwmLogEvent (password.pwm.util.logging.PwmLogEvent)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 LocalDB (password.pwm.util.localdb.LocalDB)1 LocalDBStoredQueue (password.pwm.util.localdb.LocalDBStoredQueue)1 LocalDBLogger (password.pwm.util.logging.LocalDBLogger)1