You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/04/16 22:04:59 UTC
svn commit: r1588052 - in /logging/log4j/log4j2/trunk: ./ log4j-camel/
log4j-camel/src/ log4j-camel/src/main/ log4j-camel/src/main/java/
log4j-camel/src/main/java/org/ log4j-camel/src/main/java/org/apache/
log4j-camel/src/main/java/org/apache/logging/ ...
Author: mattsicker
Date: Wed Apr 16 20:04:58 2014
New Revision: 1588052
URL: http://svn.apache.org/r1588052
Log:
Add initial implementation of Log4j Camel component.
- Still needs more unit tests, but there's several that can be stolen from camel-core.
Added:
logging/log4j/log4j2/trunk/log4j-camel/
logging/log4j/log4j2/trunk/log4j-camel/pom.xml (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/
logging/log4j/log4j2/trunk/log4j-camel/src/main/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogComponent.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogEndpoint.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProcessor.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProducer.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LoggerWrapper.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/component/
logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/component/log4j
logging/log4j/log4j2/trunk/log4j-camel/src/test/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogEndpointTest.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogInputStreamTest.java (with props)
logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/
logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/log4j2.xml (with props)
Modified:
logging/log4j/log4j2/trunk/pom.xml
Added: logging/log4j/log4j2/trunk/log4j-camel/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/pom.xml?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/pom.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/pom.xml Wed Apr 16 20:04:58 2014
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <properties>
+ <camel.version>2.13.0</camel.version>
+ </properties>
+
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>2.0-rc2-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+
+ <artifactId>log4j-camel</artifactId>
+ <version>2.0-rc2-SNAPSHOT</version>
+ <name>Log4j 2 Camel Component</name>
+ <description>Use Log4j 2 as a Camel component</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>${camel.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>${camel.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Propchange: logging/log4j/log4j2/trunk/log4j-camel/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogComponent.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogComponent.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogComponent.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogComponent.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.camel;
+
+import java.util.Map;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.processor.DefaultExchangeFormatter;
+import org.apache.camel.spi.ExchangeFormatter;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.MarkerManager;
+
+/**
+ * Log4j Component for Camel.
+ */
+public class LogComponent extends UriEndpointComponent {
+
+ private static final Logger LOGGER = LogManager.getLogger();
+
+ private ExchangeFormatter exchangeFormatter;
+
+ public LogComponent() {
+ super(LogEndpoint.class);
+ }
+
+ @Override
+ protected Endpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
+ final Level level = getLevel(parameters);
+ final LogEndpoint endpoint = new LogEndpoint(uri, this);
+ endpoint.setLevel(level.name());
+ setProperties(endpoint, parameters);
+
+ final LoggerWrapper logger = new LoggerWrapper();
+ logger.setLogger(getLogger(uri, remaining, parameters));
+ logger.setLevel(getLevel(parameters));
+ if (endpoint.getMarker() != null) {
+ logger.setMarker(MarkerManager.getMarker(endpoint.getMarker()));
+ }
+ return configureEndpoint(endpoint, logger, parameters);
+ }
+
+ private Logger getLogger(final String uri, final String remaining, final Map<String, Object> parameters) {
+ final Logger providedLogger = getAndRemoveOrResolveReferenceParameter(parameters, "logger", Logger.class);
+ if (providedLogger != null) {
+ return providedLogger;
+ }
+ final Map<String, Logger> availableLoggers = getCamelContext().getRegistry().findByTypeWithName(Logger.class);
+ if (availableLoggers.size() == 1) {
+ final Logger logger = availableLoggers.values().iterator().next();
+ LOGGER.info("Using custom logger: {}", logger);
+ return logger;
+ }
+ LOGGER.info("More than one {} instance found in the registry. Falling back to creating logger from URI {}",
+ Logger.class.getName(), uri);
+ return LogManager.getLogger(remaining);
+ }
+
+ private Level getLevel(final Map<String, Object> parameters) {
+ final String levelName = getAndRemoveParameter(parameters, "level", String.class, "INFO");
+ return Level.toLevel(levelName);
+ }
+
+ private Endpoint configureEndpoint(final LogEndpoint endpoint, final LoggerWrapper logger, final Map<String, Object> parameters) throws Exception {
+ final Processor processor = new LogProcessor(logger, configureExchangeFormatter(parameters));
+ endpoint.setLogger(processor);
+ return endpoint;
+ }
+
+ private ExchangeFormatter configureExchangeFormatter(final Map<String, Object> parameters) throws Exception {
+ // first, try to use the user-specified formatter (or the one picked up from the Registry and transferred to
+ // the property by a previous endpoint initialisation); if null, try to pick it up from the Registry now
+ ExchangeFormatter localFormatter = exchangeFormatter;
+ if (localFormatter == null) {
+ localFormatter = getCamelContext().getRegistry().lookupByNameAndType("logFormatter", ExchangeFormatter.class);
+ if (localFormatter != null) {
+ exchangeFormatter = localFormatter;
+ setProperties(exchangeFormatter, parameters);
+ }
+ }
+ // if no formatter is available in the Registry, create a local one of the default type, for a single use
+ if (localFormatter == null) {
+ localFormatter = new DefaultExchangeFormatter();
+ setProperties(localFormatter, parameters);
+ }
+ return localFormatter;
+ }
+
+ public ExchangeFormatter getExchangeFormatter() {
+ return exchangeFormatter;
+ }
+
+ public void setExchangeFormatter(final ExchangeFormatter exchangeFormatter) {
+ this.exchangeFormatter = exchangeFormatter;
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogEndpoint.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogEndpoint.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogEndpoint.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogEndpoint.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.camel;
+
+import org.apache.camel.Component;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.ProcessorEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.ServiceHelper;
+
+/**
+ * @author msicker
+ * @version 1.0.0
+ */
+@UriEndpoint(scheme = "log4j")
+public class LogEndpoint extends ProcessorEndpoint {
+
+ private volatile Processor logger;
+
+ @UriParam
+ private String level;
+
+ @UriParam
+ private String marker;
+
+ public LogEndpoint() {
+ }
+
+ public LogEndpoint(final String endpointURI, final Component component) {
+ super(endpointURI, component);
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ ServiceHelper.startService(logger);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ ServiceHelper.stopService(logger);
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new LogProducer(this, this.logger);
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return "log4j:" + logger.toString();
+ }
+
+ public Processor getLogger() {
+ return logger;
+ }
+
+ public void setLogger(final Processor logger) {
+ this.logger = logger;
+ setProcessor(this.logger);
+ }
+
+ public String getLevel() {
+ return level;
+ }
+
+ public void setLevel(final String level) {
+ this.level = level;
+ }
+
+ public String getMarker() {
+ return marker;
+ }
+
+ public void setMarker(final String marker) {
+ this.marker = marker;
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProcessor.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProcessor.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProcessor.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProcessor.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.camel;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.DefaultExchangeFormatter;
+import org.apache.camel.spi.ExchangeFormatter;
+import org.apache.camel.util.AsyncProcessorHelper;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+
+/**
+ * Camel Processor for Log4j.
+ */
+public class LogProcessor implements AsyncProcessor {
+
+ private final ExchangeFormatter formatter;
+
+ private final LoggerWrapper logger;
+
+ public LogProcessor() {
+ this(new LoggerWrapper());
+ }
+
+ public LogProcessor(final LoggerWrapper logger) {
+ this(logger, new DefaultExchangeFormatter());
+ }
+
+ public LogProcessor(final LoggerWrapper logger, final ExchangeFormatter formatter) {
+ if (logger == null) {
+ throw new NullPointerException("No LoggerWrapper provided.");
+ }
+ if (formatter == null) {
+ throw new NullPointerException("No ExchangeFormatter provided.");
+ }
+ this.logger = logger;
+ this.formatter = formatter;
+ }
+
+ @Override
+ public boolean process(final Exchange exchange, final AsyncCallback asyncCallback) {
+ if (logger.shouldLog()) {
+ logger.log(formatter.format(exchange));
+ }
+ asyncCallback.done(true);
+ return true;
+ }
+
+ public void process(Exchange exchange, Throwable exception) {
+ if (logger.shouldLog()) {
+ logger.log(formatter.format(exchange), exception);
+ }
+ }
+
+ public void process(Exchange exchange, String message) {
+ if (logger.shouldLog()) {
+ logger.log(formatter.format(exchange) + message);
+ }
+ }
+
+ @Override
+ public void process(final Exchange exchange) throws Exception {
+ AsyncProcessorHelper.process(this, exchange);
+ }
+
+ public LoggerWrapper getLogger() {
+ return logger;
+ }
+
+ public void setLoggerName(final String name) {
+ logger.setLoggerName(name);
+ }
+
+ public void setMarker(final Marker marker) {
+ logger.setMarker(marker);
+ }
+
+ public void setLevel(final Level level) {
+ logger.setLevel(level);
+ }
+
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProducer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProducer.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProducer.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProducer.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.camel;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultAsyncProducer;
+
+/**
+ * Log4j Camel producer. Does essentially the same thing as the Camel Core LogProducer.
+ */
+public class LogProducer extends DefaultAsyncProducer {
+
+ private final Processor logger;
+
+ public LogProducer(final Endpoint endpoint, final Processor logger) {
+ super(endpoint);
+ this.logger = logger;
+ }
+
+ @Override
+ public boolean process(final Exchange exchange, final AsyncCallback asyncCallback) {
+ try {
+ logger.process(exchange);
+ } catch (Exception e) {
+ exchange.setException(e);
+ } finally {
+ asyncCallback.done(true);
+ }
+ return true;
+ }
+
+ public Processor getLogger() {
+ return logger;
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LogProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LoggerWrapper.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LoggerWrapper.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LoggerWrapper.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LoggerWrapper.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.camel;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+
+/**
+ * Logger wrapper for use with Camel.
+ */
+public class LoggerWrapper {
+ private Logger logger = LogManager.getLogger();
+ private Marker marker;
+ private Level level = Level.INFO;
+
+ public boolean shouldLog() {
+ return logger.isEnabled(level, marker);
+ }
+
+ public Logger getLogger() {
+ return logger;
+ }
+
+ public void setLogger(final Logger logger) {
+ this.logger = logger;
+ }
+
+ public void setLoggerName(final String name) {
+ this.logger = LogManager.getLogger(name);
+ }
+
+ public Marker getMarker() {
+ return marker;
+ }
+
+ public void setMarker(final Marker marker) {
+ this.marker = marker;
+ }
+
+ public Level getLevel() {
+ return level;
+ }
+
+ public void setLevel(final Level level) {
+ this.level = level;
+ }
+
+ public void log(final String message) {
+ logger.log(level, marker, message);
+ }
+
+ public void log(final String message, final Throwable exception) {
+ logger.log(level, marker, message, exception);
+ }
+
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/main/java/org/apache/logging/log4j/camel/LoggerWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/component/log4j
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/component/log4j?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/component/log4j (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/main/resources/META-INF/services/org/apache/camel/component/log4j Wed Apr 16 20:04:58 2014
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class=org.apache.logging.log4j.camel.LogComponent
\ No newline at end of file
Added: logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogEndpointTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogEndpointTest.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogEndpointTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogEndpointTest.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,50 @@
+package org.apache.logging.log4j.camel;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @author msicker
+ * @version 1.0.0
+ */
+public class LogEndpointTest extends ContextTestSupport {
+
+ private static Exchange logged;
+
+ private static class MyLogger extends LogProcessor {
+ @Override
+ public void process(final Exchange exchange) throws Exception {
+ super.process(exchange);
+ logged = exchange;
+ }
+
+ @Override
+ public String toString() {
+ return "myLogger";
+ }
+ }
+
+ public void testLogEndpoint() throws Exception {
+ final MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ template.sendBody("direct:start", "Hello World");
+ assertMockEndpointsSatisfied();
+ assertNotNull(logged);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ final LogEndpoint endpoint = new LogEndpoint();
+ endpoint.setCamelContext(context);
+ endpoint.setLogger(new MyLogger());
+ assertEquals("log4j:myLogger", endpoint.getEndpointUri());
+ from("direct:start").to(endpoint).to("mock:result");
+ }
+ };
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogInputStreamTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogInputStreamTest.java?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogInputStreamTest.java (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogInputStreamTest.java Wed Apr 16 20:04:58 2014
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.camel;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @author msicker
+ * @version 1.0.0
+ */
+public class LogInputStreamTest extends ContextTestSupport {
+
+ private static final String TEST_BODY = "Hello World";
+
+ public void testA() throws Exception {
+ final MockEndpoint mock = getMockEndpoint("mock:a");
+ mock.expectedBodiesReceived(TEST_BODY);
+ final InputStream is = new ByteArrayInputStream(TEST_BODY.getBytes());
+ template.sendBody("direct:a", is);
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testB() throws Exception {
+ final MockEndpoint mock = getMockEndpoint("mock:b");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().convertToString().isEqualTo(TEST_BODY);
+ final InputStream is = new ByteArrayInputStream(TEST_BODY.getBytes());
+ template.sendBody("direct:b", is);
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:a")
+ .to("log4j:a")
+ .to("mock:a");
+
+ from("direct:b")
+ .to("log4j:b")
+ .to("mock:b");
+ }
+ };
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/test/java/org/apache/logging/log4j/camel/LogInputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/log4j2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/log4j2.xml?rev=1588052&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/log4j2.xml (added)
+++ logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/log4j2.xml Wed Apr 16 20:04:58 2014
@@ -0,0 +1,35 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<Configuration>
+ <Appenders>
+ <List name="Camel">
+ <PatternLayout pattern="%m%n"/>
+ </List>
+ <Console name="Console">
+ <PatternLayout pattern="%m%n"/>
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Logger name="org.apache.logging.log4j.camel" level="INFO">
+ <AppenderRef ref="Camel"/>
+ </Logger>
+ <Root level="INFO">
+ <AppenderRef ref="Console"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
Propchange: logging/log4j/log4j2/trunk/log4j-camel/src/test/resources/log4j2.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: logging/log4j/log4j2/trunk/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/pom.xml?rev=1588052&r1=1588051&r2=1588052&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/pom.xml (original)
+++ logging/log4j/log4j2/trunk/pom.xml Wed Apr 16 20:04:58 2014
@@ -914,6 +914,7 @@
<module>log4j-bom</module>
<module>log4j-plugin-processor</module>
<module>log4j-streams</module>
+ <module>log4j-camel</module>
</modules>
<profiles>
<profile>