Class FileLogger

  • All Implemented Interfaces:
    ExecutionLogger

    public class FileLogger
    extends java.lang.Object
    implements ExecutionLogger
    Version:
    $Id: FileLogger.java 1389141 2012-09-23 20:29:01Z hboutemy $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.File file
      The path to the log file.
      private org.apache.maven.plugin.logging.Log log
      The optional mojo logger to additionally write messages to, can be null.
      private boolean shouldFinalize
      A flag whether the output stream should be closed during finalization of this logger.
      private java.io.PrintStream stream
      The underlying file stream this logger writes to.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileLogger​(java.io.File outputFile)
      Creates a new logger that writes to the specified file.
      FileLogger​(java.io.File outputFile, org.apache.maven.plugin.logging.Log log)
      Creates a new logger that writes to the specified file and optionally mirrors messages to the given mojo logger.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying file stream.
      void consumeLine​(java.lang.String line)
      Writes the specified line to the log file and optionally to the mojo logger.
      protected void finalize()
      Closes the underlying file stream.
      java.io.File getOutputFile()
      Gets the path to the output file.
      java.io.PrintStream getPrintStream()
      Gets the underlying stream used to write message to the log file.
      • Methods inherited from class java.lang.Object

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

      • file

        private java.io.File file
        The path to the log file.
      • stream

        private java.io.PrintStream stream
        The underlying file stream this logger writes to.
      • shouldFinalize

        private boolean shouldFinalize
        A flag whether the output stream should be closed during finalization of this logger.
      • log

        private final org.apache.maven.plugin.logging.Log log
        The optional mojo logger to additionally write messages to, can be null.
    • Constructor Detail

      • FileLogger

        public FileLogger​(java.io.File outputFile)
                   throws java.io.IOException
        Creates a new logger that writes to the specified file.
        Parameters:
        outputFile - The path to the output file, must not be null.
        Throws:
        java.io.IOException - If the output file could not be created.
      • FileLogger

        public FileLogger​(java.io.File outputFile,
                          org.apache.maven.plugin.logging.Log log)
                   throws java.io.IOException
        Creates a new logger that writes to the specified file and optionally mirrors messages to the given mojo logger.
        Parameters:
        outputFile - The path to the output file, must not be null.
        log - The mojo logger to additionally output messages to, may be null if not used.
        Throws:
        java.io.IOException - If the output file could not be created.
    • Method Detail

      • getOutputFile

        public java.io.File getOutputFile()
        Gets the path to the output file.
        Returns:
        The path to the output file, never null.
      • getPrintStream

        public java.io.PrintStream getPrintStream()
        Gets the underlying stream used to write message to the log file.
        Specified by:
        getPrintStream in interface ExecutionLogger
        Returns:
        The underlying stream used to write message to the log file, never null.
      • consumeLine

        public void consumeLine​(java.lang.String line)
        Writes the specified line to the log file and optionally to the mojo logger.
        Specified by:
        consumeLine in interface ExecutionLogger
        Parameters:
        line - The message to log.
      • close

        public void close()
        Closes the underlying file stream.
      • finalize

        protected void finalize()
        Closes the underlying file stream.
        Overrides:
        finalize in class java.lang.Object