Skip to content

Commit

Permalink
Update with master
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed May 3, 2019
2 parents ac844a3 + 7b156fb commit 41ac366
Show file tree
Hide file tree
Showing 187 changed files with 4,014 additions and 9,459 deletions.
198 changes: 198 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<!--
~ JBoss, Home of Professional Open Source.
~
~ Copyright 2014 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.
-->

<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>

<name>JBoss Log Manager (Core)</name>
<description>An implementation of java.util.logging.LogManager</description>

<artifactId>jboss-logmanager</artifactId>
<packaging>jar</packaging>

<parent>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager-parent</artifactId>
<version>3.0.0.Final-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.jboss.modules</groupId>
<artifactId>jboss-modules</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<!-- Optional and provided as this is only a compile-time dependency -->
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</dependency>

<!-- test dependencies -->

<!-- Used in a test formatter -->
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<scope>test</scope>
</dependency>
<!-- JSON implementation -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<doclint>none</doclint>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<argLine>-Djava.util.logging.manager=org.jboss.logmanager.LogManager</argLine>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemPropertyVariables>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
<!-- Adding OSGI metadata to the JAR without changing the packaging type. -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>3.5.0</version>
</dependency>
</dependencies>
<configuration>
<instructions>
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
<Export-Package>
${project.groupId}.*;version=${project.version};-split-package:=error
</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java9-tests</id>
<activation>
<jdk>[9,</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test-compile-java9</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<release>9</release>
<buildDirectory>${project.build.directory}</buildDirectory>
<compileSourceRoots>${project.basedir}/src/test/java9</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
46 changes: 46 additions & 0 deletions core/src/main/java/org/jboss/logmanager/ConfiguratorFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2018 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;

/**
* Used to create a {@link LogContextConfigurator}. The {@linkplain #priority() priority} is used to determine which
* factory should be used. The lowest priority factory is used. If two factories have the same priority the second
* factory will not be used. The order of loading the factories for determining priority is done via the
* {@link java.util.ServiceLoader#load(Class, ClassLoader)}.
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public interface ConfiguratorFactory {

/**
* Creates the {@link LogContextConfigurator}.
*
* @return the log context configurator
*/
LogContextConfigurator create();

/**
* The priority for the factory which is used to determine which factory should be used to create a
* {@link LogContextConfigurator}. The lowest priority factory will be used.
*
* @return the priority for this factory
*/
int priority();
}
53 changes: 53 additions & 0 deletions core/src/main/java/org/jboss/logmanager/ExtErrorManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.jboss.logmanager;

import java.util.logging.ErrorManager;

/**
* An extended error manager, which contains additional useful utilities for error managers.
*/
public abstract class ExtErrorManager extends ErrorManager {

/**
* Get the name corresponding to the given error code.
*
* @param code the error code
* @return the corresponding name (not {@code null})
*/
protected String nameForCode(int code) {
switch (code) {
case CLOSE_FAILURE: return "CLOSE_FAILURE";
case FLUSH_FAILURE: return "FLUSH_FAILURE";
case FORMAT_FAILURE: return "FORMAT_FAILURE";
case GENERIC_FAILURE: return "GENERIC_FAILURE";
case OPEN_FAILURE: return "OPEN_FAILURE";
case WRITE_FAILURE: return "WRITE_FAILURE";
default: return "INVALID (" + code + ")";
}
}

public void error(final String msg, final Exception ex, final int code) {
super.error(msg, ex, code);
}

/**
* Convert the given error to a log record which can be published to handler(s) or stored. Care should
* be taken not to publish the log record to a logger that writes to the same handler that produced the error.
*
* @param msg the error message (possibly {@code null})
* @param ex the error exception (possibly {@code null})
* @param code the error code
* @return the log record (not {@code null})
*/
protected ExtLogRecord errorToLogRecord(String msg, Exception ex, int code) {
final ExtLogRecord record = new ExtLogRecord(Level.ERROR, "Failed to publish log record (%s[%d]): %s", ExtLogRecord.FormatStyle.PRINTF, getClass().getName());
final String codeStr = nameForCode(code);
record.setParameters(new Object[] {
codeStr,
Integer.valueOf(code),
msg,
});
record.setThrown(ex);
record.setLoggerName("");
return record;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,34 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

/**
* A formatter which handles {@link org.jboss.logmanager.ExtLogRecord ExtLogRecord} instances.
*/
public abstract class ExtFormatter extends Formatter {
/**
* Construct a new instance.
*/
public ExtFormatter() {
}

/**
* Wrap an existing formatter with an {@link ExtFormatter}, optionally replacing message formatting with
* the default extended message formatting capability.
*
* @param formatter the formatter to wrap (must not be {@code null})
* @param formatMessages {@code true} to replace message formatting, {@code false} to let the original formatter do it
* @return the extended formatter (not {@code null})
*/
public static ExtFormatter wrap(Formatter formatter, boolean formatMessages) {
if (formatter instanceof ExtFormatter && ! formatMessages) {
return (ExtFormatter) formatter;
} else {
return new WrappedFormatter(formatter, formatMessages);
}
}

/** {@inheritDoc} */
public final String format(final LogRecord record) {
Expand Down Expand Up @@ -120,4 +142,34 @@ protected String formatMessageLegacy(LogRecord record) {
protected String formatMessagePrintf(LogRecord record) {
return String.format(record.getMessage(), record.getParameters());
}

static class WrappedFormatter extends ExtFormatter {
private final Formatter formatter;
private final boolean formatMessages;

WrappedFormatter(Formatter formatter, boolean formatMessages) {
this.formatter = formatter;
this.formatMessages = formatMessages;
}

@Override
public String format(ExtLogRecord record) {
return formatter.format(record);
}

@Override
public String formatMessage(LogRecord record) {
return formatMessages ? super.formatMessage(record) : formatter.formatMessage(record);
}

@Override
public String getHead(Handler h) {
return formatter.getHead(h);
}

@Override
public String getTail(Handler h) {
return formatter.getTail(h);
}
}
}
Loading

0 comments on commit 41ac366

Please sign in to comment.