use of com.sun.identity.log.ILogRecord in project OpenAM by OpenRock.
the class RemoteFormatter method format.
/**
* The method which does the actual formatting of the LogRecord.
* @param logRecord The logRecord to be formatted
* @return The string formed by formatting the logRecord
*/
public String format(java.util.logging.LogRecord logRecord) {
Map logInfo = null;
if ((LogManagerUtil.isAMLoggingMode()) && (logRecord instanceof ILogRecord)) {
logInfo = ((com.sun.identity.log.ILogRecord) logRecord).getLogInfoMap();
}
String logName = logRecord.getLoggerName();
String loggedBySid = null;
if (logInfo != null) {
loggedBySid = (String) logInfo.get(LogConstants.LOGGED_BY_SID);
if (loggedBySid == null) {
if (Debug.warningEnabled()) {
Debug.warning("RemoteFormatter : returning null" + " because logRecord doesn't have loggedBySid");
}
return null;
}
}
Object[] parameters = logRecord.getParameters();
StringBuffer xml = new StringBuffer();
xml.append("<logRecWrite><log logName=\"");
xml.append(logName);
xml.append("\" sid=\"");
xml.append(loggedBySid);
xml.append("\"></log><logRecord><level>");
xml.append(logRecord.getLevel().intValue());
xml.append("</level><recMsg>");
String msg = formatMessage(logRecord);
if ((msg == null) || (msg.length() == 0)) {
msg = LogConstants.NOTAVAIL;
}
msg = com.sun.identity.shared.encode.Base64.encode(msg.getBytes());
xml.append(msg);
xml.append("</recMsg>");
if (logInfo != null) {
Set keys = logInfo.keySet();
Iterator keysIter = keys.iterator();
xml.append("<logInfoMap>");
while (keysIter.hasNext()) {
String key = (String) keysIter.next();
xml.append("<logInfo> <infoKey>");
xml.append(key);
xml.append("</infoKey><infoValue>");
String infoValue = (String) logInfo.get(key);
if (key.equalsIgnoreCase(LogConstants.DATA)) {
infoValue = com.sun.identity.shared.encode.Base64.encode(infoValue.getBytes());
}
xml.append(infoValue);
xml.append("</infoValue></logInfo>");
}
xml.append("</logInfoMap>");
}
if ((parameters != null) && (parameters.length > 0)) {
xml.append("<parameters>");
for (int i = 0; i < parameters.length; i++) {
xml.append("<parameter><paramIndex>");
xml.append(String.valueOf(i));
xml.append("</paramIndex><paramValue>");
xml.append(parameters[i].toString());
xml.append("</paramValue></parameter>");
}
xml.append("</parameters>");
}
xml.append("</logRecord></logRecWrite>");
if (Debug.messageEnabled()) {
Debug.message("RemoteFormatter: XML Req string = " + xml);
}
return xml.toString();
}
use of com.sun.identity.log.ILogRecord in project OpenAM by OpenRock.
the class RemoteHandler method publish.
/**
* This method sends the LogRecord to the remote logging service.
* @param logRecord The LogRecord to be published to the remote
* logging service.
*/
public synchronized void publish(java.util.logging.LogRecord logRecord) {
logName = logRecord.getLoggerName();
String xml = getFormatter().format(logRecord);
if (xml == null || xml.length() <= 0) {
if (Debug.warningEnabled()) {
Debug.warning(logName + ":RemoteHandler.publish : formatted xml is null");
}
return;
}
Request request = new Request(xml);
if (logRecord instanceof ILogRecord) {
Map logInfoMap = ((ILogRecord) logRecord).getLogInfoMap();
String loggedBySid = (String) logInfoMap.get(LogConstants.LOGGED_BY_SID);
if (loggedBySid != null) {
RequestSet reqSet = (RequestSet) reqSetMap.get(loggedBySid);
if (reqSet == null) {
reqSet = new RequestSet("Logging");
}
reqSet.addRequest(request);
reqSetMap.put(loggedBySid, reqSet);
}
}
this.recCount++;
if (this.recCount >= recCountLimit) {
if (Debug.messageEnabled()) {
Debug.message(logName + ":RemoteHandler.publish(): got " + recCount + " records, flushing all");
}
nonBlockingFlush();
}
}
Aggregations