Class LoggingHandlerEnvironmentFacet

  • All Implemented Interfaces:
    EnvironmentFacet

    public class LoggingHandlerEnvironmentFacet
    extends AbstractLogAwareFacet
    EnvironmentFacet for replacing Handlers from Java Util Logging with a Maven Log. This is required as an environment facet for capturing log statements from tools that use the Java Util Logging system internally - such as the JDK SchemaGen tool.
    Since:
    2.1
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggingHandlerEnvironmentFacet​(java.lang.String logPrefix, org.apache.maven.plugin.logging.Log mavenLog, java.lang.String encoding, java.lang.String[] loggerNamePrefixes)
      Creates a new JavaLoggingEnvironment, using the supplied variables to set up a MavenLogHandler.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static LoggingHandlerEnvironmentFacet create​(org.apache.maven.plugin.logging.Log mavenLog, java.lang.Class<? extends AbstractJaxbMojo> caller, java.lang.String encoding)
      Factory method creating a new LoggingHandlerEnvironmentFacet wrapping the supplied properties.
      void restore()
      Restores the original root Logger state, including Level and Handlers.
      void setup()
      Sets up this Environment, inferring temporary changes to environment variables or conditions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_LOGGER_NAMES

        public static final java.lang.String[] DEFAULT_LOGGER_NAMES
        Standard logger names/categories for the java.util.Logger.
      • restored

        private boolean restored
      • rootLogger

        private java.util.logging.Logger rootLogger
      • originalRootLoggerLevel

        private java.util.logging.Level originalRootLoggerLevel
      • originalHandlers

        private java.util.List<java.util.logging.Handler> originalHandlers
      • logPrefix

        private java.lang.String logPrefix
      • encoding

        private java.lang.String encoding
      • loggerNamePrefixes

        private java.lang.String[] loggerNamePrefixes
    • Constructor Detail

      • LoggingHandlerEnvironmentFacet

        public LoggingHandlerEnvironmentFacet​(java.lang.String logPrefix,
                                              org.apache.maven.plugin.logging.Log mavenLog,
                                              java.lang.String encoding,
                                              java.lang.String[] loggerNamePrefixes)
        Creates a new JavaLoggingEnvironment, using the supplied variables to set up a MavenLogHandler. The MavenLogHandler is then assigned to the root logger.
        Parameters:
        logPrefix - The prefix to use for the logger, indicating which tool is used by the log. Example: "XJC" or "SchemaGen".
        mavenLog - The active Maven Log.
        encoding - The configured encoding.
        loggerNamePrefixes - The prefixes of the Logger names to be permitted logging.
    • Method Detail

      • setup

        public void setup()
        Sets up this Environment, inferring temporary changes to environment variables or conditions. The changes must be reversible, and should be restored to their original values in the restore() method.

        Redirects JUL logging statements to the Maven Log.

      • restore

        public void restore()
        Restores the original root Logger state, including Level and Handlers.
      • create

        public static LoggingHandlerEnvironmentFacet create​(org.apache.maven.plugin.logging.Log mavenLog,
                                                            java.lang.Class<? extends AbstractJaxbMojo> caller,
                                                            java.lang.String encoding)
        Factory method creating a new LoggingHandlerEnvironmentFacet wrapping the supplied properties.
        Parameters:
        mavenLog - The active Maven Log.
        caller - The AbstractJaxbMojo subclass which invoked this LoggingHandlerEnvironmentFacet factory method.
        encoding - The encoding used by the Maven Mojo subclass.
        Returns:
        A fully set up LoggingHandlerEnvironmentFacet