EventLogFile

Description

The EventLogFile object is a EventOutput and writes events to a IoDevice for example a File. Each event is printed in a new line prefixed with the current date and time and the event’s severity. The log() method can be used to print messages to the IoDevice directly.

› Inherits:EventOutput

Properties

dateTime

This property holds a DateTime object whose DateTime.highPrecisionString property is used to format the date for log messages. It can be used to customize the date formatting.

› Type:DateTime
› Signal:dateTimeChanged()
› Attributes:Writable

error

This property holds the most recently occurred error or EventLogFile.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.

› Type:Error
› Signal:errorChanged()
› Attributes:Readonly

errorString

This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.

› Type:String
› Signal:errorStringChanged()
› Attributes:Readonly

output

This property holds the output device (e.g. File) to which the log messages are written.

› Type:IoDevice
› Signal:outputChanged()
› Attributes:Writable

outputMode

This property holds the output mode which specifies how to open the output at start, i.e. append messages or start from scratch everytime.

› Type:OutputMode
› Default:EventLogFile.OutputAppend
› Signal:outputModeChanged()
› Attributes:Writable

Methods

log(args)

This method prints a new line to the IoDevice. Each line consists of a date time and the given arguments separated by space.

Signals

errorOccurred()

This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.

Enumerations

Error

This enumeration describes all errors which can occur in EventLogFile objects. The most recently occurred error is stored in the error property.

Name Value Description
EventLogFile.NoError 0 No error occurred or was detected.
EventLogFile.OutputNotSetError 1 Output not set.
EventLogFile.OutputOpenError 2 Could not open output.

OutputMode

This enumeration describes the output mode of the EventLogFile.

Name Value Description
EventLogFile.OutputAppend 0 Append lines at the end of output. The file is never deleted or truncated with this mode.
EventLogFile.OutputTruncate 1 Truncate the file each time it is opened, i.e. every application start or whenever opened and closed manually.

Example

import InCore.Foundation 2.5

Application {

    EventLogFile {
        id: logFile
        // log to file stored on persistent local storage
        output: File {
            storage: LocalStorage { }
            fileName: "myapp.log"
        }
    }

    onCompleted: logFile.log("App started with random value", Math.random())
}