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;
}
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");
}
Aggregations