当前位置: 首页>>代码示例>>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;未经允许,请勿转载。