de.esprit.common.log

## Class LogPrinterFile

- java.lang.Object
- - de.esprit.common.log.AbstractLogPrinter
  - - de.esprit.common.log.LogPrinterFile

- All Implemented Interfaces:
    LogLevelEvent.Source, LogPrinter, java.io.Closeable, java.lang.AutoCloseable

      public class LogPrinterFile
      extends AbstractLogPrinter

  This class prints tracing output to a file. The logging directory must be provided in the constructor, the filename is automatically constructed according to this scheme: <logDir>/<channelName>_<timestamp>.log

  Note that you may use `setFileSizeLimit(int)` set a limit for the number of lines that go into one logfile. If this number is exceeded a new file will be created automatically - and a ChangeEvent is fired in order to notify interested listeners.

  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LogPrinterFile(LogChannel channel, java.io.File logDir)` Opens a new LogPrinterFile which receives messages from the given LogChannel and logs them into a logfile wich is created under the given log-directory.
    `LogPrinterFile(LogChannel channel, java.io.File logDir, java.io.File lastLogFile)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addFileChangeListener(LogFileChangeEvent.Listener l)`
    `void` | `close()` Closes the file-stream and deregisters from the underlying `LogChannel`.
    `protected java.io.File` | `createFile(java.io.File logDir)` Creates the filename for the log file.
    `java.io.File` | `getFile()` Returns the file currently being written into.
    `int` | `getFileCount()` Returns the number of files opened since started.
    `int` | `getLineCount()` Returns the number of lines already written to the current logfile.
    `TextConsole` | `getOutput(LogLevel currLevel)` Overriden to lead the output to the filestream.
    `java.lang.String` | `getTypeString()` Returns a unique string that identifies this LogPrinter.
    `void` | `openNextFile()` Quits the current logfile and opens the next one
    `void` | `removeFileChangeListener(LogFileChangeEvent.Listener l)`
    `void` | `setFileSizeLimit(int numLines)` Sets the logging limit for the log-files to the given number of lines, 0 = unlimited.

    - ### Methods inherited from class de.esprit.common.log.AbstractLogPrinter

      `addLogLevelListener, createLogMessageFormatter, fireLogLevelChange, getLogChannel, getLogFormatter, getLogLevel, getLogMessageListener, isSilent, processLogMessage, removeLogLevelListener, setLogFormatter, setLogLevel, setSilent, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### LogPrinterFile

          public LogPrinterFile(LogChannel channel,
                        java.io.File logDir)
                         throws java.lang.Exception

      Opens a new LogPrinterFile which receives messages from the given LogChannel and logs them into a logfile wich is created under the given log-directory. If logDir is null a hardcoded default applies.
      Throws:
        `java.lang.Exception`

    - #### LogPrinterFile

          public LogPrinterFile(LogChannel channel,
                        java.io.File logDir,
                        java.io.File lastLogFile)
                         throws java.lang.Exception

      Throws:
        `java.lang.Exception`

  - ### Method Detail

    - #### getFile

          public java.io.File getFile()

      Returns the file currently being written into.

    - #### getFileCount

          public int getFileCount()

      Returns the number of files opened since started.

    - #### getLineCount

          public int getLineCount()

      Returns the number of lines already written to the current logfile.

    - #### close

          public void close()

      Closes the file-stream and deregisters from the underlying `LogChannel`.
      Specified by:
        `close` in interface `LogPrinter`
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `AbstractLogPrinter`

    - #### setFileSizeLimit

          public void setFileSizeLimit(int numLines)

      Sets the logging limit for the log-files to the given number of lines, 0 = unlimited. If this limit is exceeded a new logfile is automatically created - and a ChangeEvent is fired in order to notify listeners.

    - #### createFile

          protected java.io.File createFile(java.io.File logDir)

      Creates the filename for the log file.

    - #### getOutput

          public TextConsole getOutput(LogLevel currLevel)

      Overriden to lead the output to the filestream.

    - #### openNextFile

          public void openNextFile()

      Quits the current logfile and opens the next one

    - #### getTypeString

          public java.lang.String getTypeString()

      Returns a unique string that identifies this LogPrinter. This string is supposed to be used as a key for an `EnvStore`.

    - #### addFileChangeListener

          public void addFileChangeListener(LogFileChangeEvent.Listener l)

    - #### removeFileChangeListener

          public void removeFileChangeListener(LogFileChangeEvent.Listener l)

Copyright © 2012 EsprIT-Systems. All Rights Reserved.