Java 类org.apache.camel.util.CamelLogger 实例源码

项目:Camel    文件:LoggingErrorHandlerBuilder.java   
public Processor createErrorHandler(final RouteContext routeContext, final Processor processor) {
    CamelLogger logger = new CamelLogger(log, level);

    // configure policy to use the selected logging level, and only log exhausted
    RedeliveryPolicy policy = new RedeliveryPolicy();
    policy.setLogExhausted(true);
    policy.setRetriesExhaustedLogLevel(level);
    policy.setLogStackTrace(true);
    policy.setLogRetryAttempted(false);
    policy.setRetryAttemptedLogLevel(LoggingLevel.OFF);
    policy.setLogRetryStackTrace(false);
    policy.setLogContinued(false);
    policy.setLogHandled(false);

    LoggingErrorHandler handler = new LoggingErrorHandler(routeContext.getCamelContext(), processor, logger,
            policy, getExceptionPolicyStrategy());
    configure(routeContext, handler);
    return handler;
}
项目:Camel    文件:FileIdempotentRepositoryReadLockStrategy.java   
@Override
public boolean acquireExclusiveReadLock(GenericFileOperations<File> operations, GenericFile<File> file, Exchange exchange) throws Exception {
    // in clustered mode then another node may have processed the file so we must check here again if the file exists
    File path = file.getFile();
    if (!path.exists()) {
        return false;
    }

    // check if we can begin on this file
    String key = asKey(file);
    boolean answer = idempotentRepository.add(key);
    if (!answer) {
        // another node is processing the file so skip
        CamelLogger.log(LOG, readLockLoggingLevel, "Cannot acquire read lock. Will skip the file: " + file);
    }
    return answer;
}
项目:Camel    文件:ThroughPutLoggerTest.java   
public void testLogStringDurationIsNotZero() throws Exception {
    CamelContext camel = new DefaultCamelContext();
    camel.start();

    Logger logger = EasyMock.createMock(Logger.class);
    logger.isInfoEnabled();
    EasyMock.expectLastCall().andReturn(true).atLeastOnce();
    logger.info(EasyMock.startsWith("Received: 10"));
    EasyMock.expectLastCall().once();
    logger.info(EasyMock.startsWith("Received: 20"));
    EasyMock.expectLastCall().once();
    EasyMock.replay(logger);
    ThroughputLogger underTest = new ThroughputLogger(new CamelLogger(logger));
    underTest.setGroupSize(10);
    for (int i = 0; i < 25; i++) {
        underTest.process(new DefaultExchange(camel));
    }
    EasyMock.verify(logger);

    camel.stop();
}
项目:Camel    文件:Mina2Producer.java   
public Mina2Producer(Mina2Endpoint endpoint) throws Exception {
    super(endpoint);
    this.configuration = endpoint.getConfiguration();
    this.lazySessionCreation = configuration.isLazySessionCreation();
    this.timeout = configuration.getTimeout();
    this.sync = configuration.isSync();
    this.noReplyLogger = new CamelLogger(LOG, configuration.getNoReplyLogLevel());

    String protocol = configuration.getProtocol();
    if (protocol.equals("tcp")) {
        setupSocketProtocol(protocol);
    } else if (configuration.isDatagramProtocol()) {
        setupDatagramProtocol(protocol);
    } else if (protocol.equals("vm")) {
        setupVmProtocol(protocol);
    }
}
项目:Camel    文件:Tracer.java   
/**
 * Gets the logger to be used for tracers that can format and log a given exchange.
 *
 * @param formatter the exchange formatter
 * @return the logger to use
 */
public synchronized CamelLogProcessor getLogger(ExchangeFormatter formatter) {
    if (logger == null) {
        logger = new CamelLogProcessor(new CamelLogger(getLogName(), getLogLevel()), formatter);
    }
    return logger;
}
项目:Camel    文件:ThroughputLogger.java   
public ThroughputLogger(CamelLogger log, CamelContext camelContext, Long groupInterval, Long groupDelay, Boolean groupActiveOnly) {
    this(log);
    this.camelContext = camelContext;
    setGroupInterval(groupInterval);
    setGroupActiveOnly(groupActiveOnly);
    if (groupDelay != null) {
        setGroupDelay(groupDelay);
    }
}
项目:Camel    文件:DataSetEndpoint.java   
protected ThroughputLogger createReporter() {
    // must sanitize uri to avoid logging sensitive information
    String uri = URISupport.sanitizeUri(getEndpointUri());
    CamelLogger logger = new CamelLogger(uri);
    ThroughputLogger answer = new ThroughputLogger(logger, (int) this.getDataSet().getReportCount());
    answer.setAction("Received");
    return answer;
}
项目:Camel    文件:DataSetConsumer.java   
protected ThroughputLogger createReporter() {
    // must sanitize uri to avoid logging sensitive information
    String uri = URISupport.sanitizeUri(endpoint.getEndpointUri());
    CamelLogger logger = new CamelLogger(uri);
    ThroughputLogger answer = new ThroughputLogger(logger, (int) endpoint.getDataSet().getReportCount());
    answer.setAction("Sent");
    return answer;
}
项目:Camel    文件:MockComponent.java   
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    MockEndpoint endpoint = new MockEndpoint(uri, this);
    endpoint.setName(remaining);

    Integer value = getAndRemoveParameter(parameters, "reportGroup", Integer.class);
    if (value != null) {
        Processor reporter = new ThroughputLogger(new CamelLogger("org.apache.camel.component.mock:" + remaining), value);
        endpoint.setReporter(reporter);
        endpoint.setReportGroup(value);
    }
    return endpoint;
}
项目:Camel    文件:HttpServerChannelHandler.java   
/**
 * Authenticates the http basic auth subject.
 *
 * @param authenticator      the authenticator
 * @param principal          the principal
 * @return <tt>true</tt> if username and password is valid, <tt>false</tt> if not
 */
protected Subject authenticate(SecurityAuthenticator authenticator, LoggingLevel deniedLoggingLevel, HttpPrincipal principal) {
    try {
        return authenticator.login(principal);
    } catch (LoginException e) {
        CamelLogger logger = new CamelLogger(LOG, deniedLoggingLevel);
        logger.log("Cannot login " + principal.getName() + " due " + e.getMessage(), e);
    }
    return null;
}
项目:Camel    文件:HttpServerChannelHandler.java   
/**
 * Authenticates the http basic auth subject.
 *
 * @param authenticator      the authenticator
 * @param principal          the principal
 * @return <tt>true</tt> if username and password is valid, <tt>false</tt> if not
 */
protected Subject authenticate(SecurityAuthenticator authenticator, LoggingLevel deniedLoggingLevel, HttpPrincipal principal) {
    try {
        return authenticator.login(principal);
    } catch (LoginException e) {
        CamelLogger logger = new CamelLogger(LOG, deniedLoggingLevel);
        logger.log("Cannot login " + principal.getName() + " due " + e.getMessage(), e);
    }
    return null;
}
项目:Camel    文件:MinaConsumer.java   
public MinaConsumer(final MinaEndpoint endpoint, Processor processor) {
    super(endpoint, processor);
    this.address = endpoint.getAddress();
    this.acceptor = endpoint.getAcceptor();
    this.connector = endpoint.getConnector();
    this.protocol = endpoint.getConfiguration().getProtocol();
    this.clientMode = endpoint.getConfiguration().isClientMode();
    this.sync = endpoint.getConfiguration().isSync();
    this.noReplyLogger = new CamelLogger(LOG, endpoint.getConfiguration().getNoReplyLogLevel());
}
项目:Camel    文件:MinaProducer.java   
public MinaProducer(MinaEndpoint endpoint) {
    super(endpoint);
    this.lazySessionCreation = endpoint.getConfiguration().isLazySessionCreation();
    this.timeout = endpoint.getConfiguration().getTimeout();
    this.sync = endpoint.getConfiguration().isSync();
    this.noReplyLogger = new CamelLogger(LOG, endpoint.getConfiguration().getNoReplyLogLevel());
}
项目:camel-file-loadbalancer    文件:LoadBalancedFileConsumerTest.java   
@Test
public void canCreateConsumer() {
    String uri = "lb-file://" + rootDirectory + "?initialDelay=1s&delay=10s&priorityFileFilterFactory=#defaultPriorityFileFilterFactory&runLoggingLevel=INFO";

    LogProcessor processor = new LogProcessor(ExpressionBuilder.simpleExpression("${body}"), new CamelLogger());
    LoadBalancedFileEndpoint loadBalancedFileEndpoint = new LoadBalancedFileEndpoint(uri, new LoadBalancedFileComponent(context));

    LoadBalancedFileConsumer consumer = new LoadBalancedFileConsumer(loadBalancedFileEndpoint, processor, new FileOperations());

    Assert.assertNotNull(consumer);
}
项目:eds    文件:LogicRouter.java   
@Override
    public void configure() throws Exception {
        // context error handler
      onException(Exception.class)
      .handled(false)
      .bean("consumerHelper","error");
        errorHandler(
                defaultErrorHandler()
//              .exceptionPolicyStrategy(exceptionPolicyStrategy)
//              .onPrepareFailure(processor)
                .maximumRedeliveries(10) // x 次后将进入activemq 默认的死信队列,-1为不进入
                .logger(new CamelLogger(LoggerNames.CONSUME_ERROR_LOGGER, LoggingLevel.ERROR))
                .retryAttemptedLogLevel(LoggingLevel.WARN)
                .allowRedeliveryWhileStopping(false) // 关闭时无需重发 业务逻辑无需重试,因为依赖的服务如dubbo可能已经关闭
                .backOffMultiplier(1.5)  // 指数退避
                .useExponentialBackOff()
                ) ;

        Set<String> enabledGroupSet = logicConsumerConfig.getEnabledConsumerGroupSet();
        Set<String> enabledNameSet = logicConsumerConfig.getEnabledConsumerNameSet();
        for(Element ele : logicConsumerConfig.getList()){
          String name = ele.getName();
      if(enabledNameSet.size() > 0 && !enabledNameSet.contains(name)){
        continue;
      }
      String group = ele.getGroup();
      if(enabledGroupSet.size() > 0 && !enabledGroupSet.contains(group)){
        continue;
      }
          String prefix = ele.getType().compareTo(Type.internal) == 0 ? EdsConstants.QUEUE_PREFIX : "";
            String from = ele.getFromProtocol() + ':' + prefix + ele.getFrom();
            String proc = ele.getProcessor();
            int poolSize = ele.getConcurrencyMin() ;
            int maxPoolSize = ele.getConcurrencyMax();
            String options = ele.getOptions();
            if(options != null){
              if(options.startsWith("?")){
                from += options;
              }else{
                from += "?" + options;
              }
            }
            from(from)
              .id(ele.getName())
              .routeId("logic_"+ele.getName())
              .transacted()
              .threads(poolSize, maxPoolSize,threadPoolProfile.getId())
              .bean("consumerHelper", "before")
              .log(LoggingLevel.INFO,LoggerNames.CONSUME_LOGGER,"${headers}|${body}")
                // 这里设置了线程池,上面的requestId要重新设置
//              .doTry()  // 使用doTry doCatch doFinaly 将不能使用默认的error handler
                  .process(proc)
//                .bean("consumerHelper","error")
//              .doCatch(Exception.class)
                  .bean("consumerHelper","success")
//              .end()  
                ;
        }
    }
项目:eds    文件:DispatcherRouter.java   
@Override
    public void configure() throws Exception {
//      camelContext.setTracing(true);
      onException(Exception.class)
      .handled(false)
      .bean("dispatcherHelper","error");
        errorHandler(
                defaultErrorHandler()
                .maximumRedeliveries(6) // 消费6次不成功进入死信队列 -1 永远不进入死信队列
                .logger(new CamelLogger(LoggerNames.DISPATCH_ERROR_LOGGER, LoggingLevel.ERROR))
                .retryAttemptedLogLevel(LoggingLevel.WARN)
                .backOffMultiplier(1.5)  // 指数退避
                .useExponentialBackOff()
                );
        Set<String> enabledGroupSet = dispatcherConfig.getEnabledDispatchGroupSet();
        Set<String> enabledNameSet = dispatcherConfig.getEnabledDispatchNameSet();
        // 控制开关 shutdown hook
        for(final Element ele : dispatcherConfig.getList()){
          String name = ele.getName();
          if(enabledNameSet.size() > 0 && !enabledNameSet.contains(name)){
            continue;
          }
          String group = ele.getGroup();
          if(enabledGroupSet.size() > 0 && !enabledGroupSet.contains(group)){
            continue;
          }
            String from = ele.getFromProtocol() + ':' + EdsConstants.QUEUE_PREFIX + ele.getFrom();
            List<String> to = ele.getTo();
            to = Lists.transform(to,new Function<String,String>() {
                @Override
                public String apply(String input) {
                    return ele.getToProtocol() + ':' +EdsConstants.QUEUE_PREFIX + input;
                }
            });
            int poolSize = ele.getConcurrencyMin();
            int maxPoolSize = ele.getConcurrencyMax();
            String[] tos = new String[to.size()];
            tos = to.toArray(tos);
            // 定义dispatch routes
//          RouteDefinition rd = 
            from(from)
              .routeId("dispath_"+name)
              .id(name)
              .transacted()
              .threads(poolSize, maxPoolSize, threadPoolProfile.getId())
              .bean("dispatcherHelper","before")
              .log(LoggingLevel.INFO, LoggerNames.DISPATCH_LOGGER, "${headers}|${body}")
              .multicast()
              .to(tos)
              .bean("dispatcherHelper","success");
        }
    }
项目:Camel    文件:LogDefinition.java   
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    ObjectHelper.notEmpty(message, "message", this);

    // use simple language for the message string to give it more power
    Expression exp = routeContext.getCamelContext().resolveLanguage("simple").createExpression(message);

    // get logger explicitely set in the definition
    Logger logger = this.getLogger();

    // get logger which may be set in XML definition
    if (logger == null && ObjectHelper.isNotEmpty(loggerRef)) {
        logger = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), loggerRef, Logger.class);
    }

    if (logger == null) {
        // first - try to lookup single instance in the registry, just like LogComponent
        Map<String, Logger> availableLoggers = routeContext.lookupByType(Logger.class);
        if (availableLoggers.size() == 1) {
            logger = availableLoggers.values().iterator().next();
            LOG.debug("Using custom Logger: {}", logger);
        } else if (availableLoggers.size() > 1) {
            // we should log about this somewhere...
            LOG.debug("More than one {} instance found in the registry. Falling back to create logger by name.", Logger.class.getName());
        }
    }

    if (logger == null) {
        String name = getLogName();
        if (name == null) {
            name = routeContext.getCamelContext().getProperty(Exchange.LOG_EIP_NAME);
            if (name != null) {
                LOG.debug("Using logName from CamelContext properties: {}", name);
            }
        }
        if (name == null) {
            name = routeContext.getRoute().getId();
            LOG.debug("LogName is not configured, using route id as logName: {}", name);
        }
        logger = LoggerFactory.getLogger(name);
    }

    // should be INFO by default
    LoggingLevel level = getLoggingLevel() != null ? getLoggingLevel() : LoggingLevel.INFO;
    CamelLogger camelLogger = new CamelLogger(logger, level, getMarker());

    return new LogProcessor(exp, camelLogger);
}
项目:Camel    文件:ThroughputLogger.java   
public ThroughputLogger(CamelLogger log) {
    this.log = log;
}
项目:Camel    文件:ThroughputLogger.java   
public ThroughputLogger(CamelLogger log, Integer groupSize) {
    this(log);
    setGroupSize(groupSize);
}
项目:Camel    文件:CamelLogProcessor.java   
public CamelLogProcessor() {
    this(new CamelLogger(CamelLogProcessor.class.getName()));
}
项目:Camel    文件:CamelLogProcessor.java   
public CamelLogProcessor(CamelLogger log) {
    this.formatter = new ToStringExchangeFormatter();
    this.log = log;
}
项目:Camel    文件:CamelLogProcessor.java   
public CamelLogProcessor(CamelLogger log, ExchangeFormatter formatter) {
    this(log);
    this.formatter = formatter;
}
项目:Camel    文件:CamelLogProcessor.java   
public CamelLogger getLogger() {
    return log;
}
项目:Camel    文件:LogProcessor.java   
public LogProcessor(Expression expression, CamelLogger logger) {
    this.expression = expression;
    this.logger = logger;
}
项目:Camel    文件:LogProcessor.java   
public CamelLogger getLogger() {
    return logger;
}
项目:Camel    文件:RedeliveryErrorHandler.java   
public CamelLogger getLogger() {
    return logger;
}
项目:Camel    文件:LoggingExceptionHandler.java   
@Deprecated
public LoggingExceptionHandler(Class<?> ownerType) {
    this(null, new CamelLogger(LoggerFactory.getLogger(ownerType), LoggingLevel.WARN));
}
项目:Camel    文件:LoggingExceptionHandler.java   
public LoggingExceptionHandler(CamelContext camelContext, Class<?> ownerType) {
    this(camelContext, new CamelLogger(LoggerFactory.getLogger(ownerType), LoggingLevel.WARN));
}
项目:Camel    文件:LoggingExceptionHandler.java   
@Deprecated
public LoggingExceptionHandler(Class<?> ownerType, LoggingLevel level) {
    this(null, new CamelLogger(LoggerFactory.getLogger(ownerType), level));
}
项目:Camel    文件:LoggingExceptionHandler.java   
public LoggingExceptionHandler(CamelContext camelContext, Class<?> ownerType, LoggingLevel level) {
    this(camelContext, new CamelLogger(LoggerFactory.getLogger(ownerType), level));
}
项目:Camel    文件:LoggingExceptionHandler.java   
@Deprecated
public LoggingExceptionHandler(CamelLogger logger) {
    this(null, logger);
}
项目:Camel    文件:LoggingExceptionHandler.java   
public LoggingExceptionHandler(CamelContext camelContext, CamelLogger logger) {
    this.camelContext = camelContext;
    this.logger = logger;
}
项目:Camel    文件:LoggingExceptionHandler.java   
public LoggingExceptionHandler(CamelLogger logger) {
    super(logger);
}
项目:Camel    文件:LoggingExceptionHandler.java   
public LoggingExceptionHandler(CamelContext camelContext, CamelLogger logger) {
    super(camelContext, logger);
}
项目:Camel    文件:ThrottlingInflightRoutePolicy.java   
public CamelLogger getLogger() {
    if (logger == null) {
        logger = createLogger();
    }
    return logger;
}
项目:Camel    文件:ThrottlingInflightRoutePolicy.java   
protected CamelLogger createLogger() {
    return new CamelLogger(LoggerFactory.getLogger(ThrottlingInflightRoutePolicy.class), getLoggingLevel());
}
项目:Camel    文件:DefaultErrorHandlerBuilder.java   
public CamelLogger getLogger() {
    if (logger == null) {
        logger = createLogger();
    }
    return logger;
}
项目:Camel    文件:DefaultErrorHandlerBuilder.java   
public void setLogger(CamelLogger logger) {
    this.logger = logger;
}
项目:Camel    文件:DefaultErrorHandlerBuilder.java   
protected CamelLogger createLogger() {
    return new CamelLogger(LoggerFactory.getLogger(DefaultErrorHandler.class), LoggingLevel.ERROR);
}
项目:Camel    文件:DeadLetterChannelBuilder.java   
protected CamelLogger createLogger() {
    return new CamelLogger(LoggerFactory.getLogger(DeadLetterChannel.class), LoggingLevel.ERROR);
}