Logging QML Type

Handles aspects of console system logging. More...

Import Statement: import ArcGIS.AppFramework 1.0

Properties

Methods

Detailed Description

The Logging component provides means to configure and create console logs, for diagnostic and error-checking purposes.

This component can return a number of properties provided by the app, which can be recorded into the console log in the format defined by the messagePattern property. This pattern should be structured using these placeholders for the described relevant properties:

%{appname}: The app's name
%{category}: Logging category
%{file}: Path to source file
%{function}: Function
%{line}: Line in source file
%{message}: The actual message
%{pid}: The application's process ID
%{threadid}: The system-wide ID of current thread (if it can be obtained)
%{qthreadptr}: A pointer to the current thread
%{type}: "debug", "warning", "critical" or "fatal"
%{time process}: time of the message, in seconds since the process started
%{time boot}: The time of the message, in seconds since the system boot if that can be determined. If the time since boot could not be obtained, the output is indeterminate.
%{time [format]}: System time when the message occurred. If the format is not specified, the ISO 8601 format is used.

This sample provides a simple console logging interface, including buttons to enable or disable logging and to open the created log file, and a text field to define the message pattern. When logging is enabled, every process going on within your app will be reported in the console log.

Item {
        ColumnLayout {

                Text {
                        text: "Message Pattern"
                }

                TextField {
                        id:outputTextField
                }

                TextField {
                        Layout.fillWidth: true

                        text: "%{if-category}%{category}: %{endif}%{message}"

                        onEditingFinished: {
                                AppFramework.logging.messagePattern = text;
                        }
                }

                RowLayout {
                        Layout.fillWidth: true

                        Button {
                                text: AppFramework.logging.enabled ? "Disable Logging" : "Enable Logging"
                                onClicked: {
                                        forceActiveFocus();
                                        AppFramework.logging.enabled = !AppFramework.logging.enabled;
                                }
                        }

                        Button {
                                text: "Open Output"
                                enabled: urlInfo.isLocalFile

                                onClicked: {
                                        Qt.openUrlExternally(AppFramework.logging.outputLocation);
                                }

                                UrlInfo {
                                        id: urlInfo

                                        url: AppFramework.logging.outputLocation
                                }
                        }
                }

                TextField {
                        id: logMessage

                        Layout.fillWidth: true

                        text: "Log message"
                        placeholderText: "Message to include in log output";
                }
        }

        Timer {
                id: logTimer

                repeat: true
                interval: 1000
                triggeredOnStart: true

                onTriggered: {
                        console.log("logTimer");
                        logRandom();
                }
        }

        FileDialog {
                id: fileDialog

                title: "Log Output File"
                nameFilters: [ "Log files (*.log)", "All files (*)" ]
                folder: AppFramework.resolvedPathUrl("~/ArcGIS/AppStudio/Logs")

                onAccepted: {
                        AppFramework.logging.outputLocation = fileUrl;
                }
        }

        Connections {
                target: AppFramework.logging

                onOutputLocationChanged: {
                        outputTextField.text = Qt.binding(function () {
                                return AppFramework.logging.outputLocation;
                        });
                }
        }
}

You can also record specific messages within your console log when certain lines of code are executed. This code sample prints a line in the console log when the user has finished editing a text field that writes a new filepath to the FileFolder component.

TextField {
    Layout.fillWidth: true

        text: fileFolder.path

    onEditingFinished: {
        fileFolder.path = text.trim();
        console.log("New filepath:", fileFolder.path);
    }
}

Property Documentation

append : bool

Returns true if the current logging is appending to the output log file. If false, the current log will overwrite the pre-existing one.


enabled : bool

Returns true if logging is currently enabled. Otherwise, returns false.


messagePattern : string

Returns a mockup string of what will be produced in the console log, with placeholder values describing the contents.


name : string

Returns the name of the log file. If one is not provided, the log file will be using the application name as a default.


outputLocation : url

Returns the log file's destination location.


userData : string

Returns a string that will act as identifying user data. This string will be printed in the log to denote the user producing it.


Method Documentation

setFilterRules(string rules)

The rules parameter


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.