Class MavenLogHandler


  • public class MavenLogHandler
    extends java.util.logging.Handler
    Handler implementation which delegates its actual logging to an internal Maven log. This is required to capture logging statements from tools that use the Java Util Logging system internally - such as the JDK SchemaGen tool.
    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.maven.plugin.logging.Log log  
      private java.lang.String prefix  
    • Constructor Summary

      Constructors 
      Constructor Description
      MavenLogHandler​(org.apache.maven.plugin.logging.Log log, java.lang.String prefix, java.lang.String encoding, java.lang.String[] acceptedLogRecordPrefixes)
      Creates a new MavenLogHandler which adapts a Handler to emit log messages onto a Maven Log.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      void flush()
      static java.util.logging.Level getJavaUtilLoggingLevelFor​(org.apache.maven.plugin.logging.Log mavenLog)
      Retrieves the JUL Level matching the supplied Maven Log.
      static java.util.logging.Filter getLoggingFilter​(java.lang.String... requiredPrefixes)
      Retrieves a java.util.Logging filter used to ensure that only LogRecords whose logger names start with any of the required prefixes are logged.
      void publish​(java.util.logging.LogRecord logRecord)
      • Methods inherited from class java.util.logging.Handler

        getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
      • Methods inherited from class java.lang.Object

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

      • log

        private org.apache.maven.plugin.logging.Log log
      • prefix

        private java.lang.String prefix
    • Constructor Detail

      • MavenLogHandler

        public MavenLogHandler​(org.apache.maven.plugin.logging.Log log,
                               java.lang.String prefix,
                               java.lang.String encoding,
                               java.lang.String[] acceptedLogRecordPrefixes)
        Creates a new MavenLogHandler which adapts a Handler to emit log messages onto a Maven Log.
        Parameters:
        log - The Maven Log to emit log messages to.
        prefix - An optional prefix used to prefix any log message.
        encoding - The encoding which should be used.
        acceptedLogRecordPrefixes - A non-null list of prefixes holding LogRecord logger names for permitted/accepted LogRecords.
    • Method Detail

      • publish

        public void publish​(java.util.logging.LogRecord logRecord)
        Specified by:
        publish in class java.util.logging.Handler
      • flush

        public void flush()
        Specified by:
        flush in class java.util.logging.Handler
      • close

        public void close()
                   throws java.lang.SecurityException
        Specified by:
        close in class java.util.logging.Handler
        Throws:
        java.lang.SecurityException
      • getJavaUtilLoggingLevelFor

        public static java.util.logging.Level getJavaUtilLoggingLevelFor​(org.apache.maven.plugin.logging.Log mavenLog)
        Retrieves the JUL Level matching the supplied Maven Log.
        Parameters:
        mavenLog - A non-null Maven Log.
        Returns:
        The Corresponding JUL Level.
      • getLoggingFilter

        public static java.util.logging.Filter getLoggingFilter​(java.lang.String... requiredPrefixes)
        Retrieves a java.util.Logging filter used to ensure that only LogRecords whose logger names start with any of the required prefixes are logged.
        Parameters:
        requiredPrefixes - A non-null list of prefixes to be matched with the LogRecord logger names.
        Returns:
        A java.util.logging Filter that only permits logging LogRecords whose logger names start with any of the required prefixes.