use of com.sun.common.util.logging.GFLogRecord in project Payara by payara.
the class JSONLogFormatter method jsonLogFormat.
/**
* @param record The record to format.
* @return The JSON formatted record.
*/
private String jsonLogFormat(LogRecord record) {
try {
LogEventImpl logEvent = new LogEventImpl();
JsonObjectBuilder eventObject = Json.createObjectBuilder();
/*
* Create the timestamp field and append to object.
*/
SimpleDateFormat dateFormatter;
if (null != getRecordDateFormat()) {
dateFormatter = new SimpleDateFormat(getRecordDateFormat());
} else {
dateFormatter = new SimpleDateFormat(RFC3339_DATE_FORMAT);
}
date.setTime(record.getMillis());
String timestampValue = dateFormatter.format(date);
logEvent.setTimestamp(timestampValue);
eventObject.add(TIMESTAMP_KEY, timestampValue);
/*
* Create the event level field and append to object.
*/
Level eventLevel = record.getLevel();
logEvent.setLevel(eventLevel.getName());
StringBuilder levelBuilder = new StringBuilder();
levelBuilder.append(eventLevel.getLocalizedName());
eventObject.add(LOG_LEVEL_KEY, levelBuilder.toString());
/*
* Get the product id and append to object.
*/
productId = getProductId();
logEvent.setComponentId(productId);
eventObject.add(PRODUCT_ID_KEY, productId);
/*
* Get the logger name and append to object.
*/
String loggerName = record.getLoggerName();
if (null == loggerName) {
loggerName = "";
}
logEvent.setLogger(loggerName);
StringBuilder loggerBuilder = new StringBuilder();
loggerBuilder.append(loggerName);
eventObject.add(LOGGER_NAME_KEY, loggerBuilder.toString());
/*
* Get thread information and append to object if not excluded.
*/
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.TID)) {
// Thread ID
int threadId = record.getThreadID();
logEvent.setThreadId(threadId);
eventObject.add(THREAD_ID_KEY, String.valueOf(threadId));
// Thread Name
String threadName;
if (record instanceof GFLogRecord) {
threadName = ((GFLogRecord) record).getThreadName();
} else {
threadName = Thread.currentThread().getName();
}
logEvent.setThreadName(threadName);
eventObject.add(THREAD_NAME_KEY, threadName);
}
/*
* Get user id and append if not excluded and exists with value.
*/
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.USERID)) {
String userId = logEvent.getUser();
if (null != userId && !userId.isEmpty()) {
eventObject.add(USER_ID_KEY, userId);
}
}
/*
* Get ec id and append if not excluded and exists with value.
*/
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.ECID)) {
String ecid = logEvent.getECId();
if (null != ecid && !ecid.isEmpty()) {
eventObject.add(ECID_KEY, ecid);
}
}
/*
* Get millis time for log entry timestamp
*/
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.TIME_MILLIS)) {
Long timestamp = record.getMillis();
logEvent.setTimeMillis(timestamp);
eventObject.add(TIME_MILLIS_KEY, String.valueOf(timestamp));
}
/*
* Include the integer value for log level
*/
Level level = record.getLevel();
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.LEVEL_VALUE)) {
int levelValue = level.intValue();
logEvent.setLevelValue(levelValue);
eventObject.add(LEVEL_VALUE_KEY, String.valueOf(levelValue));
}
/*
* Stick the message id on the entry
*/
String messageId = getMessageId(record);
if (messageId != null && !messageId.isEmpty()) {
logEvent.setMessageId(messageId);
eventObject.add(MESSAGE_ID_KEY, messageId);
}
/*
* Include ClassName and MethodName for FINER and FINEST log levels.
*/
if (LOG_SOURCE_IN_KEY_VALUE || level.intValue() <= Level.FINE.intValue()) {
String sourceClassName = record.getSourceClassName();
if (null != sourceClassName && !sourceClassName.isEmpty()) {
logEvent.getSupplementalAttributes().put(CLASS_NAME, sourceClassName);
eventObject.add(CLASS_NAME, sourceClassName);
}
String sourceMethodName = record.getSourceMethodName();
if (null != sourceMethodName && !sourceMethodName.isEmpty()) {
logEvent.getSupplementalAttributes().put(METHOD_NAME, sourceMethodName);
eventObject.add(METHOD_NAME, sourceMethodName);
}
}
/*
* Add the record number to the entry.
*/
if (RECORD_NUMBER_IN_KEY_VALUE) {
recordNumber++;
logEvent.getSupplementalAttributes().put(RECORD_NUMBER, recordNumber);
eventObject.add(RECORD_NUMBER, String.valueOf(recordNumber));
}
if (null != _delegate) {
_delegate.format(new StringBuilder().append(eventObject.toString()), level);
}
String logMessage = record.getMessage();
if (null == logMessage || logMessage.trim().equals("")) {
Throwable throwable = record.getThrown();
if (null != throwable) {
try (StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter)) {
JsonObjectBuilder traceObject = Json.createObjectBuilder();
throwable.printStackTrace(printWriter);
logMessage = stringWriter.toString();
traceObject.add(EXCEPTION_KEY, throwable.getMessage());
traceObject.add(STACK_TRACE_KEY, logMessage);
logEvent.setMessage(logMessage);
eventObject.add(LOG_MESSAGE_KEY, traceObject.build());
}
}
} else {
if (logMessage.contains("{0") && logMessage.contains("}") && null != record.getParameters()) {
logMessage = MessageFormat.format(logMessage, record.getParameters());
} else {
ResourceBundle bundle = getResourceBundle(record.getLoggerName());
if (null != bundle) {
try {
logMessage = MessageFormat.format(bundle.getString(logMessage), record.getParameters());
} catch (MissingResourceException ex) {
// Leave logMessage as it is because it already has
// an exception message
}
}
}
StringBuilder logMessageBuilder = new StringBuilder();
logMessageBuilder.append(logMessage);
Throwable throwable = getThrowable(record);
if (null != throwable) {
try (StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter)) {
JsonObjectBuilder traceObject = Json.createObjectBuilder();
throwable.printStackTrace(printWriter);
logMessage = stringWriter.toString();
traceObject.add(EXCEPTION_KEY, logMessageBuilder.toString());
traceObject.add(STACK_TRACE_KEY, logMessage);
logEvent.setMessage(logMessage);
eventObject.add(LOG_MESSAGE_KEY, traceObject.build());
}
} else {
logMessage = logMessageBuilder.toString();
logEvent.setMessage(logMessage);
eventObject.add(LOG_MESSAGE_KEY, logMessage);
}
}
informLogEventListeners(logEvent);
return eventObject.build().toString() + LINE_SEPARATOR;
} catch (Exception ex) {
new ErrorManager().error("Error in formatting Logrecord", ex, ErrorManager.FORMAT_FAILURE);
return "";
}
}
use of com.sun.common.util.logging.GFLogRecord in project Payara by payara.
the class GFFileHandler method publish.
/**
* Publishes the logrecord storing it in our queue
*/
@Override
public void publish(LogRecord record) {
// the queue has shutdown, we are not processing any more records
if (done.isSignalled()) {
return;
}
// JUL LogRecord does not capture thread-name. Create a wrapper to
// capture the name of the logging thread so that a formatter can
// output correct thread-name if done asynchronously. Note that
// this fix is limited to records published through this handler only.
// ***
// PAYARA-406 Check if the LogRecord passed in is already a GFLogRecord,
// and just cast the passed record if it is
GFLogRecord recordWrapper;
if (record.getClass().getSimpleName().equals("GFLogRecord")) {
recordWrapper = (GFLogRecord) record;
// Check there is actually a set thread name
if (recordWrapper.getThreadName() == null) {
recordWrapper.setThreadName(Thread.currentThread().getName());
}
} else {
recordWrapper = new GFLogRecord(record);
// set the thread id to be the current thread that is logging the message
recordWrapper.setThreadName(Thread.currentThread().getName());
}
try {
pendingRecords.add(recordWrapper);
} catch (IllegalStateException e) {
// queue is full, start waiting.
try {
pendingRecords.put(recordWrapper);
} catch (InterruptedException e1) {
// too bad, record is lost...
}
}
Formatter formatter = this.getFormatter();
if (!(formatter instanceof LogEventBroadcaster)) {
LogEvent logEvent = new LogEventImpl(record);
informLogEventListeners(logEvent);
}
}
use of com.sun.common.util.logging.GFLogRecord in project Payara by payara.
the class ODLLogFormatter method odlLogFormat.
/**
* Note: This method is not synchronized, we are assuming that the
* synchronization will happen at the Log Handler.publish( ) method.
*/
private String odlLogFormat(LogRecord record) {
try {
LogEventImpl logEvent = new LogEventImpl();
// creating message from log record using resource bundle and appending parameters
String message = getLogMessage(record);
if (message == null || message.isEmpty()) {
return "";
}
boolean multiLine = multiLineMode || isMultiLine(message);
// Starting formatting message
// Adding record begin marker
StringBuilder recordBuffer = new StringBuilder();
// A Dummy Container Date Object is used to format the date
Date date = new Date();
// Adding timestamp
SimpleDateFormat dateFormatter = new SimpleDateFormat(getRecordDateFormat() != null ? getRecordDateFormat() : RFC_3339_DATE_FORMAT);
date.setTime(record.getMillis());
recordBuffer.append(FIELD_BEGIN_MARKER);
String timestamp = dateFormatter.format(date);
logEvent.setTimestamp(timestamp);
recordBuffer.append(timestamp);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
// Adding organization ID
recordBuffer.append(FIELD_BEGIN_MARKER);
logEvent.setComponentId(uniformLogFormatter.getProductId());
recordBuffer.append(uniformLogFormatter.getProductId());
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
// Adding messageType
Level logLevel = record.getLevel();
recordBuffer.append(FIELD_BEGIN_MARKER);
if (color()) {
recordBuffer.append(getColor(logLevel));
}
String odlLevel = logLevel.getLocalizedName();
logEvent.setLevel(odlLevel);
recordBuffer.append(odlLevel);
if (color()) {
recordBuffer.append(getReset());
}
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
// Adding message ID
recordBuffer.append(FIELD_BEGIN_MARKER);
String msgId = UniformLogFormatter.getMessageId(record);
recordBuffer.append((msgId == null) ? "" : msgId);
logEvent.setMessageId(msgId);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
// Adding logger Name / module Name
recordBuffer.append(FIELD_BEGIN_MARKER);
String loggerName = record.getLoggerName();
loggerName = (loggerName == null) ? "" : loggerName;
if (color()) {
recordBuffer.append(getLoggerColor());
}
recordBuffer.append(loggerName);
if (color()) {
recordBuffer.append(getReset());
}
logEvent.setLogger(loggerName);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
// Adding thread ID
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.TID)) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("tid: _ThreadID=");
recordBuffer.append(record.getThreadID());
logEvent.setThreadId(record.getThreadID());
String threadName;
if (record instanceof GFLogRecord) {
threadName = ((GFLogRecord) record).getThreadName();
} else {
threadName = Thread.currentThread().getName();
}
recordBuffer.append(" _ThreadName=");
logEvent.setThreadName(threadName);
recordBuffer.append(threadName);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
// Adding user ID
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.USERID) && userID != null && !("").equals(userID.trim())) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("userId: ");
logEvent.setUser(userID);
recordBuffer.append(userID);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
// Adding ec ID
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.ECID) && ecID != null && !("").equals(ecID.trim())) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("ecid: ");
logEvent.setECId(ecID);
recordBuffer.append(ecID);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
// Include the raw time stamp
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.TIME_MILLIS)) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("timeMillis: ");
logEvent.setTimeMillis(record.getMillis());
recordBuffer.append(record.getMillis());
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
// Include the level value
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.LEVEL_VALUE)) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("levelValue: ");
logEvent.setLevelValue(logLevel.intValue());
recordBuffer.append(logLevel.intValue());
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
// Adding extra Attributes - record number
if (RECORD_NUMBER_IN_KEY_VALUE) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordNumber++;
recordBuffer.append("RECORDNUMBER: ");
logEvent.getSupplementalAttributes().put("RECORDNUMBER", recordNumber);
recordBuffer.append(recordNumber);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
// Adding extra Attributes - class name and method name for FINE and higher level messages
Level level = record.getLevel();
if (LOG_SOURCE_IN_KEY_VALUE || (level.intValue() <= Level.FINE.intValue())) {
String sourceClassName = record.getSourceClassName();
if (sourceClassName != null && !sourceClassName.isEmpty()) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("CLASSNAME: ");
logEvent.getSupplementalAttributes().put("CLASSNAME", sourceClassName);
recordBuffer.append(sourceClassName);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
String sourceMethodName = record.getSourceMethodName();
if (sourceMethodName != null && !sourceMethodName.isEmpty()) {
recordBuffer.append(FIELD_BEGIN_MARKER);
recordBuffer.append("METHODNAME: ");
logEvent.getSupplementalAttributes().put("METHODNAME", sourceMethodName);
recordBuffer.append(sourceMethodName);
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
}
}
if (_delegate != null) {
_delegate.format(recordBuffer, level);
}
if (multiLine) {
recordBuffer.append(FIELD_BEGIN_MARKER).append(FIELD_BEGIN_MARKER);
recordBuffer.append(LINE_SEPARATOR);
recordBuffer.append(INDENT);
}
recordBuffer.append(message);
logEvent.setMessage(message);
if (multiLine) {
recordBuffer.append(FIELD_END_MARKER).append(FIELD_END_MARKER);
}
recordBuffer.append(LINE_SEPARATOR).append(LINE_SEPARATOR);
informLogEventListeners(logEvent);
return recordBuffer.toString();
} catch (Exception ex) {
new ErrorManager().error("Error in formatting Logrecord", ex, ErrorManager.FORMAT_FAILURE);
// return is to keep javac happy
return "";
}
}
use of com.sun.common.util.logging.GFLogRecord in project Payara by payara.
the class UniformLogFormatter method uniformLogFormat.
/**
* Note: This method is not synchronized, we are assuming that the
* synchronization will happen at the Log Handler.publish( ) method.
*/
private String uniformLogFormat(LogRecord record) {
try {
LogEventImpl logEvent = new LogEventImpl();
SimpleDateFormat dateFormatter = new SimpleDateFormat(getRecordDateFormat() != null ? getRecordDateFormat() : RFC_3339_DATE_FORMAT);
StringBuilder recordBuffer = new StringBuilder(getRecordBeginMarker() != null ? getRecordBeginMarker() : RECORD_BEGIN_MARKER);
// The following operations are to format the date and time in a
// human readable format.
// _REVISIT_: Use HiResolution timer to analyze the number of
// Microseconds spent on formatting date object
date.setTime(record.getMillis());
String timestamp = dateFormatter.format(date);
logEvent.setTimestamp(timestamp);
recordBuffer.append(timestamp);
if (color()) {
recordBuffer.append(getColor(record.getLevel()));
}
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
logEvent.setLevel(record.getLevel().getName());
recordBuffer.append(record.getLevel().getLocalizedName()).append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
if (color()) {
recordBuffer.append(getReset());
}
String compId = getProductId();
logEvent.setComponentId(compId);
recordBuffer.append(compId).append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
String loggerName = record.getLoggerName();
loggerName = (loggerName == null) ? "" : loggerName;
logEvent.setLogger(loggerName);
if (color()) {
recordBuffer.append(getLoggerColor());
}
recordBuffer.append(loggerName).append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
if (color()) {
recordBuffer.append(getReset());
}
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.TID)) {
recordBuffer.append("_ThreadID").append(NV_SEPARATOR);
logEvent.setThreadId(record.getThreadID());
recordBuffer.append(record.getThreadID()).append(NVPAIR_SEPARATOR);
recordBuffer.append("_ThreadName").append(NV_SEPARATOR);
String threadName;
if (record instanceof GFLogRecord) {
threadName = ((GFLogRecord) record).getThreadName();
} else {
threadName = Thread.currentThread().getName();
}
logEvent.setThreadName(threadName);
recordBuffer.append(threadName);
recordBuffer.append(NVPAIR_SEPARATOR);
}
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.USERID)) {
String user = logEvent.getUser();
if (user != null && !user.isEmpty()) {
recordBuffer.append("_UserId").append(NV_SEPARATOR);
recordBuffer.append(user);
recordBuffer.append(NVPAIR_SEPARATOR);
}
}
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.ECID)) {
String ecid = logEvent.getECId();
if (ecid != null && !ecid.isEmpty()) {
recordBuffer.append("_ECId").append(NV_SEPARATOR);
recordBuffer.append(ecid);
recordBuffer.append(NVPAIR_SEPARATOR);
}
}
// Include the raw long time stamp value in the log
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.TIME_MILLIS)) {
recordBuffer.append("_TimeMillis").append(NV_SEPARATOR);
logEvent.setTimeMillis(record.getMillis());
recordBuffer.append(record.getMillis()).append(NVPAIR_SEPARATOR);
}
// Include the integer level value in the log
Level level = record.getLevel();
if (!excludeFieldsSupport.isSet(ExcludeFieldsSupport.SupplementalAttribute.LEVEL_VALUE)) {
recordBuffer.append("_LevelValue").append(NV_SEPARATOR);
int levelValue = level.intValue();
logEvent.setLevelValue(levelValue);
recordBuffer.append(levelValue).append(NVPAIR_SEPARATOR);
}
String msgId = getMessageId(record);
if (msgId != null && !msgId.isEmpty()) {
logEvent.setMessageId(msgId);
recordBuffer.append("_MessageID").append(NV_SEPARATOR);
recordBuffer.append(msgId).append(NVPAIR_SEPARATOR);
}
// included for FINER and FINEST log levels.
if (LOG_SOURCE_IN_KEY_VALUE || (level.intValue() <= Level.FINE.intValue())) {
String sourceClassName = record.getSourceClassName();
// sourceClassName = (sourceClassName == null) ? "" : sourceClassName;
if (sourceClassName != null && !sourceClassName.isEmpty()) {
recordBuffer.append(CLASS_NAME).append(NV_SEPARATOR);
logEvent.getSupplementalAttributes().put(CLASS_NAME, sourceClassName);
recordBuffer.append(sourceClassName);
recordBuffer.append(NVPAIR_SEPARATOR);
}
String sourceMethodName = record.getSourceMethodName();
// sourceMethodName = (sourceMethodName == null) ? "" : sourceMethodName;
if (sourceMethodName != null && !sourceMethodName.isEmpty()) {
recordBuffer.append(METHOD_NAME).append(NV_SEPARATOR);
logEvent.getSupplementalAttributes().put(METHOD_NAME, sourceMethodName);
recordBuffer.append(sourceMethodName);
recordBuffer.append(NVPAIR_SEPARATOR);
}
}
if (RECORD_NUMBER_IN_KEY_VALUE) {
recordNumber++;
recordBuffer.append(RECORD_NUMBER).append(NV_SEPARATOR);
logEvent.getSupplementalAttributes().put(RECORD_NUMBER, recordNumber);
recordBuffer.append(recordNumber).append(NVPAIR_SEPARATOR);
}
if (_delegate != null) {
_delegate.format(recordBuffer, level);
}
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);
if (multiLineMode) {
recordBuffer.append(LINE_SEPARATOR);
recordBuffer.append(INDENT);
}
String logMessage = record.getMessage();
// 2. There is a bug in the calling code causing the message to be missing.
if (logMessage == null || logMessage.trim().equals("")) {
if (record.getThrown() != null) {
// case 1: Just log the exception instead of a message
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
pw.close();
logMessage = sw.toString();
sw.close();
} else {
// GLASSFISH-18816: Suppress noise.
logMessage = "";
}
logEvent.setMessage(logMessage);
recordBuffer.append(logMessage);
} else {
if (logMessage.indexOf("{0") >= 0 && logMessage.contains("}") && record.getParameters() != null) {
// If we find {0} or {1} etc., in the message, then it's most
// likely finer level messages for Method Entry, Exit etc.,
logMessage = java.text.MessageFormat.format(logMessage, record.getParameters());
} else {
ResourceBundle rb = getResourceBundle(record.getLoggerName());
if (rb != null) {
try {
logMessage = MessageFormat.format(rb.getString(logMessage), record.getParameters());
} catch (java.util.MissingResourceException e) {
// If we don't find an entry, then we are covered
// because the logMessage is initialized already
}
}
}
StringBuffer logMessageBuffer = new StringBuffer();
logMessageBuffer.append(logMessage);
Throwable throwable = getThrowable(record);
if (throwable != null) {
logMessageBuffer.append(LINE_SEPARATOR);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
pw.close();
logMessageBuffer.append(sw.toString());
sw.close();
}
logMessage = logMessageBuffer.toString();
logEvent.setMessage(logMessage);
recordBuffer.append(logMessage);
}
recordBuffer.append(getRecordEndMarker() != null ? getRecordEndMarker() : RECORD_END_MARKER).append(LINE_SEPARATOR).append(LINE_SEPARATOR);
informLogEventListeners(logEvent);
return recordBuffer.toString();
} catch (Exception ex) {
new ErrorManager().error("Error in formatting Logrecord", ex, ErrorManager.FORMAT_FAILURE);
// return is to keep javac happy
return "";
}
}
Aggregations