| 1 |
// Copyright © 2016 Canonical Ltd. |
| 2 |
// Author: Loïc Molinari <[email protected]> |
| 3 |
// |
| 4 |
// This file is part of Lomiri UI Toolkit. |
| 5 |
// |
| 6 |
// Lomiri UI Toolkit is free software: you can redistribute it and/or modify it |
| 7 |
// under the terms of the GNU Lesser General Public License as published by the |
| 8 |
// Free Software Foundation; version 3. |
| 9 |
// |
| 10 |
// Lomiri UI Toolkit is distributed in the hope that it will be useful, but |
| 11 |
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 13 |
// for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with Lomiri UI Toolkit. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
#ifndef LOGGER_H |
| 19 |
#define LOGGER_H |
| 20 |
|
| 21 |
#include <QtCore/QFile> |
| 22 |
|
| 23 |
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 24 |
#include <LomiriMetrics-Qt6/lomirimetricsglobal.h> |
| 25 |
#else |
| 26 |
#include <LomiriMetrics/lomirimetricsglobal.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
class UMFileLoggerPrivate; |
| 30 |
struct UMLTTNGPlugin; |
| 31 |
struct UMEvent; |
| 32 |
|
| 33 |
// Log events to a specific device. |
| 34 |
class LOMIRI_METRICS_EXPORT UMLogger |
| 35 |
{ |
| 36 |
public: |
| 37 |
virtual ~UMLogger() {} |
| 38 |
|
| 39 |
// Log events. |
| 40 |
virtual void log(const UMEvent& event) = 0; |
| 41 |
|
| 42 |
// Get whether the target device has been opened successfully or not. |
| 43 |
virtual bool isOpen() = 0; |
| 44 |
}; |
| 45 |
|
| 46 |
// Log events to a file. |
| 47 |
class LOMIRI_METRICS_EXPORT UMFileLogger : public UMLogger |
| 48 |
{ |
| 49 |
public: |
| 50 |
UMFileLogger(const QString& filename, bool parsable = true); |
| 51 |
UMFileLogger(FILE* fileHandle, bool parsable = false); |
| 52 |
~UMFileLogger(); |
| 53 |
|
| 54 |
void log(const UMEvent& event) Q_DECL_OVERRIDE; |
| 55 |
bool isOpen() Q_DECL_OVERRIDE; |
| 56 |
|
| 57 |
void setParsable(bool parsable); |
| 58 |
bool parsable(); |
| 59 |
|
| 60 |
private: |
| 61 |
UMFileLoggerPrivate* const d_ptr; |
| 62 |
Q_DECLARE_PRIVATE(UMFileLogger) |
| 63 |
}; |
| 64 |
|
| 65 |
#if defined(Q_OS_LINUX) && defined(LTTNG_PLUGIN_BUILD_PATH) |
| 66 |
|
| 67 |
// Log events to LTTng. |
| 68 |
class LOMIRI_METRICS_EXPORT UMLTTNGLogger : public UMLogger |
| 69 |
{ |
| 70 |
public: |
| 71 |
UMLTTNGLogger(); |
| 72 |
void log(const UMEvent& event) Q_DECL_OVERRIDE; |
| 73 |
bool isOpen() Q_DECL_OVERRIDE { return true; } |
| 74 |
|
| 75 |
private: |
| 76 |
static UMLTTNGPlugin* m_plugin; |
| 77 |
static bool m_error; |
| 78 |
|
| 79 |
Q_DECL_UNUSED_MEMBER void* __reserved; |
| 80 |
}; |
| 81 |
|
| 82 |
#endif // defined(Q_OS_LINUX) && defined(LTTNG_PLUGIN_BUILD_PATH) |
| 83 |
|
| 84 |
#endif // LOGGER_H |