https://github.com/veeso/qmlog
Simple QML Logger component and library
https://github.com/veeso/qmlog
logger logging-library qml qt qt5 qtquick
Last synced: 2 months ago
JSON representation
Simple QML Logger component and library
- Host: GitHub
- URL: https://github.com/veeso/qmlog
- Owner: veeso
- License: gpl-3.0
- Created: 2019-11-16T10:42:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T15:17:25.000Z (over 6 years ago)
- Last Synced: 2025-06-11T20:13:44.133Z (about 1 year ago)
- Topics: logger, logging-library, qml, qt, qt5, qtquick
- Language: C++
- Size: 41 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QMLog
[](https://www.gnu.org/licenses/gpl-3.0) [](http://hits.dwyl.io/ChristianVisintin/QMLog) [](https://github.com/ChristianVisintin/QMLog) [](https://github.com/ChristianVisintin/QMLog/issues) [](https://travis-ci.org/ChristianVisintin/QMLog)
Developed by *Christian Visintin*
Current Version 0.1.1 (20/11/2019)
---
- [QMLog](#qmlog)
- [Introduction](#introduction)
- [Build instructions](#build-instructions)
- [With QtCreator](#with-qtcreator)
- [With Qmake](#with-qmake)
- [Implementation](#implementation)
- [Changelog](#changelog)
- [License](#license)
---
## Introduction
QMLog is a simple QML logging module. Its main features are:
- 5 log levels
- Custom log format
- Custom date format
- Extremely easy to use
- Possibility both to log to file and to console
## Build instructions
### With QtCreator
Using qtcreator just open qmlog project and build it, eventually install the QMLog module in your Qt directory.
### With Qmake
To build QMLog follow these steps:
1. ```cd qmlog```
2. ```mkdir build/```
3. ```qmake ..```
4. ```make```
5. ```make install```
## Implementation
Once you've installed QMLog, follow these steps to implement QMLogger in your application
1. Import QTLogger in your main file (or anywhere you want)
```qml
import QMLogger 0.1
```
2. Create a QMLogger in your Item
```qml
QMLogger {
id: logger;
logFile: "/tmp/qmlogger.log";
toConsole: true;
logLevel: "INFO";
dateFormat: "yyyy-MM-dd hh:mm:ss";
logFormat: "${DATETIME} [${LEVEL}] ${COMPONENT}: ${MESSAGE}";
truncateFile: false;
onLogError: {
console.log("Could not log message: ", error);
}
}
```
- **logFile**: specify the log file location
- **toConsole**: indicates whether to log messages to console too
- **logLevel**: indicates the log level ("DEBUG"/"INFO"/"WARN"/"ERROR"/"CRITICAL")
- **dateFormat**: Indicates the date format. The date format follows the following one
- **logFormat**: The log message format. The format is made up of keywords (${}) which are replaced during the write operation. The available keywords are:
- DATETIME: the date time string, serialized as specified in dateFormat
- LEVEL: the log level string associated to this message
- COMPONENT: the component which issued the log write
- MESSAGE: the log message
- **truncateFile**: indicates whether the log file should be truncated at application start
- **onLogError**: an handler in case of log error signal is raised by the QMLogger.
3. Log content
Once you've configured your logger, from any logger's sibling item (or one of its children) you can log a message calling a log function:
```qml
logger.debug("Component foo", "This is a debug message");
logger.info("Component bar", "This is an info message");
logger.warn("Component foo", "This is a warn message");
logger.error("Component bar", "this is an error message");
logger.critical("Component foo", "This is a critical error message");
```
## Changelog
### 0.1.1 (20/11/2019)
- Don't log to file if file is unset
- console changed to 'toConsole'
## License
Licensed under the GNU GPLv3 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
You can read the entire license [HERE](./LICENSE)