Class FileLogger

  • All Implemented Interfaces:
    java.lang.AutoCloseable, ExecutionLogger

    public class FileLogger
    extends java.lang.Object
    implements ExecutionLogger, java.lang.AutoCloseable

    FileLogger class.

    • 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, FileLoggerMirrorHandler mirrorHandler)
      Creates a new logger that writes to the specified file and optionally mirrors messages.
    • 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 invoke FileLoggerMirrorHandler.consumeOutput(String) if is given.
      protected java.io.OutputStream createOutputStream​(java.nio.file.Path outputPath)
      Override this method to create a custom output 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, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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, if null all message will be discarded.
        Throws:
        java.io.IOException - If the output file could not be created.
      • FileLogger

        public FileLogger​(java.io.File outputFile,
                          FileLoggerMirrorHandler mirrorHandler)
                   throws java.io.IOException
        Creates a new logger that writes to the specified file and optionally mirrors messages.
        Parameters:
        outputFile - The path to the output file, if null all message will be discarded.
        mirrorHandler - The class which handle mirrored message, can be null.
        Throws:
        java.io.IOException - If the output file could not be created.
    • Method Detail

      • createOutputStream

        protected java.io.OutputStream createOutputStream​(java.nio.file.Path outputPath)
                                                   throws java.io.IOException

        Override this method to create a custom output stream.

        By default, stream is created with Files.newOutputStream(Path, OpenOption...), which truncate the existing file.

        Throws:
        java.io.IOException
      • 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.
      • close

        public void close()
        Closes the underlying file stream.
        Specified by:
        close in interface java.lang.AutoCloseable