You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2022/01/02 16:29:47 UTC
[GitHub] [logging-log4j2] vorburger commented on a change in pull request #653: (DRAFT, WIP - DO NOT MERGE YET, BUT INITIAL REVIEW WELCOME) Release 2.x log4j-to-jul JDK Logging Bridge (LOG4J2-3282)
vorburger commented on a change in pull request #653:
URL: https://github.com/apache/logging-log4j2/pull/653#discussion_r777230229
##########
File path: log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java
##########
@@ -0,0 +1,246 @@
+/*
+ * 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.tojul;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.MessageFactory;
+import org.apache.logging.log4j.spi.AbstractLogger;
+
+/**
+ * Implementation of {@link org.apache.logging.log4j.Logger} that's backed by a {@link Logger}.
+ *
+ * This implementation currently ignores {@link Marker}.
+ *
+ * @author <a href="http://www.vorburger.ch">Michael Vorburger.ch</a> for Google
+ */
+public class JULLogger extends AbstractLogger {
+ private static final long serialVersionUID = 1L;
+
+ // @VisibleForTesting
+ final Logger logger;
+
+ // This implementation is inspired by org.apache.logging.slf4j.SLF4JLogger
+
+ public JULLogger(final String name, final MessageFactory messageFactory, final Logger logger) {
+ super(name, messageFactory);
+ this.logger = requireNonNull(logger, "logger");
+ }
+
+ public JULLogger(final String name, final Logger logger) {
+ super(name);
+ this.logger = requireNonNull(logger, "logger");
+ }
+
+ @Override
+ public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
+ java.util.logging.Level julLevel = convertLevel(level);
+ if (!logger.isLoggable(julLevel)) {
+ return;
+ }
+ LogRecord record = new LogRecord(julLevel, message.getFormattedMessage()); // TODO getFormat() or getFormattedMessage() ?
+ record.setLoggerName(getName()); // TODO getName() or fqcn parameter? What's that?
+ record.setParameters(message.getParameters());
Review comment:
Done. Resolving this thread, and undrafting - this PR is now ready for review, from my side.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org