本文整理汇总了Java中org.jboss.logmanager.ExtLogRecord类的典型用法代码示例。如果您正苦于以下问题:Java ExtLogRecord类的具体用法?Java ExtLogRecord怎么用?Java ExtLogRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtLogRecord类属于org.jboss.logmanager包,在下文中一共展示了ExtLogRecord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: format
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
public final String format(final ExtLogRecord record) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
String dateString = dateFormat.format(new Date(record.getMillis()));
String message = formatExtRecord(record);
if (message == null) {
return null;
}
JsonObjectBuilder builder = jsonBuilder.createObjectBuilder().add("@timestamp", dateString).add("@message", message)
.add("@source", record.getLoggerName()).add("@source_host", hostName).add("@fields", encodeFields(record));
addTags(builder);
addMDC(record, builder);
return builder.build().toString() + System.lineSeparator();
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:17,代码来源:LogstashUtilFormatter.java
示例2: formatExtRecord
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
private String formatExtRecord(final ExtLogRecord record) {
String format = getMessageFormat(record);
if (format == null) {
return super.formatMessage(record);
}
Object[] parameters = record.getParameters();
String msg;
switch (record.getFormatStyle()) {
case MESSAGE_FORMAT:
msg = format.indexOf("{0") >= 0 ? MessageFormat.format(format, parameters) : format;
break;
case PRINTF:
msg = (parameters == null) ? String.format(format) : String.format(format, parameters);
break;
case NO_FORMAT:
default:
msg = format;
break;
}
record.setParameters(null);
record.setMessage(msg);
return super.formatMessage(record);
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:24,代码来源:LogstashUtilFormatter.java
示例3: createFormattedMessage
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
private String createFormattedMessage(final ExtLogRecord record) {
final Formatter formatter = getFormatter();
try {
return formatter.format(record);
} catch (Exception e) {
reportError("Could not format message", e, ErrorManager.FORMAT_FAILURE);
return null;
}
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:10,代码来源:SocketHandler.java
示例4: testAddParameter
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
/**
* Test of message with parameters, of class LogstashUtilFormatter.
*/
@Test
public void testAddParameter() {
Locale.setDefault(Locale.US);
fullLogMessage = fullLogMessage.replace("Junit Test", "Junit Test [1] [2] [3.000000]");
ExtLogRecord extLogRecord = new ExtLogRecord(record.getLevel(), "Junit Test [%d] [%s] [%f]", FormatStyle.PRINTF,
record.getLoggerName());
extLogRecord.setParameters(new Object[] { 1, "2", 3.0f });
extLogRecord.setSourceClassName(record.getSourceClassName());
extLogRecord.setSourceMethodName(record.getSourceMethodName());
extLogRecord.setLoggerName(record.getLoggerName());
extLogRecord.setMillis(record.getMillis());
extLogRecord.setThrown(record.getThrown());
String result = instance.format(extLogRecord);
assertEquals(fullLogMessage, result);
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:20,代码来源:LogstashUtilFormatterTest.java
示例5: writeLogItem
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
void writeLogItem(String formattedItem) throws IOException {
boolean reconnect = isReconnect();
if (!reconnect) {
handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName()));
errorManager.getAndThrowError();
} else {
ControllerLogger.MGMT_OP_LOGGER.attemptingReconnectToSyslog(name, reconnectTimeout);
try {
// Reinitialise the delegating syslog handler if required, if we're already connected we don't need to
// establish a new connection
if (!connected) {
stop();
initialize();
}
handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName()));
errorManager.getAndThrowError();
lastErrorTime = -1;
} catch (Exception e) {
// A failure has occurred and initialization should be reattempted
connected = false;
lastErrorTime = System.currentTimeMillis();
errorManager.throwAsIoOrRuntimeException(e);
}
}
}
开发者ID:wildfly,项目名称:wildfly-core,代码行数:27,代码来源:SyslogAuditLogHandler.java
示例6: format
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
public String format(ExtLogRecord extLogRecord) {
LogstashGenerator logstashGenerator = factory.createGenerator();
logstashGenerator.setLevel(extLogRecord.getLevel().toString());
logstashGenerator.setMessage(extLogRecord.getFormattedMessage());
logstashGenerator.setThrowable(extLogRecord.getThrown());
logstashGenerator.setTimestamp(extLogRecord.getMillis());
logstashGenerator.setClassName(extLogRecord.getSourceClassName());
logstashGenerator.setThread(extLogRecord.getThreadName());
logstashGenerator.setNdc(extLogRecord.getNdc());
logstashGenerator.setMdc(extLogRecord.getMdcCopy());
try {
return logstashGenerator.toLogstashJSonString();
} catch (IOException e) {
return LogstashGenerator.getErrorLogstashFromThrowable(e);
}
}
开发者ID:mpucholblasco,项目名称:logstash-loggers,代码行数:18,代码来源:LogstashFormatter.java
示例7: testThrowableWithInnerThrowable
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Test
public void testThrowableWithInnerThrowable() throws Throwable {
ExtLogRecord logRecord = this.createBasicLogRecord();
InnerException innerException = new InnerException();
Exception ex = new Exception("Exception message", innerException);
logRecord.setThrown(ex);
LogstashFormatter formatter = new LogstashFormatter(
createBasicLogstashFactory());
String currentResult = formatter.format(logRecord);
String expectedResult = "{\"host\":\"myHost\",\"level\": \"INFO\",\"@timestamp\":\"2001-11-09T01:46:40.123Z\",\"message\":\"My message\",\"thread\": \"main\",\"classname\": \"net.logstash.loggers.logstash_jboss_logmanager.test\",\"exception_class\": \"java.lang.Exception\",\"exception_message\":\"Exception message\"}";
JSONAssert.assertEquals(expectedResult, currentResult, false);
// Ensure inner exception information is present
assertTrue(currentResult.contains("Caused by: "
+ InnerException.class.getName()));
}
开发者ID:mpucholblasco,项目名称:logstash-loggers,代码行数:17,代码来源:LogstashFormatterTest.java
示例8: testSeveralLogEntries
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Test
public void testSeveralLogEntries() throws Throwable {
LogstashFormatter formatter = new LogstashFormatter(
createBasicLogstashFactory());
ExtLogRecord logRecord1 = this.createBasicLogRecord();
logRecord1.setMessage("My message1");
String currentResult1 = formatter.format(logRecord1);
String expectedResult1 = "{\"host\":\"myHost\",\"level\": \"INFO\",\"@timestamp\":\"2001-11-09T01:46:40.123Z\",\"message\":\"My message1\",\"thread\": \"main\",\"classname\": \"net.logstash.loggers.logstash_jboss_logmanager.test\"}";
JSONAssert.assertEquals(expectedResult1, currentResult1, true);
ExtLogRecord logRecord2 = this.createBasicLogRecord();
logRecord2.setMessage("My message2");
String currentResult2 = formatter.format(logRecord2);
String expectedResult2 = "{\"host\":\"myHost\",\"level\": \"INFO\",\"@timestamp\":\"2001-11-09T01:46:40.123Z\",\"message\":\"My message2\",\"thread\": \"main\",\"classname\": \"net.logstash.loggers.logstash_jboss_logmanager.test\"}";
JSONAssert.assertEquals(expectedResult2, currentResult2, true);
}
开发者ID:mpucholblasco,项目名称:logstash-loggers,代码行数:18,代码来源:LogstashFormatterTest.java
示例9: doPublish
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
protected void doPublish(ExtLogRecord record) {
synchronized (this) {
if (!initialized) {
try {
initialize();
} catch (Exception e) {
reportError("Error creating fluentd connection", e, ErrorManager.OPEN_FAILURE);
setEnabled(false);
}
}
}
if (initialized) {
Map<String, Object> entries = new HashMap<>();
entries.put(Key.SEQUENCE.getKey(), record.getSequenceNumber());
entries.put(Key.LEVEL.getKey(), record.getLevel().getName());
entries.put(Key.THREAD_NAME.getKey(), record.getThreadName());
entries.put(Key.MESSAGE.getKey(), record.getFormattedMessage());
entries.put(Key.THREAD_ID.getKey(), record.getThreadID());
entries.put(Key.MDC.getKey(), record.getMdcCopy());
entries.put(Key.NDC.getKey(), record.getNdc());
this.sender.emit(this.tag, record.getMillis(), entries);
}
}
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:30,代码来源:FluentdHandler.java
示例10: addMDC
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
private void addMDC(final ExtLogRecord record, JsonObjectBuilder builder) {
boolean hasMDC = false;
JsonObjectBuilder mdcBuilder = jsonBuilder.createObjectBuilder();
for (Map.Entry<String, String> entry : record.getMdcCopy().entrySet()) {
hasMDC = true;
mdcBuilder.add(entry.getKey(), entry.getValue());
}
if (hasMDC) {
builder.add("@mdc", mdcBuilder.build());
}
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:12,代码来源:LogstashUtilFormatter.java
示例11: formatMessage
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
public synchronized String formatMessage(final LogRecord record) {
if (record instanceof ExtLogRecord) {
return formatExtRecord((ExtLogRecord) record);
}
String format = getMessageFormat(record);
Object[] parameters = record.getParameters();
String msg = format.indexOf('{') >= 0 ? MessageFormat.format(format, parameters) : format;
record.setParameters(null);
record.setMessage(msg);
return super.formatMessage(record);
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:13,代码来源:LogstashUtilFormatter.java
示例12: doPublish
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
protected void doPublish(final ExtLogRecord record) {
final String formatted = createFormattedMessage(record);
if (formatted == null || formatted.isEmpty()) {
// nothing to write; move along
return;
}
try {
synchronized (this) {
if (initialize && (em.lastExceptionTimestamp < System.currentTimeMillis() - 5000)) {
initialize();
if (em.lastException == null) {
initialize = false;
}
}
if (writer == null) {
for (Handler h : getHandlers()) {
h.publish(record);
}
return;
}
writer.write(formatted);
super.doPublish(record);
}
} catch (Exception e) {
handleExceptionOnPublish(record, e);
}
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:29,代码来源:SocketHandler.java
示例13: handleExceptionOnPublish
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
private void handleExceptionOnPublish(final ExtLogRecord record, Exception e) {
Handler[] handlers = getHandlers();
if (handlers.length > 0) {
// if we have a subhandler it will publish the record of the failed
// transmission (to disk)
for (Handler h : getHandlers()) {
h.publish(record);
}
} else {
reportError("Error writing log message", e, ErrorManager.WRITE_FAILURE);
}
closeSocketHandler();
}
开发者ID:kifj,项目名称:wildfly-logstash,代码行数:14,代码来源:SocketHandler.java
示例14: hasLevel
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
/**
* is there any record matching Level?
*
* @param level
* @return
*/
public static boolean hasLevel(Level level) {
for (ExtLogRecord record : messages.values()) {
if (record.getLevel().equals(level)) {
return true;
}
}
return false;
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:16,代码来源:AssertionLoggerHandler.java
示例15: findText
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
/**
* Find a line that contains the parameters passed as an argument
*
* @param text
* @return
*/
public static boolean findText(final String... text) {
for (Map.Entry<String, ExtLogRecord> entry : messages.entrySet()) {
String key = entry.getKey();
boolean found = true;
for (String txtCheck : text) {
found = key.contains(txtCheck);
if (!found) {
// If the main log message doesn't contain what we're looking for let's look in the message from the exception (if there is one).
Throwable throwable = entry.getValue().getThrown();
if (throwable != null && throwable.getMessage() != null) {
found = throwable.getMessage().contains(txtCheck);
if (!found) {
break;
}
} else {
break;
}
}
}
if (found) {
return true;
}
}
return false;
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:35,代码来源:AssertionLoggerHandler.java
示例16: doPublish
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
protected void doPublish(final ExtLogRecord record) {
final Appender appender = this.appender;
if (appender == null) {
throw LoggingLogger.ROOT_LOGGER.handlerClosed();
}
final LoggingEvent event = new LoggingEvent(record, DummyCategory.of(record.getLoggerName()));
appender.doAppend(event);
super.doPublish(record);
}
开发者ID:wildfly,项目名称:wildfly-core,代码行数:11,代码来源:Log4jAppenderHandler.java
示例17: format
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Override
public String format(ExtLogRecord extLogRecord) {
if (!wasSetFieldsCalled) {
addFields(SUPPORTED_FIELDS);
}
GelfMessage gelfMessage = gelfMessageAssembler.createGelfMessage(new JBoss7JulLogEvent(extLogRecord));
return gelfMessage.toJson("") + getLineBreak();
}
开发者ID:mp911de,项目名称:logstash-gelf,代码行数:10,代码来源:WildFlyJsonFormatter.java
示例18: testProfilingString
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Test
public void testProfilingString() throws Exception {
Map mdcMap = new HashMap();
mdcMap.put(GelfUtil.MDC_REQUEST_START_MS, "" + (System.currentTimeMillis() - 12000));
ExtLogRecord extLogRecord = new ExtLogRecord(Level.INFO, "test", "");
extLogRecord.setMdc(mdcMap);
GelfMessage message = new GelfMessage();
GelfUtil.addMdcProfiling(new JBoss7JulLogEvent(extLogRecord), message);
assertThat(message.getAdditonalFields().get(GelfUtil.MDC_REQUEST_DURATION)).isEqualTo("12sec");
}
开发者ID:mp911de,项目名称:logstash-gelf,代码行数:14,代码来源:GelfUtilUnitTests.java
示例19: testProfilingLong
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Test
public void testProfilingLong() throws Exception {
Map mdcMap = new HashMap();
mdcMap.put(GelfUtil.MDC_REQUEST_START_MS, (System.currentTimeMillis() - 12000));
ExtLogRecord extLogRecord = new ExtLogRecord(Level.INFO, "test", "");
extLogRecord.setMdc(mdcMap);
GelfMessage message = new GelfMessage();
GelfUtil.addMdcProfiling(new JBoss7JulLogEvent(extLogRecord), message);
assertThat(message.getAdditonalFields().get(GelfUtil.MDC_REQUEST_DURATION)).isEqualTo("12sec");
}
开发者ID:mp911de,项目名称:logstash-gelf,代码行数:14,代码来源:GelfUtilUnitTests.java
示例20: testExtLogWithBasicElements
import org.jboss.logmanager.ExtLogRecord; //导入依赖的package包/类
@Test
public void testExtLogWithBasicElements() throws Throwable {
LogstashFactory factory = new LogstashFactory();
LogstashFormatter formatter = new LogstashFormatter(factory);
ExtLogRecord logRecord = new ExtLogRecord(Level.INFO, "My message",
"net.logstash.loggers.logstash_jboss_logmanager.logger");
logRecord.setSourceClassName("net.logstash.loggers.logstash_jboss_logmanager.test");
logRecord.setMillis(1005270400123L);
String currentResult = formatter.format(logRecord);
String expectedResult = "{\"host\":\""
+ HOST_INFO.getHostName()
+ "\",\"level\": \"INFO\",\"@timestamp\":\"2001-11-09T01:46:40.123Z\",\"message\":\"My message\",\"thread\": \"main\",\"classname\": \"net.logstash.loggers.logstash_jboss_logmanager.test\"}";
JSONAssert.assertEquals(expectedResult, currentResult, true);
}
开发者ID:mpucholblasco,项目名称:logstash-loggers,代码行数:15,代码来源:LogstashFormatterTest.java
注:本文中的org.jboss.logmanager.ExtLogRecord类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论