Class LogWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable

    public class LogWriter
    extends Writer
    The LogWriter is a simple Writer which writes lines of data to a given SLF4J Logger. Data is gathered in an internal buffer until the flush() method is called or until a CR or LF character is encountered in the data to be written.
    • Constructor Detail

      • LogWriter

        public LogWriter​(org.slf4j.Logger logger)
        Creates a writer based on the given logger.
        Parameters:
        logger - the logger
    • Method Detail

      • write

        public void write​(int c)
        Writes the character to the internal buffer unless the character is a CR or LF in which case the buffer is written to the logger as an error message.
        Overrides:
        write in class Writer
      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
        Writes the indicated characters to the internal buffer, flushing the buffer on any occurrence of a CR of LF.
        Specified by:
        write in class Writer
      • flush

        public void flush()
        Writes any data conained in the buffer to the logger as an error message.
        Specified by:
        flush in interface Flushable
        Specified by:
        flush in class Writer