use of alma.Logging.XmlLogRecord in project ACS by ACS-Community.
the class TestAcsXMLLogFormatter method writeRecords.
@Override
protected void writeRecords(XmlLogRecord[] remoteLogRecords) {
for (XmlLogRecord remoteLogRecord : remoteLogRecords) {
String xmlLogRecord = remoteLogRecord.xml;
xmlLogRecordList.add(xmlLogRecord);
if (verbose) {
System.out.println(xmlLogRecord.toString());
}
}
if (verbose) {
System.out.println("--------end writeRecords-------");
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of alma.Logging.XmlLogRecord in project ACS by ACS-Community.
the class RemoteLogDispatcher method sendLogRecords.
/**
* Attempts to send <code>logRecords</code> over to the remote logging service.
* To not lose any log records in case of failure, they can be obtained from the returned
* <code>FailedLogRecords</code> object, and should be fed back to the log record queue in order to try again later.
* <p>
* Should not be called concurrently (which can't happen since we use a single threaded executor
* in <code>DispatchingLogQueue</code>).
* <p>
* Sorts all log records by timestamp before converting them for remote transmission.
*
* @param logRecords
* @return those LogRecords that failed to be sent, either because they could not be converted to Any,
* or because the remote logger failed.
*/
FailedLogRecords sendLogRecords(LogRecord[] logRecords) {
// sort this set of records by timestamp (queue delivers them by level/timestamp)
Arrays.sort(logRecords, timestampLogRecordComparator);
FailedLogRecords failures = new FailedLogRecords();
// used for feeding back these LogRecords if the sending fails
List<LogRecord> candidateLogRecords = new ArrayList<LogRecord>();
if (useAcsLogServiceExtensions) {
// create CORBA XmlLogRecord containing XML representations of log records and the log level as a separate field
List<XmlLogRecord> remoteLogRecords = new ArrayList<XmlLogRecord>();
for (int i = 0; i < logRecords.length; i++) {
if (i < getBufferSize()) {
try {
String xml = ((AcsXMLLogFormatter) logFormatter).format(logRecords[i]);
int level = AcsLogLevel.getNativeLevel(logRecords[i].getLevel()).getAcsLevel().value;
XmlLogRecord remoteLogRecord = new XmlLogRecord(xml, (short) level);
remoteLogRecords.add(remoteLogRecord);
candidateLogRecords.add(logRecords[i]);
} catch (RuntimeException e) {
failures.addSerializationFailure(logRecords[i]);
}
} else {
// records that don't fit into one remote call must be sent later
// this should never happen except for during concurrently changing buffer size.
failures.addSendFailure(logRecords[i]);
}
}
// send the log records over CORBA
if (!remoteLogRecords.isEmpty()) {
XmlLogRecord[] remoteLogRecordsArray = remoteLogRecords.toArray(new XmlLogRecord[remoteLogRecords.size()]);
writeRecords(remoteLogRecordsArray);
}
} else {
// default is Corba telecom Log interface that requires records inside Anys
List<Any> anyLogRecords = new ArrayList<Any>();
for (int i = 0; i < logRecords.length; i++) {
if (i < getBufferSize()) {
try {
Any anyLogRecord = orb.create_any();
anyLogRecord = logFormatter.formatAny(anyLogRecord, logRecords[i]);
anyLogRecords.add(anyLogRecord);
candidateLogRecords.add(logRecords[i]);
} catch (RuntimeException e) {
failures.addSerializationFailure(logRecords[i]);
}
} else {
// records that don't fit into one remote call must be sent later
failures.addSendFailure(logRecords[i]);
}
}
// send the log records over CORBA
if (!anyLogRecords.isEmpty()) {
Any[] anyLogRecordsArray = anyLogRecords.toArray(new Any[anyLogRecords.size()]);
try {
writeRecords(anyLogRecordsArray);
}// // LogOffDuty - other exotic reasons to be not "on duty", such as log duration time or scheduling time
catch (Throwable thr) {
// feed back these records to we can try them again later
failures.addSendFailures(candidateLogRecords);
// Currently ACS does not make use of the semantics of the various exceptions specified here by CORBA, i.e.
// LogDisabled, LogOffDuty, LogLocked, LogFull (see above)
// There can also be java.net.ConnectException thrown.. @TODO perhaps we should print that to stdout, with repeatGuard.
}
}
}
return failures;
}
Aggregations