That JMS stuff doesn't look like it belongs here? On 27 June 2017 at 13:12, <[email protected]> wrote:
> Repository: logging-log4j2 > Updated Branches: > refs/heads/master 93afa566c -> a5a95886b > > > [LOG4J2-1699] Log File Permissions with PosixFilePermission feedback > from jira. Closes #89. > - item 2: Better log at configuration step if file attribute view are > defined but underlying files system doesnt support it > - item 3: Exception catch and logged if OperationNotSupported or > Operation not permitted are thrown while changing file attribute > permissions, user or group > - item 4: No need to apply file posix attribute if file is just rolled > not compressed, both in DirectWriteRolloverStrategy and > DefaultRolloverStrategy. > - Changed next release version in documentation and javadoc. > > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo > Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/ > commit/a5a95886 > Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a5a95886 > Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a5a95886 > > Branch: refs/heads/master > Commit: a5a95886b6912b31009a7c61f18396280e083cd6 > Parents: 93afa56 > Author: Pierrick HYMBERT <[email protected]> > Authored: Tue Jun 27 11:12:27 2017 -0700 > Committer: Gary Gregory <[email protected]> > Committed: Tue Jun 27 11:12:27 2017 -0700 > > ---------------------------------------------------------------------- > .../mom/activemq/JmsAppenderConnectLaterIT.java | 108 +++++++++++++++++++ > .../log4j/core/appender/FileManager.java | 65 +++++++---- > .../rolling/DefaultRolloverStrategy.java | 10 +- > .../rolling/DirectWriteRolloverStrategy.java | 10 +- > .../appender/rolling/RollingFileManager.java | 6 +- > .../rolling/RollingRandomAccessFileManager.java | 4 +- > .../action/PosixViewAttributeAction.java | 6 +- > src/site/xdoc/manual/appenders.xml | 4 +- > 8 files changed, 167 insertions(+), 46 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core-its/src/test/java/org/apache/logging/ > log4j/core/appender/mom/activemq/JmsAppenderConnectLaterIT.java > ---------------------------------------------------------------------- > diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/ > core/appender/mom/activemq/JmsAppenderConnectLaterIT.java > b/log4j-core-its/src/test/java/org/apache/logging/log4j/ > core/appender/mom/activemq/JmsAppenderConnectLaterIT.java > new file mode 100644 > index 0000000..8f548d2 > --- /dev/null > +++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/ > core/appender/mom/activemq/JmsAppenderConnectLaterIT.java > @@ -0,0 +1,108 @@ > +/* > + * 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.core.appender.mom.activemq; > + > +import java.util.HashMap; > +import java.util.Map; > + > +import org.apache.activemq.broker.BrokerService; > +import org.apache.activemq.jndi.ActiveMQInitialContextFactory; > +import org.apache.logging.log4j.Level; > +import org.apache.logging.log4j.categories.Appenders; > +import org.apache.logging.log4j.core.Layout; > +import org.apache.logging.log4j.core.LogEvent; > +import org.apache.logging.log4j.core.appender.mom.JmsAppender; > +import org.apache.logging.log4j.core.impl.Log4jLogEvent; > +import org.apache.logging.log4j.core.layout.MessageLayout; > +import org.apache.logging.log4j.message.StringMapMessage; > +import org.apache.logging.log4j.test.AvailablePortFinder; > +import org.junit.Ignore; > +import org.junit.Test; > +import org.junit.experimental.categories.Category; > + > +/** > + * Tests that a JMS Appender can reconnect to a JMS broker after it has > been > + * recycled. > + * <p> > + * LOG4J2-1934 JMS Appender does not know how to recover from a broken > + * connection. See https://issues.apache.org/jira/browse/LOG4J2-1934 > + * </p> > + */ > +@Category(Appenders.Jms.class) > +public class JmsAppenderConnectLaterIT { > + > + private void appendEvent(final JmsAppender appender) { > + final Map<String, String> map = new HashMap<>(); > + final String messageText = "Hello, World!"; > + final String loggerName = this.getClass().getName(); > + map.put("messageText", messageText); > + map.put("threadName", Thread.currentThread().getName()); > + // @formatter:off > + final LogEvent event = Log4jLogEvent.newBuilder() > + .setLoggerName(loggerName) > + .setLoggerFqcn(loggerName) > + .setLevel(Level.INFO) > + .setMessage(new StringMapMessage(map)) > + .setTimeMillis(System.currentTimeMillis()) > + .build(); > + // @formatter:on > + appender.append(event); > + } > + > + @Test > + public void testConnectReConnect() throws Exception { > + // Start broker > + final int port = AvailablePortFinder.getNextAvailable(); > + final String brokerUrlString = "tcp://localhost:" + port; > + // Start appender > + // final JmsClientTestConfig jmsClientTestConfig = new > JmsClientTestConfig( > + // ActiveMQInitialContextFactory.class.getName(), > brokerUrlString, "admin", > + // "admin".toCharArray()); > + // jmsClientTestConfig.start(); > + // final JmsAppender appender = > + // jmsClientTestConfig.createAppender(MessageLayout. > createLayout()); > + > + // @formatter:off > + final JmsAppender appender = JmsAppender.newBuilder() > + .setName("JmsAppender") > + .setLayout(MessageLayout.createLayout()) > + .setIgnoreExceptions(true) > + .setFactoryBindingName("ConnectionFactory") > + .setProviderUrl(brokerUrlString) > + .setUserName("admin") > + .setPassword("admin".toCharArray()) > + .build(); > + // @formatter:on > + appender.start(); > + > + // Log message > + appendEvent(appender); > + // Start broker > + BrokerService brokerService = ActiveMqBrokerServiceHelper > + > .startBrokerService(JmsAppenderConnectLaterIT.class.getName(), > brokerUrlString, port); > + // Stop broker > + ActiveMqBrokerServiceHelper.stopBrokerService(brokerService); > + // Restart broker > + brokerService = ActiveMqBrokerServiceHelper.startBrokerService( > JmsAppenderConnectLaterIT.class.getName(), > + brokerUrlString, port); > + // Logging again should cause the appender to reconnect > + appendEvent(appender); > + // Stop broker > + ActiveMqBrokerServiceHelper.stopBrokerService(brokerService); > + } > + > +} > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core/src/main/java/org/apache/logging/log4j/ > core/appender/FileManager.java > ---------------------------------------------------------------------- > diff --git > a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java > b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/FileManager.java > index 2438e97..6f7a98a 100644 > --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/FileManager.java > +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/FileManager.java > @@ -58,7 +58,7 @@ public class FileManager extends OutputStreamManager { > private final Set<PosixFilePermission> filePermissions; > private final String fileOwner; > private final String fileGroup; > - private final boolean posixSupported; > + private final boolean attributeViewEnabled; > > /** > * @deprecated > @@ -87,7 +87,7 @@ public class FileManager extends OutputStreamManager { > this.filePermissions = null; > this.fileOwner = null; > this.fileGroup = null; > - this.posixSupported = false; > + this.attributeViewEnabled = false; > } > > /** > @@ -107,11 +107,11 @@ public class FileManager extends OutputStreamManager > { > this.filePermissions = null; > this.fileOwner = null; > this.fileGroup = null; > - this.posixSupported = false; > + this.attributeViewEnabled = false; > } > > /** > - * @since 2.8.3 > + * @since 2.9 > */ > protected FileManager(final LoggerContext loggerContext, final String > fileName, final OutputStream os, final boolean append, final boolean > locking, > final boolean createOnDemand, final String advertiseURI, > final Layout<? extends Serializable> layout, > @@ -125,13 +125,31 @@ public class FileManager extends OutputStreamManager > { > this.bufferSize = buffer.capacity(); > > final Set<String> views = FileSystems.getDefault(). > supportedFileAttributeViews(); > - this.filePermissions = filePermissions != null && > views.contains("posix") > - ? > PosixFilePermissions.fromString(filePermissions) > : null; > - this.fileOwner = views.contains("owner") ? fileOwner : null; > - this.fileGroup = views.contains("posix") ? fileGroup : null; > + if (views.contains("posix")) { > + this.filePermissions = filePermissions != null ? > PosixFilePermissions.fromString(filePermissions) : null; > + this.fileGroup = fileGroup; > + } else { > + this.filePermissions = null; > + this.fileGroup = null; > + if (filePermissions != null) { > + LOGGER.warn("Posix file attribute permissions defined but > it is not supported by this files system."); > + } > + if (fileGroup != null) { > + LOGGER.warn("Posix file attribute group defined but it is > not supported by this files system."); > + } > + } > + > + if (views.contains("owner")) { > + this.fileOwner = fileOwner; > + } else { > + this.fileOwner = null; > + if (fileOwner != null) { > + LOGGER.warn("Owner file attribute defined but it is not > supported by this files system."); > + } > + } > > // Supported and defined > - this.posixSupported = filePermissions != null || fileOwner != > null || fileGroup != null; > + this.attributeViewEnabled = this.filePermissions != null || > this.fileOwner != null || this.fileGroup != null; > } > > /** > @@ -168,20 +186,23 @@ public class FileManager extends OutputStreamManager > { > final String filename = getFileName(); > LOGGER.debug("Now writing to {} at {}", filename, new Date()); > final FileOutputStream fos = new FileOutputStream(filename, > isAppend); > - definePathAttributeView(Paths.get(filename)); > + defineAttributeView(Paths.get(filename)); > return fos; > } > > - protected void definePathAttributeView(final Path path) throws > IOException { > - if (posixSupported) { > - // FileOutputStream may not create new file on all jvm > - path.toFile().createNewFile(); > + protected void defineAttributeView(final Path path) { > + if (attributeViewEnabled) { > + try { > + // FileOutputStream may not create new file on all jvm > + path.toFile().createNewFile(); > > - FileUtils.defineFilePosixAttributeView(path, > filePermissions, fileOwner, fileGroup); > + FileUtils.defineFilePosixAttributeView(path, > filePermissions, fileOwner, fileGroup); > + } catch (final Exception e) { > + LOGGER.error("Could not define attribute view on path > \"{}\" got {}", path, e.getMessage(), e); > + } > } > } > > - > @Override > protected synchronized void write(final byte[] bytes, final int > offset, final int length, > final boolean immediateFlush) { > @@ -312,12 +333,12 @@ public class FileManager extends OutputStreamManager > { > } > > /** > - * If posix file attribute view supported and defined. > + * Returns true if file attribute view enabled for this file manager. > * > - * @return True if posix supported and defined false otherwise. > + * @return True if posix or owner supported and defined false > otherwise. > */ > - public boolean isPosixSupported() { > - return posixSupported; > + public boolean isAttributeViewEnabled() { > + return attributeViewEnabled; > } > > /** > @@ -402,8 +423,8 @@ public class FileManager extends OutputStreamManager { > FileManager fm = new FileManager(data.getLoggerContext(), > name, fos, data.append, data.locking, > data.createOnDemand, data.advertiseURI, > data.layout, > data.filePermissions, data.fileOwner, > data.fileGroup, writeHeader, byteBuffer); > - if (fos != null && fm.posixSupported) { > - fm.definePathAttributeView(file.toPath()); > + if (fos != null && fm.attributeViewEnabled) { > + fm.defineAttributeView(file.toPath()); > } > return fm; > } catch (final IOException ex) { > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core/src/main/java/org/apache/logging/log4j/ > core/appender/rolling/DefaultRolloverStrategy.java > ---------------------------------------------------------------------- > diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/DefaultRolloverStrategy.java b/log4j-core/src/main/java/ > org/apache/logging/log4j/core/appender/rolling/ > DefaultRolloverStrategy.java > index 865eeb4..972f348 100644 > --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/DefaultRolloverStrategy.java > +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/DefaultRolloverStrategy.java > @@ -569,8 +569,8 @@ public class DefaultRolloverStrategy extends > AbstractRolloverStrategy { > return new RolloverDescriptionImpl(currentFileName, false, > null, null); > } > > - if (manager.isPosixSupported()) { > - // Propagate posix attribute view to rolled/compressed file > + if (compressAction != null && manager.isAttributeViewEnabled()) { > + // Propagate posix attribute view to compressed file > // @formatter:off > Action posixAttributeViewAction = PosixViewAttributeAction. > newBuilder() > > .withBasePath(compressedName) > @@ -583,11 +583,7 @@ public class DefaultRolloverStrategy extends > AbstractRolloverStrategy { > > .withFileGroup(manager.getFileGroup()) > .build(); > // @formatter:on > - if (compressAction == null) { > - compressAction = posixAttributeViewAction; > - } else { > - compressAction = new > CompositeAction(Arrays.asList(compressAction, > posixAttributeViewAction), false); > - } > + compressAction = new > CompositeAction(Arrays.asList(compressAction, > posixAttributeViewAction), false); > } > > final FileRenameAction renameAction = new FileRenameAction(new > File(currentFileName), new File(renameTo), > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core/src/main/java/org/apache/logging/log4j/ > core/appender/rolling/DirectWriteRolloverStrategy.java > ---------------------------------------------------------------------- > diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/DirectWriteRolloverStrategy.java > b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/ > DirectWriteRolloverStrategy.java > index 06dd5d3..538a895 100644 > --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/DirectWriteRolloverStrategy.java > +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/DirectWriteRolloverStrategy.java > @@ -369,8 +369,8 @@ public class DirectWriteRolloverStrategy extends > AbstractRolloverStrategy implem > } > } > > - if (manager.isPosixSupported()) { > - // Propagate posix attribute view to rolled/compressed file > + if (compressAction != null && manager.isAttributeViewEnabled()) { > + // Propagate posix attribute view to compressed file > // @formatter:off > Action posixAttributeViewAction = PosixViewAttributeAction. > newBuilder() > > .withBasePath(compressedName) > @@ -383,11 +383,7 @@ public class DirectWriteRolloverStrategy extends > AbstractRolloverStrategy implem > > .withFileGroup(manager.getFileGroup()) > .build(); > // @formatter:on > - if (compressAction == null) { > - compressAction = posixAttributeViewAction; > - } else { > - compressAction = new > CompositeAction(Arrays.asList(compressAction, > posixAttributeViewAction), false); > - } > + compressAction = new > CompositeAction(Arrays.asList(compressAction, > posixAttributeViewAction), false); > } > > final Action asyncAction = merge(compressAction, customActions, > stopCustomActionsOnError); > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core/src/main/java/org/apache/logging/log4j/ > core/appender/rolling/RollingFileManager.java > ---------------------------------------------------------------------- > diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/ > org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java > index 90b19ef..546924c 100644 > --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/RollingFileManager.java > +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/RollingFileManager.java > @@ -119,7 +119,7 @@ public class RollingFileManager extends FileManager { > } > > /** > - * @since 2.8.3 > + * @since 2.9 > */ > protected RollingFileManager(final LoggerContext loggerContext, final > String fileName, final String pattern, final OutputStream os, > final boolean append, final boolean createOnDemand, final > long size, final long time, > @@ -631,8 +631,8 @@ public class RollingFileManager extends FileManager { > RollingFileManager rm = new > RollingFileManager(data.getLoggerContext(), > data.fileName, data.pattern, os, > data.append, data.createOnDemand, size, time, > data.policy, data.strategy, data.advertiseURI, > data.layout, data.filePermissions, data.fileOwner, > data.fileGroup, writeHeader, buffer); > - if (os != null && rm.isPosixSupported()) { > - rm.definePathAttributeView(file.toPath()); > + if (os != null && rm.isAttributeViewEnabled()) { > + rm.defineAttributeView(file.toPath()); > } > > return rm; > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core/src/main/java/org/apache/logging/log4j/ > core/appender/rolling/RollingRandomAccessFileManager.java > ---------------------------------------------------------------------- > diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/RollingRandomAccessFileManager.java > b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/ > RollingRandomAccessFileManager.java > index ccce93c..af53d97 100644 > --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/RollingRandomAccessFileManager.java > +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/RollingRandomAccessFileManager.java > @@ -207,8 +207,8 @@ public class RollingRandomAccessFileManager extends > RollingFileManager { > RollingRandomAccessFileManager rrm = new > RollingRandomAccessFileManager(data.getLoggerContext(), raf, name, > data.pattern, > NullOutputStream.getInstance(), data.append, > data.immediateFlush, data.bufferSize, size, time, data.policy, > data.strategy, data.advertiseURI, data.layout, > data.filePermissions, data.fileOwner, data.fileGroup, writeHeader); > - if (rrm.isPosixSupported()) { > - rrm.definePathAttributeView(file.toPath()); > + if (rrm.isAttributeViewEnabled()) { > + rrm.defineAttributeView(file.toPath()); > } > return rrm; > } catch (final IOException ex) { > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/log4j-core/src/main/java/org/apache/logging/log4j/ > core/appender/rolling/action/PosixViewAttributeAction.java > ---------------------------------------------------------------------- > diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/action/PosixViewAttributeAction.java > b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/action/PosixViewAttributeAction.java > index d74fcbd..431de3f 100644 > --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/action/PosixViewAttributeAction.java > +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/ > appender/rolling/action/PosixViewAttributeAction.java > @@ -122,13 +122,13 @@ public class PosixViewAttributeAction extends > AbstractPathAction { > > if (filePermissions == null && Strings.isEmpty( > filePermissionsString) > && Strings.isEmpty(fileOwner) && > Strings.isEmpty(fileGroup)) { > - LOGGER.error("Posix file attribute view not valid because > nor permissions, user and group defined."); > + LOGGER.error("Posix file attribute view not valid because > nor permissions, user or group defined."); > return null; > } > > if (!FileUtils.isFilePosixAttributeViewSupported()) { > - LOGGER.warn("Posix file attribute view defined but it is > not supported by this file system."); > -// return null; // FIXME Should we avoid operations not > permitted or unsupported exception ? > + LOGGER.warn("Posix file attribute view defined but it is > not supported by this files system."); > + return null; > } > > return new PosixViewAttributeAction(basePath, followLinks, > maxDepth, pathConditions, > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ > a5a95886/src/site/xdoc/manual/appenders.xml > ---------------------------------------------------------------------- > diff --git a/src/site/xdoc/manual/appenders.xml b/src/site/xdoc/manual/ > appenders.xml > index 339d35c..98956d7 100644 > --- a/src/site/xdoc/manual/appenders.xml > +++ b/src/site/xdoc/manual/appenders.xml > @@ -2535,7 +2535,7 @@ public class JpaLogEntity extends > AbstractLogEventWrapperEntity { > DefaultRolloverStrategy to run at rollover. Since 2.8 if no > file name is configured then > <a href="#DirectWriteRolloverStrategy"> > DirectWriteRolloverStrategy</a> will be used instead of > DefaultRolloverStrategy. > - Since log4j-2.8.3, a <a > href="#CustomPosixViewAttributeOnRollover">custom > POSIX file attribute view action</a> can be configured in the > + Since log4j-2.9, a <a > href="#CustomPosixViewAttributeOnRollover">custom > POSIX file attribute view action</a> can be configured in the > DefaultRolloverStrategy to run at rollover, if not defined, > inherited POSIX file attribute view from the RollingFileAppender will be > applied. > </p> > <p> > @@ -3520,7 +3520,7 @@ public class JpaLogEntity extends > AbstractLogEventWrapperEntity { > <a name="CustomPosixViewAttributeOnRollover"/> > <h5>Log Archive File Attribute View Policy: Custom file > attribute on Rollover</h5> > <p> > - Log4j-2.8.3 introduces a <tt>PosixViewAttribute</tt> action > that gives users more control > + Log4j-2.9 introduces a <tt>PosixViewAttribute</tt> action > that gives users more control > over which file attribute permissions, owner and group should > be applied. > The PosixViewAttribute action lets users configure one or > more conditions that select the eligible files > relative to a base directory. > > -- Matt Sicker <[email protected]>
