The file appender appends log messages to a file.

Version

1

Hierarchy (view full)

Constructors

  • Parameters

    • format: string = DefaultFormats.MESSAGE

      The log message format to use. All properties of a log message can be inserted to their placeholders, e.g. '%id%'.

    • timeFormat: string = DefaultFormats.TIME

      The time format to use for the %time% placeholder. The time format is inspired by https://msdn.microsoft.com/de-de/library/8kb3ddd4(v=vs.110).aspx, but some of the placeholders might not work.

    • Optional formatLookups: FormatLookup

      map containing lookups for the printing of formatted messages, see DefaultFormats

    • fileAppenderOptions: FileAppenderOptions = {}

      map containing the options specifically for the file appender. fileNamePattern defaults to ''; fileExtension defaults to '.log'; targetPath defaults to the current working directory; acceptExistingFile defaults to false; maxFileSize defaults to 1000000000; backupCompression defaults to BackupCompressionMode.GZIP; syntax defaults to FileAppenderSyntax.PLAIN; pretty defaults to false; dateRollover defaults to false; deferredStart defaults to false;

    Returns FileAppender

Properties

_active: boolean = false

The flag indicating the activation state.

_appending: boolean = false

Flag indicating that the log file currently is written.

_backingUp: boolean = false

Flag indicating that the log file currently is backed up.

_buffer: LogMessage[]

A buffer that will be filled with log messages until the Appender is writable.

_currentFileName: string = ""

Stores the currently used file name of the log file. This will be recalculated in case of date rollovers.

_currentTargetPath: string = ""

Stores the currently used target path.

_failed: boolean = false

Flag indicating, that writing to the log file failed.

_file: null | FileHandle = null

The file handle opened for appending the log entries.

_fileNamePatternContainsInstancePlaceholder: boolean = false

Flag indicating whether the file name pattern already contains a placeholder for the instance counter.

_fileWriteBuffer: null | Buffer = null

Used internally for buffering contents to be written to the file.

_filterRelation: FilterRelation

The relation, to which all the appenders results must adhere. See FilterRelation.

_filters: Filter[]

The filter that will be evaluated in order to determine whether a message shall be handled by this appender.

_instanceId: number = 0

The, by existing log files, determined instance id that will be issued if a placeholder is present in the file name pattern, or if existing files shall not be overridden, or if the log file is not writable. The value will be preserved in case of date or file size rollovers.

_instanceStartTime: Date = ...

Timestamp when starting the current process.

_nextDateRollover: null | Date = null

The point in time when the file name shall be re-evaluated and a date rollover is to be performed Currently, this property is set but ignored.

_size: number = 0

The current file size

_writable: boolean = false

The writable flag of the appender.

acceptExistingFile: boolean = false

Sets the Appender to append logs to an existing log file on startup if it already exists. See FileAppenderOptions#acceptExistingFile.

ageLookup: string[] = DefaultFormats.ENUMS.AGE
backupCompression: BackupCompressionMode = BackupCompressionMode.GZIP

The backup compression mode. See FileAppenderOptions#backupCompression.

dateRollover: boolean = false

Whether to re-determine the file name at 00:00h when the date changes. See FileAppenderOptions#dateRollover. Currently, this feature is not supported.

dayOfTheWeekLookup: string[] = DefaultFormats.ENUMS.DAY_OF_WEEK
deferredStart: boolean = false

Whether the appender shall immediately create its file handle on instanciation. If set to true, clients habe to activate it explicitly.

fileExtension: string = ".log"

The file extension that is being appended to the file name, should start with period (.). See FileAppenderOptions#fileExtension.

fileNamePattern: string = "yyyy-MM-dd_HH-mm_%INSTANCE%"

The name pattern of the log file. See FileAppenderOptions#fileNamePattern.

format: string

The log message format to use. All properties of a log message can be inserted to their placeholders, e.g. '%id%'.

maxFileSize: number = ...

The maximum log file size. If exceeded, a backup will be created. Defaults to 1GB See FileAppenderOptions#maxFileSize.

monthLookup: string[] = DefaultFormats.ENUMS.MONTH
noonLookup: string[] = DefaultFormats.ENUMS.NOON
pretty: boolean = false

Whether to print pretty XML and JSON. See FileAppenderOptions#pretty.

separatorLookup: string[] = DefaultFormats.ENUMS.SEPARATOR
severityLookup: string[] = DefaultFormats.ENUMS.SEVERITY

A simple lookup from where the strings for the severity levels can be fetched. see DefaultFormats.ENUMS.SEVERITY

syntax: FileAppenderSyntax = FileAppenderSyntax.PLAIN

The write syntax mode. See FileAppenderOptions#syntax.

targetPath: string = ...

The path to generate the log files to. See FileAppenderOptions#targetPath.

timeFormat: string

The time format to use for the %time% placeholder. The time format is inspired by https://msdn.microsoft.com/de-de/library/8kb3ddd4(v=vs.110).aspx, but some of the placeholders might not work.

Accessors

Methods

  • Backs the log file up using the specified compression method.

    Returns Promise<void>

  • creates a compressed file from a given file fith the file extension '.gz' appended to the file name.

    Parameters

    • fileName: string

    Returns Promise<void>

  • Appends the current content to the file. Checks the resulting file size and backs the file up, if needed. Repeats the flush, if new content to be logged has arrived in the mean time.

    Returns void

  • Parameters

    • path: string
    • Optional options: MakeDirectoryOptions

    Returns Promise<undefined | string>

  • Parameters

    • path: string
    • Optional options: ObjectEncodingOptions & {
          withFileTypes?: boolean;
      }

    Returns Promise<string[]>

  • Parameters

    • srcPath: string
    • targetPath: string

    Returns Promise<void>

  • Returns a dirent entry matching the specified file name from a collection of dirent entries

    Parameters

    • fileName: string
    • entries: Dirent[]

    Returns null | Dirent

  • Returns string

    the file name according to the file name pattern specified including the instance id, if required.

  • Initializes the appender by either cleaning the file or reading its current size.

    Returns Promise<void>

  • The input function of an Appender for any log message. This function calls the filter evaluation, and hands the message over to the _handleMessage method, if the appender is currently writable. If the appender is not writable, the message is stored to the internal buffer.

    Parameters

    • msg: LogMessage

      The message that shall be received and appended.

    Returns boolean

    True, if the message was handled, false otherwise.