本文整理汇总了Java中org.apache.log4j.spi.LoggingEvent类的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent类的具体用法?Java LoggingEvent怎么用?Java LoggingEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggingEvent类属于org.apache.log4j.spi包,在下文中一共展示了LoggingEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
public String format(LoggingEvent event){
if( event.getLevel() == Level.FATAL){
return fatalErrorColor+super.format(event)+END_COLOR;
}else if( event.getLevel() == Level.ERROR){
return errorColor+super.format(event)+END_COLOR;
}if( event.getLevel() == Level.WARN){
return super.format(event);
// return warnColor+super.format(event)+END_COLOR;
}if( event.getLevel() == Level.INFO){
return super.format(event);
// return infoColor+super.format(event)+END_COLOR;
}if( event.getLevel() == Level.DEBUG){
return super.format(event);
// return debugColor+super.format(event)+END_COLOR;
}else{
throw new RuntimeException("Unsupported Level "+event.toString());
}
}
示例2: run
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
void run() {
Logger rootLogger = Logger.getRootLogger();
List<LoggingEvent> events = new ArrayList<>();
Appender appender = new MockUp<Appender>() {
@Mock
public void doAppend(LoggingEvent event) {
events.add(event);
}
}.getMockInstance();
rootLogger.addAppender(appender);
doRun(events);
rootLogger.removeAppender(appender);
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:TestServiceRegistryClientImpl.java
示例3: testRegisterSchemaException
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Test
public void testRegisterSchemaException() {
InterruptedException e = new InterruptedException();
new MockUp<CountDownLatch>() {
@Mock
public void await() throws InterruptedException {
throw e;
}
};
new RegisterSchemaTester() {
void doRun(java.util.List<LoggingEvent> events) {
oClient.registerSchema("msid", "schemaId", "content");
Assert.assertEquals(
"register schema msid/schemaId fail.",
events.get(0).getMessage());
Assert.assertEquals(e, events.get(0).getThrowableInformation().getThrowable());
}
}.run();
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:TestServiceRegistryClientImpl.java
示例4: decide
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Test
public void decide() {
assertNotNull(mdcFilter);
mdcFilter.setExpression("MessageId!=null || LoggedBy!=null");
mdcFilter.setKeys("LoggedBy,MessageId");
final LoggingEvent event = new LoggingEvent("", LOG, LOG.getLevel(),
"MessageId=123", null);
MDC.put("LoggedBy", "abc");
MDC.put("fff", "abc");
final int ret = mdcFilter.decide(event);
LOG.info("decide: " + ret);
assertTrue(ret == Filter.NEUTRAL);
}
示例5: append
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Override
public void append(LoggingEvent event) {
Level level = event.getLevel();
// depends on the api, == might not work
// see HADOOP-7055 for details
if (level.equals(Level.INFO)) {
counts.incr(INFO);
}
else if (level.equals(Level.WARN)) {
counts.incr(WARN);
}
else if (level.equals(Level.ERROR)) {
counts.incr(ERROR);
}
else if (level.equals(Level.FATAL)) {
counts.incr(FATAL);
}
}
示例6: testLifecycleEvent
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Test
public void testLifecycleEvent() throws Exception {
when(mockLifeCycle.getState()).thenReturn(LifecycleState.STOPPING);
lifeCycleListener.lifecycleEvent(new LifecycleEvent(mockLifeCycle, null, null));
sleep(2500);
when(mockLifeCycle.getState()).thenReturn(LifecycleState.STOPPED);
lifeCycleListener.lifecycleEvent(new LifecycleEvent(mockLifeCycle, null, null));
sleep(2500);
verify(mockAppender, atLeastOnce()).doAppend((LoggingEvent) captorLoggingEvent.capture());
final int eventTotal = captorLoggingEvent.getAllValues().size();
final LoggingEvent loggingEvent = (LoggingEvent) captorLoggingEvent.getAllValues().get(eventTotal - 1);
assertEquals("Channel closed", loggingEvent.getMessage());
System.out.println(captorLoggingEvent.getAllValues().size());
// make sure that the scheduler has stopped by checking if there are extra events after the listener has processed
// a STOPPED life cycle
sleep(2500); // pause to let any rogue scheduler do logging if there are any...
assertEquals(eventTotal, captorLoggingEvent.getAllValues().size());
}
示例7: log
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
/**
* Log an event, writing a line in the log file of the form
* <pre>
* DATE EVENT_TYPE PARAM_1 PARAM_2 ...
* </pre>
*/
synchronized void log(String eventType, Object... params) {
try {
if (logDisabled)
return;
StringBuffer buffer = new StringBuffer();
buffer.append(eventType);
for (Object param: params) {
buffer.append("\t");
buffer.append(param);
}
String message = buffer.toString();
Logger logger = Logger.getLogger(getClass());
appender.append(new LoggingEvent("", logger, Level.INFO, message, null));
} catch (Exception e) {
LOG.error("Failed to append to fair scheduler event log", e);
logDisabled = true;
}
}
示例8: doAppend
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
/**
* 覆写doAppend, 去掉closed的log日志
* @param event
*/
@Override
public synchronized void doAppend(LoggingEvent event) {
if (closed) {
return;
}
if (!isAsSevereAsThreshold(event.getLevel())) {
return;
}
Filter f = this.headFilter;
FILTER_LOOP:
while(f != null) {
switch(f.decide(event)) {
case Filter.DENY: return;
case Filter.ACCEPT: break FILTER_LOOP;
case Filter.NEUTRAL: f = f.getNext();
}
}
this.append(event);
}
示例9: decide
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
/**
* Returns Filter#DENY if Expression returns false based on the values
* returned from the MDC Context.
*
* @param event
* <code>LoggingEvent</code>
*/
public int decide(final LoggingEvent event) {
int ret = DENY;
if (keys != null && expression != null) {
final List<Object> mdcValues = new ArrayList<Object>();
final List<Class<String>> keyTypes = new ArrayList<Class<String>>();
final String[] keyValues = keys.split(SPLIT_EXPRESSION);
if (keyValues != null) {
for (final String keyValue : keyValues) {
final Object mdcValue = MDC.get(keyValue);
keyTypes.add((Class<String>) keyValue.getClass());
mdcValues.add(mdcValue);
}
}
ret = evaluate(getExpressionEvaluator(keyTypes, keyValues), mdcValues);
}
return ret;
}
示例10: getLoggingMesage
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
private String getLoggingMesage( LoggingEvent event ) {
Throwable throwable = null;
ThrowableInformation throwableInfo = event.getThrowableInformation();
if (throwableInfo != null && throwableInfo.getThrowable() != null) {
// logging through methods like error(new Exception);
throwable = throwableInfo.getThrowable();
} else if (event.getMessage() instanceof Throwable) {
// logging through methods like error("some message", new Exception);
throwable = (Throwable) event.getMessage();
}
// first format the message using the layout
String message = layout.format(event);
// then append the exception stack trace
if (throwable != null) {
message = getExceptionMsg(throwable, message);
}
return message;
}
示例11: append
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Override
protected void append(LoggingEvent event)
{
if (closed)
{
throw new IllegalStateException("appender is closed");
}
if (! ready)
{
initialize();
}
try
{
internalAppend(new LogMessage(event, getLayout()));
}
catch (Exception ex)
{
LogLog.warn("unable to append event", ex);
}
}
示例12: testAsciiMessageFromEventDefaultLayout
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Test
public void testAsciiMessageFromEventDefaultLayout() throws Exception
{
final long timestamp = System.currentTimeMillis();
final String text = "test";
LoggingEvent event = createLoggingEvent(timestamp, text, null);
LogMessage message = new LogMessage(event, new PatternLayout());
// the default pattern appends a newline
String expectedText = text + "\n";
assertEquals("timestmap", timestamp, message.getTimestamp());
assertEquals("message", expectedText, message.getMessage());
assertArrayEquals("message as bytes", expectedText.getBytes("UTF-8"), message.getBytes());
assertEquals("size", 5, message.size());
}
示例13: testUnicodeMessageFromEventDefaultLayout
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Test
public void testUnicodeMessageFromEventDefaultLayout() throws Exception
{
final long timestamp = System.currentTimeMillis();
final String text = "\u0024\u00a2\u20ac";
LoggingEvent event = createLoggingEvent(timestamp, text, null);
LogMessage message = new LogMessage(event, new PatternLayout());
// the default pattern appends a newline
String expectedText = text + "\n";
assertEquals("timestmap", timestamp, message.getTimestamp());
assertEquals("message", expectedText, message.getMessage());
assertArrayEquals("message as bytes", expectedText.getBytes("UTF-8"), message.getBytes());
assertEquals("size", 7, message.size());
}
示例14: testAsciiMessageFromEventDefaultLayoutWithException
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
@Test
// at this point we'll assume that UTF-8 conversion works as expected
public void testAsciiMessageFromEventDefaultLayoutWithException() throws Exception
{
final long timestamp = System.currentTimeMillis();
final String text = "test";
final Exception ex = new Exception();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println(text);
ex.printStackTrace(pw);
pw.close();
String expectedText = sw.toString();
LoggingEvent event = createLoggingEvent(timestamp, text, ex);
LogMessage message = new LogMessage(event, new PatternLayout());
assertEquals("explicit timestamp", timestamp, message.getTimestamp());
assertEquals("message as string", expectedText, message.getMessage());
}
示例15: getThrowableRepresentationFromLoggingEvent
import org.apache.log4j.spi.LoggingEvent; //导入依赖的package包/类
/**
* Extracts Stack trace of Throwable contained in LogginEvent, if there is
* any
*
* @param aLoggingEvent
* logging event
* @return stack trace of throwable
*/
public String getThrowableRepresentationFromLoggingEvent(LoggingEvent aLoggingEvent) {
// extract throwable information from loggingEvent if available
ThrowableInformation throwableinfo = aLoggingEvent.getThrowableInformation();
StringBuffer throwableStringBuffer = new StringBuffer();
if (throwableinfo != null) {
String[] lines = throwableinfo.getThrowableStrRep();
for (int index = 0; index < lines.length; index++) {
throwableStringBuffer = (StringBuffer) throwableStringBuffer.append(lines[index]
+ "\r\n");
}
}
String result = quotedString(throwableStringBuffer.toString());
if (this.getThrowableMaxChars() != -1 && result.length() > this.getThrowableMaxChars()) {
result = result.substring(0, this.getThrowableMaxChars() - 1);
}
return result;
}