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


Java Message類代碼示例

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


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

示例1: prepareLogEvent

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
/**
 * Prepare log event log event.
 *
 * @param logEvent the log event
 * @return the log event
 */
public static LogEvent prepareLogEvent(final LogEvent logEvent) {
    final String messageModified = TicketIdSanitizationUtils.sanitize(logEvent.getMessage().getFormattedMessage());
    final Message message = new SimpleMessage(messageModified);
    final LogEvent newLogEvent = Log4jLogEvent.newBuilder()
            .setLevel(logEvent.getLevel())
            .setLoggerName(logEvent.getLoggerName())
            .setLoggerFqcn(logEvent.getLoggerFqcn())
            .setContextMap(logEvent.getContextMap())
            .setContextStack(logEvent.getContextStack())
            .setEndOfBatch(logEvent.isEndOfBatch())
            .setIncludeLocation(logEvent.isIncludeLocation())
            .setMarker(logEvent.getMarker())
            .setMessage(message)
            .setNanoTime(logEvent.getNanoTime())
            .setSource(logEvent.getSource())
            .setThreadName(logEvent.getThreadName())
            .setThrownProxy(logEvent.getThrownProxy())
            .setThrown(logEvent.getThrown())
            .setTimeMillis(logEvent.getTimeMillis())
            .build();
    return newLogEvent;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:29,代碼來源:LoggingUtils.java

示例2: log

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Override
public void log(Marker marker, String fqcn, Level level, Message data, Throwable t) {
  if (ConfigHandler.textureErrorRemover != 0) {
    if (t instanceof FileNotFoundException) {
      if (ConfigHandler.textureErrorRemover == 1) {
        super.log(marker, fqcn, level, data, null);
      }
      removed++;
    } else {
      super.log(marker, fqcn, level, data, t);
    }
    if (data.getFormat().startsWith("Created:")) {
      EnderCore.logger.info(ConfigHandler.textureErrorRemover == 1 ? new FormattedMessage("Removed %d missing texture stacktraces. Tada!", removed)
          : new FormattedMessage("There were %d missing texture errors here. They're gone now.", removed));
      removed = 0;
    }
    return;
  }
  super.log(marker, fqcn, level, data, t);
}
 
開發者ID:SleepyTrousers,項目名稱:EnderCore,代碼行數:21,代碼來源:TextureErrorRemover.java

示例3: toSolrDocument

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Override
public SolrDocument toSolrDocument(LogEvent event) {
  SolrDocument doc = new SolrDocument();
  doc.setField("time", new Date(event.getTimeMillis()));
  doc.setField("level", event.getLevel().toString());
  doc.setField("logger", event.getLoggerName());
  Message message = event.getMessage();
  doc.setField("message", message.getFormattedMessage());
  Throwable t = message.getThrowable();
  if (t != null)
    doc.setField("trace", Throwables.getStackTraceAsString(t));

  Map<String,String> contextMap = event.getContextMap();
  if (contextMap != null) {
    for (String key : contextMap.keySet())
      doc.setField(key, contextMap.get(key));
  }

  if (!doc.containsKey("core"))
    doc.setField("core", ""); // avoids an ugly "undefined" column in the UI

  return doc;
}
 
開發者ID:lucidworks,項目名稱:solr-log4j2,代碼行數:24,代碼來源:Log4j2Watcher.java

示例4: testGetStackifyError

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
/**
 * testGetStackifyError
 */
@Test
public void testGetStackifyError() {
	Message message = Mockito.mock(Message.class);
	Mockito.when(message.getFormattedMessage()).thenReturn("Exception message");

	LogEvent event = Mockito.mock(LogEvent.class);
	Mockito.when(event.getMessage()).thenReturn(message);
	
	Throwable exception = Mockito.mock(Throwable.class);
	
	LogEventAdapter adapter = new LogEventAdapter(Mockito.mock(EnvironmentDetail.class));
	StackifyError error = adapter.getStackifyError(event, exception);
	
	Assert.assertNotNull(error);
}
 
開發者ID:stackify,項目名稱:stackify-log-log4j2,代碼行數:19,代碼來源:LogEventAdapterTest.java

示例5: testGetStackifyErrorServletContext

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
/**
 * testGetStackifyErrorServletContext
 */
@Test
public void testGetStackifyErrorServletContext() {
	String user = "user";
	ServletLogContext.putUser(user);
	
	WebRequestDetail webRequest = WebRequestDetail.newBuilder().build();
	ServletLogContext.putWebRequest(webRequest);
	
	Message message = Mockito.mock(Message.class);
	Mockito.when(message.getFormattedMessage()).thenReturn("Exception message");

	LogEvent event = Mockito.mock(LogEvent.class);
	Mockito.when(event.getMessage()).thenReturn(message);
	
	Throwable exception = Mockito.mock(Throwable.class);
	
	LogEventAdapter adapter = new LogEventAdapter(Mockito.mock(EnvironmentDetail.class));
	StackifyError error = adapter.getStackifyError(event, exception);
	
	Assert.assertNotNull(error);
	
	Assert.assertEquals(user, error.getUserName());
	Assert.assertNotNull(error.getWebRequestDetail());
}
 
開發者ID:stackify,項目名稱:stackify-log-log4j2,代碼行數:28,代碼來源:LogEventAdapterTest.java

示例6: testGetStackifyErrorWithoutException

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
/**
 * testGetStackifyErrorWithoutException
 */
@Test
public void testGetStackifyErrorWithoutException() {
	StackTraceElement source = new StackTraceElement("class", "method", null, 123);
	
	Message message = Mockito.mock(Message.class);
	Mockito.when(message.getFormattedMessage()).thenReturn("Exception message");

	LogEvent event = Mockito.mock(LogEvent.class);
	Mockito.when(event.getMessage()).thenReturn(message);
	Mockito.when(event.getSource()).thenReturn(source);
	
	LogEventAdapter adapter = new LogEventAdapter(Mockito.mock(EnvironmentDetail.class));
	StackifyError error = adapter.getStackifyError(event, null);
	
	Assert.assertNotNull(error);
	Assert.assertEquals("StringException", error.getError().getErrorType());
}
 
開發者ID:stackify,項目名稱:stackify-log-log4j2,代碼行數:21,代碼來源:LogEventAdapterTest.java

示例7: newEvent

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Override
protected Object newEvent(LogDetails logDetails) {
    final Message message = new SimpleMessage(logDetails.getLogMessage());
    final StringMap contextData;
    if (!logDetails.getMdc().isEmpty()) {
        contextData = ContextDataFactory.createContextData();
        logDetails.getMdc().entrySet().forEach(it -> contextData.putValue(it.getKey(), it.getValue()));
    } else {
        contextData = null;
    }
    Log4jLogEvent.Builder builder = Log4jLogEvent.newBuilder().setLoggerName(logDetails.getClassName())
            .setTimeMillis(logDetails.getTimeMillis()).setLevel(Level.DEBUG).setContextData(contextData)
            .setIncludeLocation(logDetails.isLocationInfo()).setLoggerFqcn(logDetails.getClassName()).setMessage(message);
    if (logDetails.isLocationInfo()) {
        builder.setSource(new StackTraceElement(logDetails.getClassName(), logDetails.getMethodName(),
                logDetails.getFileName(), logDetails.getLineNumber()));
    }
    if (logDetails.getException() != null) {
        builder.setThrown(logDetails.getException());
    }
    return builder.build();
}
 
開發者ID:Talend,項目名稱:daikon,代碼行數:23,代碼來源:Log4j2JSONLayoutTest.java

示例8: append

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
/**
     * @see org.apache.logging.log4j.core.Appender#append(org.apache.logging.log4j.core.LogEvent)
     */
    @Override
    public void append( LogEvent aEvent )
    {
        Message m = aEvent.getMessage();

//        LOGGER.error( "Received Event: " + m.getClass().getSimpleName() );
        if ( ! ( m instanceof ReportMsg ) )
        {
            return;
        } // if ! ( m instanceof ReportMsg )

        SdiReporter reporter = getReporter();

        if ( reporter == null )
        {
            LOGGER.error( "Bean SdiReporter is null" );
            return;
        } // if reporter == null


        myReporter.add( (ReportMsg) m );
    }
 
開發者ID:heribender,項目名稱:SocialDataImporter,代碼行數:26,代碼來源:SdiReportAppender.java

示例9: logMessage

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
public void logMessage(String string, Level level, Marker marker, Message message, Throwable t) {
    String msg = message.getFormattedMessage();

    msg = MessageFormat.format(msg, message.getParameters());

    if (level == Level.ALL) {
        logger.log(java.util.logging.Level.ALL, msg, t);
    } else if (level == Level.DEBUG) {
        logger.log(java.util.logging.Level.FINEST, msg, t);
    } else if (level == Level.ERROR) {
        logger.log(java.util.logging.Level.SEVERE, msg, t);
    } else if (level == Level.FATAL) {
        logger.log(java.util.logging.Level.SEVERE, msg, t);
    } else if (level == Level.INFO) {
        logger.log(java.util.logging.Level.INFO, msg, t);
    } else if (level == Level.OFF) {
        logger.log(java.util.logging.Level.OFF, msg, t);
    } else if (level == Level.TRACE) {
        logger.log(java.util.logging.Level.SEVERE, msg, t);
    } else if (level == Level.WARN) {
        logger.log(java.util.logging.Level.WARNING, msg, t);
    } else {
        logger.log(java.util.logging.Level.INFO, msg, t);
    }
}
 
開發者ID:mc-societies,項目名稱:societies,代碼行數:26,代碼來源:LoggerWrapper.java

示例10: append

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Override
public void append(final LogEvent event) {
    LogStatementTO statement = new LogStatementTO();

    statement.setLevel(LoggerLevel.fromLevel(event.getLevel()));
    statement.setLoggerName(event.getLoggerName());

    Message msg = event.getMessage();
    statement.setMessage((msg instanceof ReusableMessage
            ? ((ReusableMessage) msg).memento()
            : msg).getFormattedMessage());

    statement.setTimeMillis(event.getTimeMillis());

    if (event.getThrown() != null) {
        statement.setStackTrace(ExceptionUtils2.getFullStackTrace(event.getThrown()));
    }

    statement.setThreadId(event.getThreadId());
    statement.setThreadName(event.getThreadName());
    statement.setThreadPriority(event.getThreadPriority());

    this.statements.add(statement);
}
 
開發者ID:apache,項目名稱:syncope,代碼行數:25,代碼來源:MemoryAppender.java

示例11: testAppend_Simple

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Test
public void testAppend_Simple() {
    SystemdJournalAppender journalAppender = new SystemdJournalAppender("Journal", null, null, false, journalLibrary,
            false, false, false, false, false, false, null, null);

    Message message = mock(Message.class);
    when(message.getFormattedMessage()).thenReturn("some message");
    LogEvent event = new Log4jLogEvent.Builder().setMessage(message).setLevel(Level.INFO).build();

    journalAppender.append(event);

    List<Object> expectedArgs = new ArrayList<>();
    expectedArgs.add("some message");
    expectedArgs.add("PRIORITY=%d");
    expectedArgs.add(6);
    expectedArgs.add(null);

    verify(journalLibrary).sd_journal_send("MESSAGE=%s", expectedArgs.toArray());
}
 
開發者ID:bwaldvogel,項目名稱:log4j-systemd-journal-appender,代碼行數:20,代碼來源:SystemdJournalAppenderTest.java

示例12: testAppend_DoNotLogException

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Test
public void testAppend_DoNotLogException() {

    SystemdJournalAppender journalAppender = new SystemdJournalAppender("Journal", null, null, false, journalLibrary,
            false, false, false, false, false, false, null, null);

    Message message = mock(Message.class);
    when(message.getFormattedMessage()).thenReturn("some message");

    LogEvent event = new Log4jLogEvent.Builder() //
            .setMessage(message)//
            .setLoggerFqcn(journalAppender.getClass().getName())//
            .setThrown(new Throwable()) //
            .setLevel(Level.INFO).build();
    event.setIncludeLocation(true);

    journalAppender.append(event);

    List<Object> expectedArgs = new ArrayList<>();
    expectedArgs.add("some message");
    expectedArgs.add("PRIORITY=%d");
    expectedArgs.add(6);
    expectedArgs.add(null);

    verify(journalLibrary).sd_journal_send("MESSAGE=%s", expectedArgs.toArray());
}
 
開發者ID:bwaldvogel,項目名稱:log4j-systemd-journal-appender,代碼行數:27,代碼來源:SystemdJournalAppenderTest.java

示例13: append

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
@Override
public void append(LogEvent event) {
    Message msg = event.getMessage();
    if (msg instanceof ConsoleSetupMessage) {
        ConsoleReader reader = ((ConsoleSetupMessage) msg).getReader();
        Listener listener = new ConsoleReaderListener(reader);
        switch (((ConsoleSetupMessage) msg).getAction()) {
        case ADD:
            this.manager.addListener(listener);
            break;
        case REMOVE:
            this.manager.removeListener(listener);
        }
    }
    super.append(event);
}
 
開發者ID:Wolf480pl,項目名稱:jline-log4j2-appender,代碼行數:17,代碼來源:JLineConsoleAppender.java

示例14: setValues

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
public void setValues(final AsyncLogger asyncLogger,
        final String loggerName, final Marker marker, final String fqcn,
        final Level level, final Message data, final Throwable t,
        final Map<String, String> map, final ContextStack contextStack,
        final String threadName, final StackTraceElement location,
        final long currentTimeMillis) {
    this.asyncLogger = asyncLogger;
    this.loggerName = loggerName;
    this.marker = marker;
    this.fqcn = fqcn;
    this.level = level;
    this.message = data;
    this.thrown = t;
    this.contextMap = map;
    this.contextStack = contextStack;
    this.threadName = threadName;
    this.location = location;
    this.currentTimeMillis = currentTimeMillis;
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:20,代碼來源:RingBufferLogEvent.java

示例15: log

import org.apache.logging.log4j.message.Message; //導入依賴的package包/類
/**
 * Logs a message with location information by redirecting it to the underlaying {@link java.util.logging.Logger}.
 *
 * @param marker the Marker
 * @param fqcn   the fully qualified class name of the <b>caller</b>
 * @param level  the logging level
 * @param data   the Message.
 * @param t      a Throwable or null.
 */
@Override
public void log(Marker marker, String fqcn, Level level, Message data, Throwable t) {
    final String msg;
    String mkName = (marker == null) ? "" : marker.getName();
    if (this.format == null) {
        if (mkName.isEmpty()) {
            msg = data.getFormattedMessage();
        } else {
            msg = String.format(DEFAULT_FORMAT, data.getFormattedMessage(), mkName);
        }
    } else {
        msg = String.format(this.format, data.getFormattedMessage(), mkName);
    }
    LogRecord record = new LogRecord(Util.levelToJUL(level), msg);
    record.setThrown(t);
    record.setSourceClassName(fqcn);
    record.setLoggerName(this.jul.getName());
    this.jul.log(record);
}
 
開發者ID:Wolf480pl,項目名稱:log4j2-to-jul,代碼行數:29,代碼來源:JULLogger.java


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