Skip to content

Commits on Source 3

jboss-logmanager (2.1.14-1) unstable; urgency=medium
* New upstream version 2.1.14.
-- Markus Koschany <apo@debian.org> Mon, 12 Aug 2019 00:38:40 +0200
jboss-logmanager (2.1.13-1) unstable; urgency=medium
* New upstream version 2.1.13.
......
......@@ -28,7 +28,7 @@
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<packaging>jar</packaging>
<version>2.1.13.Final</version>
<version>2.1.14.Final</version>
<parent>
<groupId>org.jboss</groupId>
......
......@@ -118,7 +118,8 @@ public final class CallerClassLoaderLogContextSelector implements LogContextSele
*/
@Override
public LogContext getLogContext() {
return AccessController.doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
AccessController.doPrivileged(logContextAction);
}
/**
......
......@@ -118,7 +118,8 @@ public final class ClassLoaderLogContextSelector implements LogContextSelector {
* with any log context.
*/
public LogContext getLogContext() {
return AccessController.doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
AccessController.doPrivileged(logContextAction);
}
/**
......
......@@ -69,7 +69,8 @@ public final class ContextClassLoaderLogContextSelector implements LogContextSel
};
public LogContext getLogContext() {
return doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
doPrivileged(logContextAction);
}
/**
......
......@@ -664,14 +664,13 @@ final class LogContextConfigurationImpl implements LogContextConfiguration {
expect(")", iterator);
return new SimpleObjectProducer(new SubstituteFilter(pattern, replacement, true));
} else {
final String name = expectName(iterator);
if (! filters.containsKey(name) || immediate && ! filterRefs.containsKey(name)) {
throw new IllegalArgumentException(String.format("No filter named \"%s\" is defined", name));
if (! filters.containsKey(token) || immediate && ! filterRefs.containsKey(token)) {
throw new IllegalArgumentException(String.format("No filter named \"%s\" is defined", token));
}
if (immediate) {
return new SimpleObjectProducer(filterRefs.get(name));
return new SimpleObjectProducer(filterRefs.get(token));
} else {
return new RefProducer(name, filterRefs);
return new RefProducer(token, filterRefs);
}
}
}
......
......@@ -765,8 +765,20 @@ public final class Formatters {
public static FormatStep exceptionFormatStep(final boolean leftJustify, final int minimumWidth, final boolean truncateBeginning, final int maximumWidth, final String argument, final boolean extended) {
return new JustifyingFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth) {
public void renderRaw(final StringBuilder builder, final ExtLogRecord record) {
if (System.getSecurityManager() != null)
doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
doExceptionFormatStep(builder, record, argument, extended);
return null;
}
});
else
doExceptionFormatStep(builder, record, argument, extended);
}
};
}
private static void doExceptionFormatStep(final StringBuilder builder, final ExtLogRecord record, final String argument, final boolean extended) {
final Throwable t = record.getThrown();
if (t != null) {
int depth = -1;
......@@ -778,11 +790,6 @@ public final class Formatters {
}
StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
}
return null;
}
});
}
};
}
/**
......
......@@ -154,6 +154,8 @@ public class PeriodicSizeRotatingFileHandler extends PeriodicRotatingFileHandler
final String suffix = getNextSuffix();
final SuffixRotator suffixRotator = getSuffixRotator();
if (suffixRotator != SuffixRotator.EMPTY && suffix != null) {
// Make sure any previous files are closed before we attempt to rotate
setFileInternal(null);
suffixRotator.rotate(getErrorManager(), file.toPath(), suffix, maxBackupIndex);
}
}
......
......@@ -139,6 +139,8 @@ public class SizeRotatingFileHandler extends FileHandler {
synchronized (outputLock) {
// Check for a rotate
if (rotateOnBoot && maxBackupIndex > 0 && file != null && file.exists() && file.length() > 0L) {
// Make sure any previous files are closed before we attempt to rotate
setFileInternal(null);
suffixRotator.rotate(getErrorManager(), file.toPath(), maxBackupIndex);
}
setFileInternal(file);
......
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2019 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed 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.jboss.logmanager;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.ErrorManager;
import org.junit.Assert;
/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class AssertingErrorManager extends ErrorManager {
private final int[] allowedCodes;
private AssertingErrorManager() {
this.allowedCodes = null;
}
private AssertingErrorManager(final int... allowedCodes) {
this.allowedCodes = allowedCodes;
}
public static AssertingErrorManager of() {
return new AssertingErrorManager();
}
public static AssertingErrorManager of(final int... allowedCodes) {
return new AssertingErrorManager(allowedCodes);
}
@Override
public void error(final String msg, final Exception ex, final int code) {
if (notAllowed(code)) {
final String codeStr;
switch (code) {
case CLOSE_FAILURE:
codeStr = "CLOSE_FAILURE";
break;
case FLUSH_FAILURE:
codeStr = "FLUSH_FAILURE";
break;
case FORMAT_FAILURE:
codeStr = "FORMAT_FAILURE";
break;
case GENERIC_FAILURE:
codeStr = "GENERIC_FAILURE";
break;
case OPEN_FAILURE:
codeStr = "OPEN_FAILURE";
break;
case WRITE_FAILURE:
codeStr = "WRITE_FAILURE";
break;
default:
codeStr = "INVALID (" + code + ")";
break;
}
try (
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)
) {
pw.printf("LogManager error of type %s: %s%n", codeStr, msg);
ex.printStackTrace(pw);
Assert.fail(sw.toString());
} catch (IOException e) {
// This shouldn't happen, but just fail if it does
e.printStackTrace();
Assert.fail(String.format("Failed to print error message: %s", e.getMessage()));
}
}
}
private boolean notAllowed(final int code) {
if (allowedCodes != null) {
for (int allowedCode : allowedCodes) {
if (code == allowedCode) {
return false;
}
}
}
return true;
}
}
......@@ -38,6 +38,7 @@ public class FileHandlerPerformanceTests {
handler.setLevel(Level.ALL);
handler.setAutoFlush(true);
handler.setEncoding("utf-8");
handler.setErrorManager(AssertingErrorManager.of());
}
private static void publish(final ExtHandler handler, final String msg) {
......
......@@ -172,6 +172,7 @@ public final class HandlerTests {
static class MultiHandler extends ExtHandler {
protected MultiHandler() {
setErrorManager(AssertingErrorManager.of());
}
public void publish(final LogRecord record) {
......
......@@ -36,10 +36,12 @@ public class TestFileHandler extends FileHandler {
public TestFileHandler() {
super();
setErrorManager(AssertingErrorManager.of());
}
public TestFileHandler(final String fileName, final boolean append) throws FileNotFoundException {
super(fileName, append);
setErrorManager(AssertingErrorManager.of());
}
@Override
......
......@@ -22,6 +22,7 @@ package org.jboss.logmanager.config;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
......@@ -74,6 +75,51 @@ public class LogContextConfigurationTests {
}
}
@Test
public void testNamedFilter() {
final LogContext context = LogContext.create();
final LogContextConfiguration configuration = LogContextConfiguration.Factory.create(context);
final LoggerConfiguration loggerConfiguration = configuration.addLoggerConfiguration(LOGGER_NAME);
final Logger logger = context.getLogger(LOGGER_NAME);
final FilterDescription description = new FilterDescription("test", "test named filter",
"test named filter | filtered", true);
configuration.addFilterConfiguration(null, TestFilter.class.getName(), "test");
loggerConfiguration.setFilter(description.filterExpression);
configuration.commit();
final ExtLogRecord record = create(description.logMessage);
final Filter filter = logger.getFilter();
Assert.assertNotNull("Expected a filter on the logger, but one was not found: " + description, filter);
Assert.assertEquals("Filter.isLoggable() test failed: " + description, description.isLoggable, filter.isLoggable(record));
final String msg = record.getFormattedMessage();
Assert.assertEquals(String.format("Expected %s found %s: %n%s", description.expectedMessage, msg, description), description.expectedMessage, msg);
}
@Test
public void testEmbeddedNamedFilter() {
final LogContext context = LogContext.create();
final LogContextConfiguration configuration = LogContextConfiguration.Factory.create(context);
final LoggerConfiguration loggerConfiguration = configuration.addLoggerConfiguration(LOGGER_NAME);
final Logger logger = context.getLogger(LOGGER_NAME);
final FilterDescription description = new FilterDescription("all(test)", "test named filter",
"test named filter | filtered", true);
configuration.addFilterConfiguration(null, TestFilter.class.getName(), "test");
loggerConfiguration.setFilter(description.filterExpression);
configuration.commit();
final ExtLogRecord record = create(description.logMessage);
final Filter filter = logger.getFilter();
Assert.assertNotNull("Expected a filter on the logger, but one was not found: " + description, filter);
Assert.assertEquals("Filter.isLoggable() test failed: " + description, description.isLoggable, filter.isLoggable(record));
final String msg = record.getFormattedMessage();
Assert.assertEquals(String.format("Expected %s found %s: %n%s", description.expectedMessage, msg, description), description.expectedMessage, msg);
}
private static ExtLogRecord create(final String message) {
final ExtLogRecord record = new ExtLogRecord(Level.INFO, message, Logger.class.getName());
record.setLoggerName(LOGGER_NAME);
......@@ -105,4 +151,13 @@ public class LogContextConfigurationTests {
", isLoggable=" + isLoggable + ")";
}
}
public static class TestFilter implements Filter {
@Override
public boolean isLoggable(final LogRecord record) {
record.setMessage(record.getMessage() + " | filtered");
return true;
}
}
}
......@@ -37,6 +37,7 @@ import java.util.zip.GZIPInputStream;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.junit.After;
import org.junit.Assert;
......@@ -105,6 +106,7 @@ public class AbstractHandlerTest {
protected static void configureHandlerDefaults(final ExtHandler handler) {
handler.setAutoFlush(true);
handler.setFormatter(FORMATTER);
handler.setErrorManager(AssertingErrorManager.of());
}
protected ExtLogRecord createLogRecord(final String msg) {
......
......@@ -23,6 +23,7 @@ import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
......@@ -108,6 +109,7 @@ public class AsyncHandlerTests {
BlockingQueueHandler() {
queue = new LinkedBlockingDeque<String>();
setErrorManager(AssertingErrorManager.of());
}
@Override
......
......@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.LogContext;
......@@ -101,6 +102,7 @@ public class DelayedHandlerTests {
final LogContext logContext = LogContext.create();
final DelayedHandler handler = new DelayedHandler();
handler.setErrorManager(AssertingErrorManager.of());
final Logger rootLogger = logContext.getLogger("");
rootLogger.addHandler(handler);
......@@ -141,6 +143,7 @@ public class DelayedHandlerTests {
final LogContext logContext = LogContext.create();
final DelayedHandler handler = new DelayedHandler();
handler.setErrorManager(AssertingErrorManager.of());
final Logger rootLogger = logContext.getLogger("");
rootLogger.addHandler(handler);
final Random r = new Random();
......@@ -186,6 +189,7 @@ public class DelayedHandlerTests {
final LogContext logContext = LogContext.create();
final DelayedHandler handler = new DelayedHandler();
handler.setErrorManager(AssertingErrorManager.of());
final Logger rootLogger = logContext.getLogger("");
rootLogger.addHandler(handler);
final Random r = new Random();
......@@ -241,6 +245,11 @@ public class DelayedHandlerTests {
public static class TestHandler extends ExtHandler {
static final List<ExtLogRecord> MESSAGES = new ArrayList<>();
@SuppressWarnings("WeakerAccess")
public TestHandler() {
setErrorManager(AssertingErrorManager.of());
}
@Override
protected synchronized void doPublish(final ExtLogRecord record) {
MESSAGES.add(record);
......
......@@ -21,6 +21,7 @@ package org.jboss.logmanager.handlers;
import java.util.logging.SimpleFormatter;
import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtHandler;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.junit.Assert;
......@@ -140,6 +141,10 @@ public class ExtHandlerTests {
static class CloseHandler extends ExtHandler {
private boolean closed = false;
CloseHandler() {
setErrorManager(AssertingErrorManager.of());
}
@Override
public void close() {
closed = true;
......
......@@ -18,22 +18,23 @@
*/
package org.jboss.logmanager.handlers;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.io.StringWriter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import static org.hamcrest.core.Is.is;
import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
import org.jboss.logmanager.handlers.ConsoleHandler.Target;
import org.junit.After;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
/**
*
* @author <a href="mailto:ehugonne@redhat.com">Emmanuel Hugonnet</a> (c) 2013 Red Hat, inc.
*/
public class OutputStreamHandlerTest {
......@@ -65,6 +66,7 @@ public class OutputStreamHandlerTest {
@Test
public void testSetEncoding() throws Exception {
handler = new OutputStreamHandler();
handler.setErrorManager(AssertingErrorManager.of());
handler.setEncoding("UTF-8");
assertThat(handler.getEncoding(), is("UTF-8"));
}
......@@ -72,6 +74,7 @@ public class OutputStreamHandlerTest {
@Test
public void testSetEncodingOnOutputStream() throws Exception {
handler = new ConsoleHandler(Target.CONSOLE, NO_FORMATTER);
handler.setErrorManager(AssertingErrorManager.of());
handler.setWriter(out);
handler.setEncoding("UTF-8");
assertThat(handler.getEncoding(), is("UTF-8"));
......@@ -82,6 +85,7 @@ public class OutputStreamHandlerTest {
@Test
public void testSetNullEncodingOnOutputStream() throws Exception {
handler = new OutputStreamHandler(NO_FORMATTER);
handler.setErrorManager(AssertingErrorManager.of());
handler.setWriter(out);
handler.setEncoding(null);
handler.publish(new ExtLogRecord(Level.INFO, "Hello World", getClass().getName()));
......
......@@ -29,9 +29,11 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.List;
import java.util.logging.ErrorManager;
import org.jboss.byteman.contrib.bmunit.BMRule;
import org.jboss.byteman.contrib.bmunit.BMUnitRunner;
import org.jboss.logmanager.AssertingErrorManager;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.Level;
import org.junit.After;
......@@ -59,6 +61,7 @@ public class PeriodicRotatingFileHandlerTests extends AbstractHandlerTest {
handler.setFormatter(FORMATTER);
// Set append to true to ensure the rotated file is overwritten
handler.setAppend(true);
handler.setErrorManager(AssertingErrorManager.of());
}
@After
......@@ -112,6 +115,7 @@ public class PeriodicRotatingFileHandlerTests extends AbstractHandlerTest {
final int nextDay = currentDay + 1;
// Set to false for this specific test
handler.setAppend(false);
handler.setErrorManager(AssertingErrorManager.of(ErrorManager.GENERIC_FAILURE));
final String currentDate = sdf.format(cal.getTime());
......