com.alibaba.dubbo.common.logger.Logger Java Examples

The following examples show how to use com.alibaba.dubbo.common.logger.Logger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Log4jLoggerAdapter.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Log4jLoggerAdapter() {
	try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
           if (logger != null) {
               Enumeration<Appender> appenders = logger.getAllAppenders();
               if (appenders != null) {
                   while (appenders.hasMoreElements()) {
                       Appender appender = appenders.nextElement();
                       if (appender instanceof FileAppender) {
                           FileAppender fileAppender = (FileAppender)appender;
                           String filename = fileAppender.getFile();
                           file = new File(filename);
                           break;
                       }
                   }
               }
           }
       } catch (Throwable t) {
       }
}
 
Example #2
Source File: Log4jLoggerAdapter.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Log4jLoggerAdapter() {
	try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
           if (logger != null) {
               Enumeration<Appender> appenders = logger.getAllAppenders();
               if (appenders != null) {
                   while (appenders.hasMoreElements()) {
                       Appender appender = appenders.nextElement();
                       if (appender instanceof FileAppender) {
                           FileAppender fileAppender = (FileAppender)appender;
                           String filename = fileAppender.getFile();
                           file = new File(filename);
                           break;
                       }
                   }
               }
           }
       } catch (Throwable t) {
       }
}
 
Example #3
Source File: Log4jLoggerAdapter.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Log4jLoggerAdapter() {
    try {
        org.apache.log4j.Logger logger = LogManager.getRootLogger();
        if (logger != null) {
            Enumeration<Appender> appenders = logger.getAllAppenders();
            if (appenders != null) {
                while (appenders.hasMoreElements()) {
                    Appender appender = appenders.nextElement();
                    if (appender instanceof FileAppender) {
                        FileAppender fileAppender = (FileAppender) appender;
                        String filename = fileAppender.getFile();
                        file = new File(filename);
                        break;
                    }
                }
            }
        }
    } catch (Throwable t) {
    }
}
 
Example #4
Source File: Log4jLoggerAdapter.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Log4jLoggerAdapter() {
	try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
           if (logger != null) {
               Enumeration<Appender> appenders = logger.getAllAppenders();
               if (appenders != null) {
                   while (appenders.hasMoreElements()) {
                       Appender appender = appenders.nextElement();
                       if (appender instanceof FileAppender) {
                           FileAppender fileAppender = (FileAppender)appender;
                           String filename = fileAppender.getFile();
                           file = new File(filename);
                           break;
                       }
                   }
               }
           }
       } catch (Throwable t) {
       }
}
 
Example #5
Source File: ExceptionFilterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
Example #6
Source File: ExceptionFilterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
Example #7
Source File: ExceptionFilterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
Example #8
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void debug(Logger logger, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug(e);
    }
}
 
Example #9
Source File: LogHelper.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public static void debug(Logger logger, String msg, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug(msg, e);
    }
}
 
Example #10
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void debug(Logger logger, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug(e);
    }
}
 
Example #11
Source File: FailsafeLoggerTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailSafeForLoggingMethod() {
    Logger failLogger = mock(Logger.class);
    FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger);

    doThrow(new RuntimeException()).when(failLogger).error(anyString());
    doThrow(new RuntimeException()).when(failLogger).warn(anyString());
    doThrow(new RuntimeException()).when(failLogger).info(anyString());
    doThrow(new RuntimeException()).when(failLogger).debug(anyString());
    doThrow(new RuntimeException()).when(failLogger).trace(anyString());

    failsafeLogger.error("error");
    failsafeLogger.warn("warn");
    failsafeLogger.info("info");
    failsafeLogger.debug("debug");
    failsafeLogger.trace("info");

    doThrow(new RuntimeException()).when(failLogger).error(any(Throwable.class));
    doThrow(new RuntimeException()).when(failLogger).warn(any(Throwable.class));
    doThrow(new RuntimeException()).when(failLogger).info(any(Throwable.class));
    doThrow(new RuntimeException()).when(failLogger).debug(any(Throwable.class));
    doThrow(new RuntimeException()).when(failLogger).trace(any(Throwable.class));

    failsafeLogger.error(new Exception("error"));
    failsafeLogger.warn(new Exception("warn"));
    failsafeLogger.info(new Exception("info"));
    failsafeLogger.debug(new Exception("debug"));
    failsafeLogger.trace(new Exception("trace"));

    failsafeLogger.error("error", new Exception("error"));
    failsafeLogger.warn("warn", new Exception("warn"));
    failsafeLogger.info("info", new Exception("info"));
    failsafeLogger.debug("debug", new Exception("debug"));
    failsafeLogger.trace("trace", new Exception("trace"));
}
 
Example #12
Source File: FailsafeLoggerTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSuccessLogger() {
    Logger successLogger = mock(Logger.class);
    FailsafeLogger failsafeLogger = new FailsafeLogger(successLogger);
    failsafeLogger.error("error");
    failsafeLogger.warn("warn");
    failsafeLogger.info("info");
    failsafeLogger.debug("debug");
    failsafeLogger.trace("info");

    verify(successLogger).error(anyString());
    verify(successLogger).warn(anyString());
    verify(successLogger).info(anyString());
    verify(successLogger).debug(anyString());
    verify(successLogger).trace(anyString());

    failsafeLogger.error(new Exception("error"));
    failsafeLogger.warn(new Exception("warn"));
    failsafeLogger.info(new Exception("info"));
    failsafeLogger.debug(new Exception("debug"));
    failsafeLogger.trace(new Exception("trace"));

    failsafeLogger.error("error", new Exception("error"));
    failsafeLogger.warn("warn", new Exception("warn"));
    failsafeLogger.info("info", new Exception("info"));
    failsafeLogger.debug("debug", new Exception("debug"));
    failsafeLogger.trace("trace", new Exception("trace"));
}
 
Example #13
Source File: LogHelper.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static void error(Logger logger, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isErrorEnabled()) {
        logger.error(e);
    }
}
 
Example #14
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void error(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isErrorEnabled()) {
        logger.error(msg);
    }
}
 
Example #15
Source File: LogHelper.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static void error(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isErrorEnabled()) {
        logger.error(msg);
    }
}
 
Example #16
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void trace(Logger logger, Throwable throwable) {
    if (logger == null) {
        return;
    }

    if (logger.isTraceEnabled()) {
        logger.trace(throwable);
    }
}
 
Example #17
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void debug(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug(msg);
    }
}
 
Example #18
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void trace(Logger logger, Throwable throwable) {
    if (logger == null) {
        return;
    }

    if (logger.isTraceEnabled()) {
        logger.trace(throwable);
    }
}
 
Example #19
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void debug(Logger logger, String msg, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug(msg, e);
    }
}
 
Example #20
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void info(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isInfoEnabled()) {
        logger.info(msg);
    }
}
 
Example #21
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void warn(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isWarnEnabled()) {
        logger.warn(msg);
    }
}
 
Example #22
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void debug(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isDebugEnabled()) {
        logger.debug(msg);
    }
}
 
Example #23
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void error(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isErrorEnabled()) {
        logger.error(msg);
    }
}
 
Example #24
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void error(Logger logger, String msg, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isErrorEnabled()) {
        logger.error(msg, e);
    }
}
 
Example #25
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void warn(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isWarnEnabled()) {
        logger.warn(msg);
    }
}
 
Example #26
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void error(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isErrorEnabled()) {
        logger.error(msg);
    }
}
 
Example #27
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void info(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isInfoEnabled()) {
        logger.info(msg);
    }
}
 
Example #28
Source File: LogHelper.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static void info(Logger logger, String msg, Throwable e) {
    if (logger == null) {
        return;
    }

    if (logger.isInfoEnabled()) {
        logger.info(msg, e);
    }
}
 
Example #29
Source File: LogHelper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void warn(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isWarnEnabled()) {
        logger.warn(msg);
    }
}
 
Example #30
Source File: LogHelper.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public static void trace(Logger logger, String msg) {
    if (logger == null) {
        return;
    }

    if (logger.isTraceEnabled()) {
        logger.trace(msg);
    }
}