當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.getParameters方法代碼示例

本文整理匯總了Java中org.apache.logging.log4j.message.Message.getParameters方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.getParameters方法的具體用法?Java Message.getParameters怎麽用?Java Message.getParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.logging.log4j.message.Message的用法示例。


在下文中一共展示了Message.getParameters方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rewrite

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
/**
 * Rewrite the event.
 * 
 * @param source
 *            a logging event that may be returned or used to create a new
 *            logging event.
 * @return The LogEvent after rewriting.
 */
       @Override
public LogEvent rewrite(LogEvent source) {
	// get the markers for the log event. If no markers, nothing can be
	// tagged confidential and we can return
	Marker sourceMarker = source.getMarker();
	if (sourceMarker == null)
		return source;

	// get the message. If no message we can return
	final Message msg = source.getMessage();
	if (msg == null || !(msg instanceof ParameterizedMessage))
		return source;

	// get the parameters. If no params we can return
	Object[] params = msg.getParameters();
	if (params == null || params.length == 0)
		return source;

	// check if this event is actually marked as confidential. If not,
	// return
	Log4jMarker eventMarker = new Log4jMarker(sourceMarker);
	if (!eventMarker.contains(SecurityMarkers.CONFIDENTIAL))
		return source;

	// we have a message, parameters, a marker, and it is confidential.
	// Process
	for (int i = 0; i < params.length; i++) {
		params[i] = MASKED_PASSWORD;
	}
	Message outMessage = new ParameterizedMessage(msg.getFormat(), params,
			msg.getThrowable());
	LogEvent output = new Log4jLogEvent(source.getLoggerName(),
			source.getMarker(), source.getLoggerFqcn(), source.getLevel(),
			outMessage, source.getThrown(), source.getContextMap(),
			source.getContextStack(), source.getThreadName(),
			source.getSource(), source.getTimeMillis());

	return output;
}
 
開發者ID:javabeanz,項目名稱:owasp-security-logging,代碼行數:48,代碼來源:MaskingRewritePolicy.java

示例2: log

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
@Override
public void log(final Marker marker, final String fqcn, final Level level, final Message msg, final Throwable throwable) {
    final StringBuilder sb = new StringBuilder();
    sb.append(" ");
    sb.append(level.toString());
    sb.append(" ");
    sb.append(msg.getFormattedMessage());
    final Map<String, String> mdc = ThreadContext.getContext();
    if (mdc.size() > 0) {
        sb.append(" ");
        sb.append(mdc.toString());
        sb.append(" ");
    }
    final Object[] params = msg.getParameters();
    Throwable t;
    if (throwable == null && params != null && params[params.length -1] instanceof Throwable ) {
        t = (Throwable) params[params.length - 1];
    } else {
        t = throwable;
    }
    if (t != null) {
        sb.append(" ");
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        t.printStackTrace(new PrintStream(baos));
        sb.append(baos.toString());
    }
    list.add(sb.toString());
    //System.out.println(sb.toString());
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:30,代碼來源:TestLogger.java

示例3: testForcedLog

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
/**
 * Tests Category.forcedLog.
 */
@Test
@SuppressWarnings("deprecation")
public void testForcedLog() {
    final MockCategory category = new MockCategory("org.example.foo");
    category.setAdditivity(false);
    category.getLogger().addAppender(appender);
    category.info("Hello, World");
    final List<LogEvent> list = appender.getEvents();
    int events = list.size();
    assertTrue("Number of events should be 1, was " + events, events == 1);
    LogEvent event = list.get(0);
    Message msg = event.getMessage();
    assertNotNull("No message", msg);
    assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
    Object[] objects = msg.getParameters();
    assertTrue("Incorrect Object type", objects[0] instanceof String);
    appender.clear();
    category.log(Priority.INFO, "Hello, World");
    events = list.size();
    assertTrue("Number of events should be 1, was " + events, events == 1);
    event = list.get(0);
    msg = event.getMessage();
    assertNotNull("No message", msg);
    assertTrue("Incorrect Message type", msg instanceof ObjectMessage);
    objects = msg.getParameters();
    assertTrue("Incorrect Object type", objects[0] instanceof String);
    appender.clear();
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:32,代碼來源:CategoryTest.java

示例4: logMessage

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
@Override
public void logMessage(String fqcn, Level level, Marker marker, Message msg, Throwable throwable) {
    if (logFile != null) {
        StringBuilder loggedStr = new StringBuilder();
        loggedStr.append(DATE_FORMAT.format(new Date()));

        loggedStr.append(" [");
        loggedStr.append(level.toString());
        loggedStr.append("] ");

        loggedStr.append(msg.getFormattedMessage());

        final Object[] params = msg.getParameters();
        Throwable t;
        if (throwable == null && params != null && params.length != 0 && params[params.length - 1] instanceof Throwable) {
            t = (Throwable) params[params.length - 1];
        } else {
            t = throwable;
        }
        if (t != null) {
            loggedStr.append(" ");
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            t.printStackTrace(new PrintStream(baos));
            loggedStr.append(baos.toString());
        }

        try {
            PrintWriter out = new PrintWriter(new FileWriter(logFile, true), true);
            out.println(loggedStr.toString());
        } catch (IOException e) {
            GSLogger.logError("Error while writing in graves log file!");
            e.printStackTrace();
        }
    } else {
        GSLogger.logError("Graves logs file doesn't exists");
    }
}
 
開發者ID:NightKosh,項目名稱:Gravestone-mod-Graves,代碼行數:38,代碼來源:GravesLogger.java

示例5: logMessage

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
@Override
public void logMessage(final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) {
    final StringBuilder sb = new StringBuilder();
    if (marker != null) {
        sb.append(marker);
    }
    sb.append(' ');
    sb.append(level.toString());
    sb.append(' ');
    sb.append(msg.getFormattedMessage());
    final Map<String, String> mdc = ThreadContext.getImmutableContext();
    if (mdc.size() > 0) {
        sb.append(' ');
        sb.append(mdc.toString());
        sb.append(' ');
    }
    final Object[] params = msg.getParameters();
    Throwable t;
    if (throwable == null && params != null && params.length > 0 && params[params.length - 1] instanceof Throwable) {
        t = (Throwable) params[params.length - 1];
    } else {
        t = throwable;
    }
    if (t != null) {
        sb.append(' ');
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        t.printStackTrace(new PrintStream(baos));
        sb.append(baos.toString());
    }
    list.add(sb.toString());
    //System.out.println(sb.toString());
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:33,代碼來源:TestLogger.java

示例6: toSerializable

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
@Override
public String toSerializable(final LogEvent event) {
    final Message message = event.getMessage();
    final Object[] parameters = message.getParameters();
    final StringBuilder buffer = getStringBuilder();
    try {
        getFormat().printRecord(buffer, parameters);
        return buffer.toString();
    } catch (final IOException e) {
        StatusLogger.getLogger().error(message, e);
        return getFormat().getCommentMarker() + " " + e;
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:14,代碼來源:CsvParameterLayout.java

示例7: log

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
@Override
public void log(final Marker marker, final String fqcn, final Level level, final Message msg,
                final Throwable throwable) {
    final StringBuilder sb = new StringBuilder();
    // Append date-time if so configured
    if (showDateTime) {
        final Date now = new Date();
        String dateText;
        synchronized (dateFormatter) {
            dateText = dateFormatter.format(now);
        }
        sb.append(dateText);
        sb.append(SPACE);
    }

    sb.append(level.toString());
    sb.append(SPACE);
    if (logName != null && logName.length() > 0) {
        sb.append(logName);
        sb.append(SPACE);
    }
    sb.append(msg.getFormattedMessage());
    if (showContextMap) {
        final Map<String, String> mdc = ThreadContext.getContext();
        if (mdc.size() > 0) {
            sb.append(SPACE);
            sb.append(mdc.toString());
            sb.append(SPACE);
        }
    }
    final Object[] params = msg.getParameters();
    Throwable t;
    if (throwable == null && params != null && params[params.length - 1] instanceof Throwable) {
        t = (Throwable) params[params.length - 1];
    } else {
        t = throwable;
    }
    if (t != null) {
        sb.append(SPACE);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        t.printStackTrace(new PrintStream(baos));
        sb.append(baos.toString());
    }
    stream.println(sb.toString());
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:46,代碼來源:SimpleLogger.java

示例8: logMessage

import org.apache.logging.log4j.message.Message; //導入方法依賴的package包/類
@Override
public void logMessage(final String fqcn, final Level mgsLevel, final Marker marker, final Message msg,
        final Throwable throwable) {
    final StringBuilder sb = new StringBuilder();
    // Append date-time if so configured
    if (showDateTime) {
        final Date now = new Date();
        String dateText;
        synchronized (dateFormatter) {
            dateText = dateFormatter.format(now);
        }
        sb.append(dateText);
        sb.append(SPACE);
    }

    sb.append(mgsLevel.toString());
    sb.append(SPACE);
    if (Strings.isNotEmpty(logName)) {
        sb.append(logName);
        sb.append(SPACE);
    }
    sb.append(msg.getFormattedMessage());
    if (showContextMap) {
        final Map<String, String> mdc = ThreadContext.getImmutableContext();
        if (mdc.size() > 0) {
            sb.append(SPACE);
            sb.append(mdc.toString());
            sb.append(SPACE);
        }
    }
    final Object[] params = msg.getParameters();
    Throwable t;
    if (throwable == null && params != null && params.length > 0
            && params[params.length - 1] instanceof Throwable) {
        t = (Throwable) params[params.length - 1];
    } else {
        t = throwable;
    }
    stream.println(sb.toString());
    if (t != null) {
        stream.print(SPACE);
        t.printStackTrace(stream);
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:45,代碼來源:SimpleLogger.java


注:本文中的org.apache.logging.log4j.message.Message.getParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。