This is an automated email from the ASF dual-hosted git repository. clebertsuconic pushed a commit to branch new-logging in repository https://gitbox.apache.org/repos/asf/activemq-artemis-native.git
commit 8e3366952a3265b3fa8148024c2f24f7758da500 Author: Clebert Suconic <[email protected]> AuthorDate: Fri Jul 1 10:24:41 2022 -0400 Removing Logger references and its dependencies --- pom.xml | 14 ------ .../artemis/nativo/jlibaio/LibaioContext.java | 12 ++---- .../artemis/nativo/jlibaio/LibaioFile.java | 7 +-- .../{NativeLogger.java => LoggerCallback.java} | 24 +++++------ .../artemis/nativo/jlibaio/NativeLogger.java | 36 ++++++++++++---- .../artemis/nativo/jlibaio/SystemCallback.java | 50 ++++++++++++++++++++++ 6 files changed, 93 insertions(+), 50 deletions(-) diff --git a/pom.xml b/pom.xml index 44ebcf5..16b4602 100644 --- a/pom.xml +++ b/pom.xml @@ -88,20 +88,6 @@ </issueManagement> <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>${slf4j.version}</version> - <scope>provided</scope> - </dependency> - - <!-- ## Test Dependencies --> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <version>${log4j.version}</version> - <scope>test</scope> - </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java index c53f0fa..bdde812 100644 --- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java +++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java @@ -26,9 +26,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * This class is used as an aggregator for the {@link LibaioFile}. * <br> @@ -45,7 +42,6 @@ import org.slf4j.LoggerFactory; */ public class LibaioContext<Callback extends SubmitInfo> implements Closeable { - private static final Logger logger = LoggerFactory.getLogger(LibaioContext.class); private static final AtomicLong totalMaxIO = new AtomicLong(0); /** @@ -73,7 +69,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable { return true; } } catch (Throwable e) { - logger.debug(name + " -> error loading the native library", e); + NativeLogger.debug(name + " -> error loading the native library", e); return false; } @@ -97,12 +93,12 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable { }); break; } else { - logger.debug("Library " + library + " not found!"); + NativeLogger.debug("Library " + library + " not found!"); } } if (!loaded) { - logger.debug("Couldn't locate LibAIO Wrapper"); + NativeLogger.debug("Couldn't locate LibAIO Wrapper"); } } @@ -246,7 +242,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable { try { ioSpace.tryAcquire(queueSize, 10, TimeUnit.SECONDS); } catch (Exception e) { - logger.error(e.getMessage(), e); + NativeLogger.warn(e.getMessage(), e); } } totalMaxIO.addAndGet(-queueSize); diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java index febe26a..f03ed87 100644 --- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java +++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java @@ -19,16 +19,11 @@ package org.apache.activemq.artemis.nativo.jlibaio; import java.io.IOException; import java.nio.ByteBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * This is an extension to use libaio. */ public final class LibaioFile<Callback extends SubmitInfo> implements AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(LibaioFile.class); - protected boolean open; /** * This represents a structure allocated on the native @@ -125,7 +120,7 @@ public final class LibaioFile<Callback extends SubmitInfo> implements AutoClosea try { LibaioContext.fill(fd, alignment, size); } catch (OutOfMemoryError e) { - logger.debug("Didn't have enough memory to allocate {} bytes in memory, using simple fallocate", size); + NativeLogger.warn("Did not have enough memory to allocate " + size + " bytes in memory while filling the file, using simple fallocate"); LibaioContext.fallocate(fd, size); } } diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java similarity index 58% copy from src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java copy to src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java index f24c214..dc41013 100644 --- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java +++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java @@ -14,24 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.activemq.artemis.nativo.jlibaio; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -/** - * Logger Code 16 - */ -public class NativeLogger { +/** I am keeping Artemis Native Log Free, so it will be simpler to compile it, especially on the include bits. + * If you want the NativeLogger redirected to any framework you can use the method NativeLogger.setCallback(LoggerCallback) on your + * usage implementation*/ +public interface LoggerCallback { + + void info(String message); - private static final Logger logger = LoggerFactory.getLogger(NativeLogger.class.getPackage().getName()); + void warn(String message); - public static final String PROJECT_PREFIX = "jlibaio"; + void warn(String message, Throwable e); - private static final int DIFFERENT_VERSION_ID = 163001; - private static final String DIFFERENT_VERSION = PROJECT_PREFIX + DIFFERENT_VERSION_ID + " You have a native library with a different version than expected"; + void debug(String message); - public final static void incompatibleNativeLibrary() { - logger.warn(DIFFERENT_VERSION); - } + void debug(String message, Throwable e); } diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java index f24c214..c5ddd81 100644 --- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java +++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java @@ -16,22 +16,40 @@ */ package org.apache.activemq.artemis.nativo.jlibaio; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Logger Code 16 - */ public class NativeLogger { - private static final Logger logger = LoggerFactory.getLogger(NativeLogger.class.getPackage().getName()); - public static final String PROJECT_PREFIX = "jlibaio"; + private static LoggerCallback loggerCallback = new SystemCallback(); + + public static void setLoggerCallback(LoggerCallback callback) { + loggerCallback = callback; + } + private static final int DIFFERENT_VERSION_ID = 163001; private static final String DIFFERENT_VERSION = PROJECT_PREFIX + DIFFERENT_VERSION_ID + " You have a native library with a different version than expected"; public final static void incompatibleNativeLibrary() { - logger.warn(DIFFERENT_VERSION); + warn(DIFFERENT_VERSION); + } + + public final static void info(String message) { + loggerCallback.info(message); + } + + public final static void warn(String message) { + loggerCallback.warn(message); + } + + public final static void warn(String message, Throwable e) { + loggerCallback.warn(message, e); + } + + public final static void debug(String message) { + loggerCallback.debug(message); + } + + public final static void debug(String message, Throwable e) { + loggerCallback.debug(message, e); } } diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java new file mode 100644 index 0000000..b50c209 --- /dev/null +++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java @@ -0,0 +1,50 @@ +/* + * 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.activemq.artemis.nativo.jlibaio; + +/** This will use System.err for warn and System.out for info */ +public class SystemCallback implements LoggerCallback { + + private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty(SystemCallback.class.getName() + ".DEBUG", "false")); + + public void debug(String message, Throwable e) { + if (DEBUG) { + System.out.println("Debug from ArtemisNative: " + message); + e.printStackTrace(System.out); + } + } + + public void debug(String message) { + if (DEBUG) { + System.out.println("Debug from ArtemisNative: " + message); + } + } + + public void info(String message) { + System.out.println("Information from ArtemisNative: " + message); + } + + public void warn(String message) { + System.err.println("Warning from ArtemisNative: " + message); + } + + public void warn(String message, Throwable e) { + System.err.println("Warning from ArtemisNative: " + message); + e.printStackTrace(System.err); + } +}
