Search in sources :

Example 1 with CamelLogger

use of org.apache.camel.util.CamelLogger in project camel by apache.

the class LogEndpoint method createLogger.

/**
     * Creates the logger {@link Processor} to be used.
     */
protected Processor createLogger() throws Exception {
    Processor answer;
    // setup a new logger here
    CamelLogger camelLogger;
    LoggingLevel loggingLevel = LoggingLevel.INFO;
    if (level != null) {
        loggingLevel = LoggingLevel.valueOf(level);
    }
    if (providedLogger == null) {
        camelLogger = new CamelLogger(loggerName, loggingLevel, getMarker());
    } else {
        camelLogger = new CamelLogger(providedLogger, loggingLevel, getMarker());
    }
    if (getGroupSize() != null) {
        answer = new ThroughputLogger(camelLogger, getGroupSize());
    } else if (getGroupInterval() != null) {
        Boolean groupActiveOnly = getGroupActiveOnly() != null ? getGroupActiveOnly() : Boolean.TRUE;
        Long groupDelay = getGroupDelay();
        answer = new ThroughputLogger(camelLogger, this.getCamelContext(), getGroupInterval(), groupDelay, groupActiveOnly);
    } else {
        answer = new CamelLogProcessor(camelLogger, localFormatter);
    }
    // the logger is the processor
    setProcessor(answer);
    return answer;
}
Also used : CamelLogger(org.apache.camel.util.CamelLogger) CamelLogProcessor(org.apache.camel.processor.CamelLogProcessor) Processor(org.apache.camel.Processor) LoggingLevel(org.apache.camel.LoggingLevel) CamelLogProcessor(org.apache.camel.processor.CamelLogProcessor) ThroughputLogger(org.apache.camel.processor.ThroughputLogger)

Example 2 with CamelLogger

use of org.apache.camel.util.CamelLogger in project camel by apache.

the class MockComponent method createEndpoint.

@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;
}
Also used : CamelLogger(org.apache.camel.util.CamelLogger) Processor(org.apache.camel.Processor) ThroughputLogger(org.apache.camel.processor.ThroughputLogger)

Example 3 with CamelLogger

use of org.apache.camel.util.CamelLogger in project camel by apache.

the class DataSetConsumer method createReporter.

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;
}
Also used : CamelLogger(org.apache.camel.util.CamelLogger) ThroughputLogger(org.apache.camel.processor.ThroughputLogger)

Example 4 with CamelLogger

use of org.apache.camel.util.CamelLogger in project camel by apache.

the class BaseTypeConverterRegistry method addTypeConverter.

@Override
public void addTypeConverter(Class<?> toType, Class<?> fromType, TypeConverter typeConverter) {
    log.trace("Adding type converter: {}", typeConverter);
    TypeMapping key = new TypeMapping(toType, fromType);
    TypeConverter converter = typeMappings.get(key);
    if (typeConverter != converter) {
        // add the converter unless we should ignore
        boolean add = true;
        // if converter is not null then a duplicate exists
        if (converter != null) {
            if (typeConverterExists == TypeConverterExists.Override) {
                CamelLogger logger = new CamelLogger(log, typeConverterExistsLoggingLevel);
                logger.log("Overriding type converter from: " + converter + " to: " + typeConverter);
            } else if (typeConverterExists == TypeConverterExists.Ignore) {
                CamelLogger logger = new CamelLogger(log, typeConverterExistsLoggingLevel);
                logger.log("Ignoring duplicate type converter from: " + converter + " to: " + typeConverter);
                add = false;
            } else {
                // we should fail
                throw new TypeConverterExistsException(toType, fromType);
            }
        }
        if (add) {
            typeMappings.put(key, typeConverter);
            // remove any previous misses, as we added the new type converter
            misses.remove(key);
        }
    }
}
Also used : TypeConverter(org.apache.camel.TypeConverter) CamelLogger(org.apache.camel.util.CamelLogger) TypeConverterExistsException(org.apache.camel.TypeConverterExistsException)

Example 5 with CamelLogger

use of org.apache.camel.util.CamelLogger in project camel by apache.

the class LogDefinition method createProcessor.

@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().getGlobalOption(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);
}
Also used : CamelLogger(org.apache.camel.util.CamelLogger) LoggingLevel(org.apache.camel.LoggingLevel) Expression(org.apache.camel.Expression) LogProcessor(org.apache.camel.processor.LogProcessor) Logger(org.slf4j.Logger) CamelLogger(org.apache.camel.util.CamelLogger)

Aggregations

CamelLogger (org.apache.camel.util.CamelLogger)8 ThroughputLogger (org.apache.camel.processor.ThroughputLogger)4 LoggingLevel (org.apache.camel.LoggingLevel)2 Processor (org.apache.camel.Processor)2 Logger (org.slf4j.Logger)2 CamelContext (org.apache.camel.CamelContext)1 Expression (org.apache.camel.Expression)1 TypeConverter (org.apache.camel.TypeConverter)1 TypeConverterExistsException (org.apache.camel.TypeConverterExistsException)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 CamelLogProcessor (org.apache.camel.processor.CamelLogProcessor)1 LogProcessor (org.apache.camel.processor.LogProcessor)1 LoggingErrorHandler (org.apache.camel.processor.LoggingErrorHandler)1 RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)1