TreeFrogFramework  2.8
tlogger.h
Go to the documentation of this file.
1 #pragma once
2 #include <QString>
3 #include <QVariant>
4 #include <TGlobal>
5 #include <TLog>
6 #if QT_VERSION >= 0x060000
7 # include <QStringEncoder>
8 #endif
9 
10 class TLog;
11 class QTextCodec;
12 
13 namespace Tf {
14 
15 T_CORE_EXPORT void setAppLogLayout(const QByteArray &layout);
16 T_CORE_EXPORT void setAppLogDateTimeFormat(const QByteArray &format);
17 
18 }
19 
20 
22 public:
23  TLogger();
24  virtual ~TLogger() { }
25  virtual QString key() const = 0;
26  virtual bool isMultiProcessSafe() const = 0;
27  virtual bool open() = 0;
28  virtual void close() = 0;
29  virtual bool isOpen() const = 0;
30  virtual void log(const QByteArray &) = 0; // thread safe log output
31  virtual void log(const TLog &tlog) { log(logToByteArray(tlog)); } // thread safe log output
32  virtual void flush() { }
33  virtual QByteArray logToByteArray(const TLog &log) const;
34 
35  const QByteArray &layout() const;
36  const QByteArray &dateTimeFormat() const;
37  Tf::LogPriority threshold() const;
38  const QString &target() const;
39 
40 #if QT_VERSION < 0x060000
41  static QByteArray logToByteArray(const TLog &log, const QByteArray &layout, const QByteArray &dateTimeFormat, QTextCodec *codec = nullptr);
42 #else
43  static QByteArray logToByteArray(const TLog &log, const QByteArray &layout, const QByteArray &dateTimeFormat, QStringConverter::Encoding encoding = QStringConverter::Utf8);
44 #endif
45  static QByteArray priorityToString(Tf::LogPriority priority);
46 
47 protected:
48 #if QT_VERSION < 0x060000
49  QTextCodec *codec() const;
50 #else
51  QStringConverter::Encoding encoding() const;
52 #endif
53  QVariant settingsValue(const QString &key, const QVariant &defaultValue = QVariant()) const;
54 
55 private:
56  mutable Tf::LogPriority _threshold {(Tf::LogPriority)-1};
57  mutable QString _target;
58 #if QT_VERSION < 0x060000
59  mutable QTextCodec *_codec {nullptr};
60 #else
61  mutable std::optional<QStringConverter::Encoding> _encoding;
62 #endif
63 };
The TLog class contains log messages for web application.
Definition: tlog.h:9
The TLogger class provides an abstract base of logging functionality.
Definition: tlogger.h:21
virtual void flush()
Flushes any buffered data to the device.
Definition: tlogger.h:32
virtual ~TLogger()
Definition: tlogger.h:24
virtual void close()=0
Closes the device.
virtual bool isMultiProcessSafe() const =0
Returns true if the implementation is guaranteed to be free of race conditions when accessed by multi...
virtual bool isOpen() const =0
Returns true if the device is open; otherwise returns false.
virtual void log(const TLog &tlog)
Writes the log log to the device.
Definition: tlogger.h:31
virtual QString key() const =0
Returns a key that this logger plugin supports.
virtual bool open()=0
Opens the device for logging.
virtual void log(const QByteArray &)=0
The Tf namespace contains miscellaneous identifiers used throughout the library of TreeFrog Framework...
Definition: tdebug.h:10
T_CORE_EXPORT void setAppLogLayout(const QByteArray &layout)
Definition: tlogger.cpp:44
@ Encoding
Definition: tfnamespace.h:86
T_CORE_EXPORT void setAppLogDateTimeFormat(const QByteArray &format)
Definition: tlogger.cpp:50
LogPriority
Definition: tfnamespace.h:230
#define T_CORE_EXPORT
Definition: tdeclexport.h:28