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;
}
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;
}
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;
}
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);
}
}
}
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);
}
Aggregations