Commit 58b9a91d by 李定达

1.完成注册;2.完成支付;基本功能可用

parent 957dd0e9
http://10.92.192.12:80/adapter/downloadRsaKey
http://10.92.192.12:80/adapter
60
60
1
\ No newline at end of file
[a0]
template={"ver":1}
[0]
template={"ver":1,"statusCode":0,"message":"","type":0,"paymentMethod":"","paymentMethodCode":"","ext":{"print":"","hint":""},"info":{"status":"","statusDesc":"","actId":"","actName":"","vdata":"","code":"","authCode":"","amount":0,"products":[{"pid":"","name":"","scope":"","discount":0,"number":0,"priceAct":0,"payment":{"remaining":0,"paid":0}}]}}
[71]
template={"ver":1,"statusCode":0,"message":"","fmId":"","consumeFactAmount":0,"consumeDiscountAmount":0,"type":0,"paymentMethod":"","paymentMethodCode":"","ext":{"print":"","hint":""},"actInfo":[{"actId":"","actName":"","code":""}]}
[72]
template={"ver":1,"statusCode":0,"message":"","payAccount":"","payTransId":"","fmId":"","type":0,"paymentMethod":"","paymentMethodCode":"","ext":{"print":"","hint":"","printRow":0,"printSign":""},"transAmount":0,"merchantDiscount":0,"platformDiscount":0}
[62]
template={"ver":1,"statusCode":0,"message":"","fmId":"","ext":{"print":"","hint":"","printRow":0,"printSign":""}}
2017-8-10 9:56:8:cretserverurl:http://10.92.192.12:80/adapter/downloadRsaKey;serverurl:http://10.92.192.12:80/adapter;longtime:60;shortime:60;useRSA:1
2017-8-10 9:56:8:Not Found D:\gitcode\sbkpay\build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\client.p12
2017-8-10 9:56:8:{
"ver": 1,
"reqType": 99,
"partnerId":0,
"storeId":"171300000000000 *",
"stationId": "hhhhhh"
}
2017-8-10 9:56:8:compress json : {"partnerId":0,"reqType":99,"stationId":"hhhhhh","storeId":"171300000000000 *","ver":1}
2017-8-10 9:56:8:3DES Encode(base64):u/WS2qp09faZrVhLwtatoG5c662hZuSl7tjIqPyKDJm0usVUm29TOXWlMOgejAHSvEX+suj9Xmvy5wn+/144FhOI86UWuKvyEQFNrUfqSiDpjkSXo4ZfDdkq/84TB6hD
2017-8-9 20:21:58:cretserverurl:http://10.92.192.12:80/adapter/downloadRsaKey;serverurl:http://10.92.192.12:80/adapter;longtime:60;shortime:60;useRSA:1
2017-8-9 20:21:58:Not Found D:\gitcode\sbkpay\build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\client.p12
2017-8-9 20:21:58:{
"ver": 1,
"reqType": 99,
"partnerId":0,
"storeId":"171300000000000 *",
"stationId": "hhhhhh"
}
2017-8-9 20:21:58:compress json : {"partnerId":0,"reqType":99,"stationId":"hhhhhh","storeId":"171300000000000 *","ver":1}
2017-8-9 20:21:58:3DES Encode(base64):u/WS2qp09faZrVhLwtatoG5c662hZuSl7tjIqPyKDJm0usVUm29TOXWlMOgejAHSvEX+suj9Xmvy5wn+/144FhOI86UWuKvyEQFNrUfqSiDpjkSXo4ZfDdkq/84TB6hD
2017-8-9 20:22:0:cretserverurl:http://10.92.192.12:80/adapter/downloadRsaKey;serverurl:http://10.92.192.12:80/adapter;longtime:60;shortime:60;useRSA:1
2017-8-9 20:22:0:Not Found D:\gitcode\sbkpay\build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\client.p12
2017-8-9 20:22:0:{
"ver": 1,
"reqType": 99,
"partnerId":0,
"storeId":"171300000000000 *",
"stationId": "hhhhhh"
}
2017-8-9 20:22:0:compress json : {"partnerId":0,"reqType":99,"stationId":"hhhhhh","storeId":"171300000000000 *","ver":1}
2017-8-9 20:22:0:3DES Encode(base64):u/WS2qp09faZrVhLwtatoG5c662hZuSl7tjIqPyKDJm0usVUm29TOXWlMOgejAHSvEX+suj9Xmvy5wn+/144FhOI86UWuKvyEQFNrUfqSiDpjkSXo4ZfDdkq/84TB6hD
2017-8-9 20:22:20:recv msg failed:Couldn't connect to server
2017-8-9 20:22:20:recv buf is NULL
2017-8-9 20:22:20:Check Cret failed
2017-8-9 20:22:21:recv msg failed:Couldn't connect to server
2017-8-9 20:22:21:recv buf is NULL
2017-8-9 20:22:21:Check Cret failed
2017-8-9 20:24:4:cretserverurl:http://10.92.192.12:80/adapter/downloadRsaKey;serverurl:http://10.92.192.12:80/adapter;longtime:60;shortime:60;useRSA:1
2017-8-9 20:24:4:Not Found D:\gitcode\sbkpay\build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\client.p12
2017-8-9 20:24:4:{
"ver": 1,
"reqType": 99,
"partnerId":0,
"storeId":"171300000000000 *",
"stationId": "hhhhhh"
}
2017-8-9 20:24:4:compress json : {"partnerId":0,"reqType":99,"stationId":"hhhhhh","storeId":"171300000000000 *","ver":1}
2017-8-9 20:24:4:3DES Encode(base64):u/WS2qp09faZrVhLwtatoG5c662hZuSl7tjIqPyKDJm0usVUm29TOXWlMOgejAHSvEX+suj9Xmvy5wn+/144FhOI86UWuKvyEQFNrUfqSiDpjkSXo4ZfDdkq/84TB6hD
2017-8-9 20:24:6:cretserverurl:http://10.92.192.12:80/adapter/downloadRsaKey;serverurl:http://10.92.192.12:80/adapter;longtime:60;shortime:60;useRSA:1
2017-8-9 20:24:6:Not Found D:\gitcode\sbkpay\build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\client.p12
2017-8-9 20:24:6:{
"ver": 1,
"reqType": 99,
"partnerId":0,
"storeId":"171300000000000 *",
"stationId": "hhhhhh"
}
2017-8-9 20:24:6:compress json : {"partnerId":0,"reqType":99,"stationId":"hhhhhh","storeId":"171300000000000 *","ver":1}
2017-8-9 20:24:6:3DES Encode(base64):u/WS2qp09faZrVhLwtatoG5c662hZuSl7tjIqPyKDJm0usVUm29TOXWlMOgejAHSvEX+suj9Xmvy5wn+/144FhOI86UWuKvyEQFNrUfqSiDpjkSXo4ZfDdkq/84TB6hD
2017-8-9 20:24:25:recv msg failed:Couldn't connect to server
2017-8-9 20:24:25:recv buf is NULL
2017-8-9 20:24:25:Check Cret failed
2017-8-9 20:24:27:recv msg failed:Couldn't connect to server
2017-8-9 20:24:27:recv buf is NULL
2017-8-9 20:24:27:Check Cret failed
2017-8-9 20:26:52:delete data2017-08-08
2017-8-9 20:26:52:delete sql : delete from orderlist where businessDate<datetime('2017-08-08')
2017-8-9 20:26:52:delete table failed error : no such table: orderlist
2017-8-9 20:26:52:cretserverurl:http://10.92.192.12:80/adapter/downloadRsaKey;serverurl:http://10.92.192.12:80/adapter;longtime:60;shortime:60;useRSA:1
2017-8-9 20:26:52:Not Found D:\gitcode\sbkpay\build-sbkpay-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\client.p12
2017-8-9 20:26:52:Not Found RollBack File
2017-8-9 20:26:52:get json from pos :{"businessDate":"#dhhhhhh","code":"6921262100991","operatorId":"hhhhhh","partnerId":0,"products":[],"reqType":72,"stationId":"hhhhhh","storeId":"171300000000000 *","transAmount":0,"transId":"hh","undiscountAmount":0,"ver":1}
2017-8-9 20:26:52:partnerOrderId code : 0171300000000000 *hhhhhh20170809202652
2017-8-9 20:26:52:return json to pos{"statusCode": 307, "message": "证书加载失败无法进行交易"}
/****************************************************************************
** Meta object code from reading C++ file 'QsLogDestFunctor.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.5.1)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../../sbkpay/QsLog/QsLogDestFunctor.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'QsLogDestFunctor.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.5.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_QsLogging__FunctorDestination_t {
QByteArrayData data[5];
char stringdata0[61];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_QsLogging__FunctorDestination_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_QsLogging__FunctorDestination_t qt_meta_stringdata_QsLogging__FunctorDestination = {
{
QT_MOC_LITERAL(0, 0, 29), // "QsLogging::FunctorDestination"
QT_MOC_LITERAL(1, 30, 15), // "logMessageReady"
QT_MOC_LITERAL(2, 46, 0), // ""
QT_MOC_LITERAL(3, 47, 7), // "message"
QT_MOC_LITERAL(4, 55, 5) // "level"
},
"QsLogging::FunctorDestination\0"
"logMessageReady\0\0message\0level"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_QsLogging__FunctorDestination[] = {
// content:
7, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
1, // signalCount
// signals: name, argc, parameters, tag, flags
1, 2, 19, 2, 0x05 /* Protected */,
// signals: parameters
QMetaType::Void, QMetaType::QString, QMetaType::Int, 3, 4,
0 // eod
};
void QsLogging::FunctorDestination::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
FunctorDestination *_t = static_cast<FunctorDestination *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->logMessageReady((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
default: ;
}
} else if (_c == QMetaObject::IndexOfMethod) {
int *result = reinterpret_cast<int *>(_a[0]);
void **func = reinterpret_cast<void **>(_a[1]);
{
typedef void (FunctorDestination::*_t)(const QString & , int );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&FunctorDestination::logMessageReady)) {
*result = 0;
}
}
}
}
const QMetaObject QsLogging::FunctorDestination::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_QsLogging__FunctorDestination.data,
qt_meta_data_QsLogging__FunctorDestination, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};
const QMetaObject *QsLogging::FunctorDestination::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *QsLogging::FunctorDestination::qt_metacast(const char *_clname)
{
if (!_clname) return Q_NULLPTR;
if (!strcmp(_clname, qt_meta_stringdata_QsLogging__FunctorDestination.stringdata0))
return static_cast<void*>(const_cast< FunctorDestination*>(this));
if (!strcmp(_clname, "Destination"))
return static_cast< Destination*>(const_cast< FunctorDestination*>(this));
return QObject::qt_metacast(_clname);
}
int QsLogging::FunctorDestination::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
// SIGNAL 0
void QsLogging::FunctorDestination::logMessageReady(const QString & _t1, int _t2)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
QT_END_MOC_NAMESPACE
/****************************************************************************
** Meta object code from reading C++ file 'control.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.5.1)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../../sbkpay/control.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'control.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.5.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_Control_t {
QByteArrayData data[6];
char stringdata0[43];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_Control_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_Control_t qt_meta_stringdata_Control = {
{
QT_MOC_LITERAL(0, 0, 7), // "Control"
QT_MOC_LITERAL(1, 8, 15), // "RequestWithType"
QT_MOC_LITERAL(2, 24, 0), // ""
QT_MOC_LITERAL(3, 25, 7), // "ReqType"
QT_MOC_LITERAL(4, 33, 4), // "type"
QT_MOC_LITERAL(5, 38, 4) // "list"
},
"Control\0RequestWithType\0\0ReqType\0type\0"
"list"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_Control[] = {
// content:
7, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 2, 19, 2, 0x0a /* Public */,
// slots: parameters
QMetaType::Void, 0x80000000 | 3, QMetaType::QStringList, 4, 5,
0 // eod
};
void Control::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
Control *_t = static_cast<Control *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->RequestWithType((*reinterpret_cast< ReqType(*)>(_a[1])),(*reinterpret_cast< QStringList(*)>(_a[2]))); break;
default: ;
}
}
}
const QMetaObject Control::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_Control.data,
qt_meta_data_Control, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};
const QMetaObject *Control::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *Control::qt_metacast(const char *_clname)
{
if (!_clname) return Q_NULLPTR;
if (!strcmp(_clname, qt_meta_stringdata_Control.stringdata0))
return static_cast<void*>(const_cast< Control*>(this));
return QObject::qt_metacast(_clname);
}
int Control::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
QT_END_MOC_NAMESPACE
/****************************************************************************
** Meta object code from reading C++ file 'hostwidget.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.5.1)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../../sbkpay/hostwidget.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'hostwidget.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.5.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_HostWidget_t {
QByteArrayData data[16];
char stringdata0[287];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_HostWidget_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_HostWidget_t qt_meta_stringdata_HostWidget = {
{
QT_MOC_LITERAL(0, 0, 10), // "HostWidget"
QT_MOC_LITERAL(1, 11, 15), // "RequestWithType"
QT_MOC_LITERAL(2, 27, 0), // ""
QT_MOC_LITERAL(3, 28, 7), // "ReqType"
QT_MOC_LITERAL(4, 36, 4), // "type"
QT_MOC_LITERAL(5, 41, 4), // "list"
QT_MOC_LITERAL(6, 46, 11), // "ExitWithMSG"
QT_MOC_LITERAL(7, 58, 7), // "message"
QT_MOC_LITERAL(8, 66, 32), // "on_btn_mananger_register_clicked"
QT_MOC_LITERAL(9, 99, 29), // "on_btn_mananger_check_clicked"
QT_MOC_LITERAL(10, 129, 29), // "on_btn_mananger_print_clicked"
QT_MOC_LITERAL(11, 159, 28), // "on_btn_mananger_exit_clicked"
QT_MOC_LITERAL(12, 188, 23), // "on_btn_pay_exit_clicked"
QT_MOC_LITERAL(13, 212, 24), // "on_btn_find_exit_clicked"
QT_MOC_LITERAL(14, 237, 24), // "on_btn_sign_exit_clicked"
QT_MOC_LITERAL(15, 262, 24) // "on_btn_sign_sign_clicked"
},
"HostWidget\0RequestWithType\0\0ReqType\0"
"type\0list\0ExitWithMSG\0message\0"
"on_btn_mananger_register_clicked\0"
"on_btn_mananger_check_clicked\0"
"on_btn_mananger_print_clicked\0"
"on_btn_mananger_exit_clicked\0"
"on_btn_pay_exit_clicked\0"
"on_btn_find_exit_clicked\0"
"on_btn_sign_exit_clicked\0"
"on_btn_sign_sign_clicked"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_HostWidget[] = {
// content:
7, // revision
0, // classname
0, 0, // classinfo
10, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
2, // signalCount
// signals: name, argc, parameters, tag, flags
1, 2, 64, 2, 0x06 /* Public */,
6, 1, 69, 2, 0x06 /* Public */,
// slots: name, argc, parameters, tag, flags
8, 0, 72, 2, 0x08 /* Private */,
9, 0, 73, 2, 0x08 /* Private */,
10, 0, 74, 2, 0x08 /* Private */,
11, 0, 75, 2, 0x08 /* Private */,
12, 0, 76, 2, 0x08 /* Private */,
13, 0, 77, 2, 0x08 /* Private */,
14, 0, 78, 2, 0x08 /* Private */,
15, 0, 79, 2, 0x08 /* Private */,
// signals: parameters
QMetaType::Void, 0x80000000 | 3, QMetaType::QStringList, 4, 5,
QMetaType::Void, QMetaType::QString, 7,
// slots: parameters
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void,
0 // eod
};
void HostWidget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
HostWidget *_t = static_cast<HostWidget *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->RequestWithType((*reinterpret_cast< ReqType(*)>(_a[1])),(*reinterpret_cast< QStringList(*)>(_a[2]))); break;
case 1: _t->ExitWithMSG((*reinterpret_cast< QString(*)>(_a[1]))); break;
case 2: _t->on_btn_mananger_register_clicked(); break;
case 3: _t->on_btn_mananger_check_clicked(); break;
case 4: _t->on_btn_mananger_print_clicked(); break;
case 5: _t->on_btn_mananger_exit_clicked(); break;
case 6: _t->on_btn_pay_exit_clicked(); break;
case 7: _t->on_btn_find_exit_clicked(); break;
case 8: _t->on_btn_sign_exit_clicked(); break;
case 9: _t->on_btn_sign_sign_clicked(); break;
default: ;
}
} else if (_c == QMetaObject::IndexOfMethod) {
int *result = reinterpret_cast<int *>(_a[0]);
void **func = reinterpret_cast<void **>(_a[1]);
{
typedef void (HostWidget::*_t)(ReqType , QStringList );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&HostWidget::RequestWithType)) {
*result = 0;
}
}
{
typedef void (HostWidget::*_t)(QString );
if (*reinterpret_cast<_t *>(func) == static_cast<_t>(&HostWidget::ExitWithMSG)) {
*result = 1;
}
}
}
}
const QMetaObject HostWidget::staticMetaObject = {
{ &FMPWindow::staticMetaObject, qt_meta_stringdata_HostWidget.data,
qt_meta_data_HostWidget, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};
const QMetaObject *HostWidget::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *HostWidget::qt_metacast(const char *_clname)
{
if (!_clname) return Q_NULLPTR;
if (!strcmp(_clname, qt_meta_stringdata_HostWidget.stringdata0))
return static_cast<void*>(const_cast< HostWidget*>(this));
return FMPWindow::qt_metacast(_clname);
}
int HostWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = FMPWindow::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 10)
qt_static_metacall(this, _c, _id, _a);
_id -= 10;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 10)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 10;
}
return _id;
}
// SIGNAL 0
void HostWidget::RequestWithType(ReqType _t1, QStringList _t2)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
// SIGNAL 1
void HostWidget::ExitWithMSG(QString _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 1, _a);
}
QT_END_MOC_NAMESPACE
INPUT(
./debug\QsLogDest.o
./debug\QsLog.o
./debug\QsLogDestConsole.o
./debug\QsLogDestFile.o
./debug\QsLogDestFunctor.o
./debug\main.o
./debug\hostwidget.o
./debug\control.o
./debug\moc_QsLogDestFunctor.o
./debug\moc_hostwidget.o
./debug\moc_control.o
);
INPUT(
./release\QsLogDest.o
./release\QsLog.o
./release\QsLogDestConsole.o
./release\QsLogDestFile.o
./release\QsLogDestFunctor.o
./release\main.o
./release\hostwidget.o
./release\control.o
./release\moc_QsLogDestFunctor.o
./release\moc_hostwidget.o
./release\moc_control.o
);
D:\GITCODE\SBKCLIENT\DEBUG\FMCLIENT.EXE
D:\gitcode\sbkclient\Debug\fmclient.exp
D:\GITCODE\SBKCLIENT\DEBUG\FMCLIENT.ILK
D:\gitcode\sbkclient\Debug\fmclient.lib
D:\GITCODE\SBKCLIENT\DEBUG\FMCLIENT.PDB
D:\gitcode\sbkclient\ZH_Client\Debug\cl.command.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\CL.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\CL.write.1.tlog
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\DUMP.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\ERROR.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\FMCLIENT.EXE.EMBED.MANIFEST
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\FMCLIENT.EXE.EMBED.MANIFEST.RES
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\FMCLIENT.EXE.INTERMEDIATE.MANIFEST
D:\gitcode\sbkclient\ZH_Client\Debug\fmclient.write.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\fmclient_manifest.rc
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\HASHTABLE.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\HASHTABLE_SEED.OBJ
D:\gitcode\sbkclient\ZH_Client\Debug\link.15988.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link.15988.write.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link.15988-cvtres.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link.15988-cvtres.write.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link.command.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link.write.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link-cvtres.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\link-cvtres.write.1.tlog
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\LOAD.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\MEMORY.OBJ
D:\gitcode\sbkclient\ZH_Client\Debug\mt.command.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\mt.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\mt.write.1.tlog
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\PACK_UNPACK.OBJ
D:\gitcode\sbkclient\ZH_Client\Debug\rc.command.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\rc.read.1.tlog
D:\gitcode\sbkclient\ZH_Client\Debug\rc.write.1.tlog
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\RESDATA.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\SBK_CLIENT.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\STRBUFFER.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\STRCONV.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\TASTDATAPROCESS.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\TESTLOG.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\TESTRESDATA.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\TESTTOOL.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\UTF.OBJ
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\VALUE.OBJ
D:\gitcode\sbkclient\ZH_Client\Debug\vc100.idb
D:\GITCODE\SBKCLIENT\ZH_CLIENT\DEBUG\VC100.PDB
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
#v4.0:v100
Debug|Win32|D:\gitcode\sbkclient\|
^D:\gitcode\sbkclient\ZH_Client\ZH_Client.vcxproj
D:\gitcode\sbkclient\Debug\fmclient.lib
D:\gitcode\sbkclient\Debug\fmclient.lib
D:\gitcode\sbkclient\Debug\fmclient.exp
D:\gitcode\sbkclient\Debug\fmclient.exp
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QsLog.h"
#include "QsLogDest.h"
#ifdef QS_LOG_SEPARATE_THREAD
#include <QThreadPool>
#include <QRunnable>
#endif
#include <QMutex>
#include <QVector>
#include <QDateTime>
#include <QLatin1String>
#include <QtGlobal>
#include <cassert>
#include <cstdlib>
#include <stdexcept>
namespace QsLogging
{
typedef QVector<DestinationPtr> DestinationList;
static const char TraceString[] = "TRACE";
static const char DebugString[] = "DEBUG";
static const char InfoString[] = "INFO ";
static const char WarnString[] = "WARN ";
static const char ErrorString[] = "ERROR";
static const char FatalString[] = "FATAL";
// not using Qt::ISODate because we need the milliseconds too
static const QString fmtDateTime("yyyy-MM-ddThh:mm:ss.zzz");
static const char* LevelToText(Level theLevel)
{
switch (theLevel) {
case TraceLevel:
return TraceString;
case DebugLevel:
return DebugString;
case InfoLevel:
return InfoString;
case WarnLevel:
return WarnString;
case ErrorLevel:
return ErrorString;
case FatalLevel:
return FatalString;
case OffLevel:
return "";
default: {
assert(!"bad log level");
return InfoString;
}
}
}
#ifdef QS_LOG_SEPARATE_THREAD
class LogWriterRunnable : public QRunnable
{
public:
LogWriterRunnable(QString message, Level level);
virtual void run();
private:
QString mMessage;
Level mLevel;
};
#endif
class LoggerImpl
{
public:
LoggerImpl();
#ifdef QS_LOG_SEPARATE_THREAD
QThreadPool threadPool;
#endif
QMutex logMutex;
Level level;
DestinationList destList;
};
#ifdef QS_LOG_SEPARATE_THREAD
LogWriterRunnable::LogWriterRunnable(QString message, Level level)
: QRunnable()
, mMessage(message)
, mLevel(level)
{
}
void LogWriterRunnable::run()
{
Logger::instance().write(mMessage, mLevel);
}
#endif
LoggerImpl::LoggerImpl()
: level(InfoLevel)
{
// assume at least file + console
destList.reserve(2);
#ifdef QS_LOG_SEPARATE_THREAD
threadPool.setMaxThreadCount(1);
threadPool.setExpiryTimeout(-1);
#endif
}
Logger::Logger()
: d(new LoggerImpl)
{
}
Logger& Logger::instance()
{
static Logger instance;
return instance;
}
// tries to extract the level from a string log message. If available, conversionSucceeded will
// contain the conversion result.
Level Logger::levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded)
{
if (conversionSucceeded)
*conversionSucceeded = true;
if (logMessage.startsWith(QLatin1String(TraceString)))
return TraceLevel;
if (logMessage.startsWith(QLatin1String(DebugString)))
return DebugLevel;
if (logMessage.startsWith(QLatin1String(InfoString)))
return InfoLevel;
if (logMessage.startsWith(QLatin1String(WarnString)))
return WarnLevel;
if (logMessage.startsWith(QLatin1String(ErrorString)))
return ErrorLevel;
if (logMessage.startsWith(QLatin1String(FatalString)))
return FatalLevel;
if (conversionSucceeded)
*conversionSucceeded = false;
return OffLevel;
}
Logger::~Logger()
{
#ifdef QS_LOG_SEPARATE_THREAD
d->threadPool.waitForDone();
#endif
delete d;
d = 0;
}
void Logger::addDestination(DestinationPtr destination)
{
assert(destination.data());
QMutexLocker lock(&d->logMutex);
d->destList.push_back(destination);
}
void Logger::removeDestination(const DestinationPtr& destination)
{
QMutexLocker lock(&d->logMutex);
const int destinationIndex = d->destList.indexOf(destination);
if (destinationIndex != -1) {
d->destList.remove(destinationIndex);
}
}
bool Logger::hasDestinationOfType(const char* type) const
{
QMutexLocker lock(&d->logMutex);
for (DestinationList::iterator it = d->destList.begin(),
endIt = d->destList.end();it != endIt;++it) {
if ((*it)->type() == QLatin1String(type)) {
return true;
}
}
return false;
}
void Logger::setLoggingLevel(Level newLevel)
{
d->level = newLevel;
}
Level Logger::loggingLevel() const
{
return d->level;
}
//! creates the complete log message and passes it to the logger
void Logger::Helper::writeToLog()
{
const char* const levelName = LevelToText(level);
const QString completeMessage(QString("%1 %2 %3")
.arg(levelName)
.arg(QDateTime::currentDateTime().toString(fmtDateTime))
.arg(buffer)
);
Logger::instance().enqueueWrite(completeMessage, level);
}
Logger::Helper::~Helper()
{
try {
writeToLog();
}
catch(std::exception&) {
// you shouldn't throw exceptions from a sink
assert(!"exception in logger helper destructor");
throw;
}
}
//! directs the message to the task queue or writes it directly
void Logger::enqueueWrite(const QString& message, Level level)
{
#ifdef QS_LOG_SEPARATE_THREAD
LogWriterRunnable *r = new LogWriterRunnable(message, level);
d->threadPool.start(r);
#else
write(message, level);
#endif
}
//! Sends the message to all the destinations. The level for this message is passed in case
//! it's useful for processing in the destination.
void Logger::write(const QString& message, Level level)
{
QMutexLocker lock(&d->logMutex);
for (DestinationList::iterator it = d->destList.begin(),
endIt = d->destList.end();it != endIt;++it) {
(*it)->write(message, level);
}
}
} // end namespace
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSLOG_H
#define QSLOG_H
#include "QsLogLevel.h"
#include "QsLogDest.h"
#include <QDebug>
#include <QString>
#define QS_LOG_VERSION "2.1"
namespace QsLogging
{
class Destination;
class LoggerImpl; // d pointer
class QSLOG_SHARED_OBJECT Logger
{
public:
static Logger& instance();
static Level levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded = 0);
~Logger();
//! Adds a log message destination. Don't add null destinations.
void addDestination(DestinationPtr destination);
//! Removes a previously added destination. Does nothing if destination was not previously added.
void removeDestination(const DestinationPtr& destination);
//! Checks if a destination of a specific type has been added. Pass T::Type as parameter.
bool hasDestinationOfType(const char* type) const;
//! Logging at a level < 'newLevel' will be ignored
void setLoggingLevel(Level newLevel);
//! The default level is INFO
Level loggingLevel() const;
//! The helper forwards the streaming to QDebug and builds the final
//! log message.
class QSLOG_SHARED_OBJECT Helper
{
public:
explicit Helper(Level logLevel) :
level(logLevel),
qtDebug(&buffer) {}
~Helper();
QDebug& stream(){ return qtDebug; }
private:
void writeToLog();
Level level;
QString buffer;
QDebug qtDebug;
};
private:
Logger();
Logger(const Logger&); // not available
Logger& operator=(const Logger&); // not available
void enqueueWrite(const QString& message, Level level);
void write(const QString& message, Level level);
LoggerImpl* d;
friend class LogWriterRunnable;
};
} // end namespace
//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number
//! in the log output.
#ifndef QS_LOG_LINE_NUMBERS
#define QLOG_TRACE() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream()
#define QLOG_DEBUG() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream()
#define QLOG_INFO() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream()
#define QLOG_WARN() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream()
#define QLOG_ERROR() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream()
#define QLOG_FATAL() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream()
#else
#define QLOG_TRACE() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() << __FILE__ << '@' << __LINE__
#define QLOG_DEBUG() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__
#define QLOG_INFO() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__
#define QLOG_WARN() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__
#define QLOG_ERROR() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__
#define QLOG_FATAL() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__
#endif
#ifdef QS_LOG_DISABLE
#include "QsLogDisableForThisFile.h"
#endif
#endif // QSLOG_H
INCLUDEPATH += $$PWD
#DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message
#DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op
#DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread
#DEFINES += QS_LOG_WIN_PRINTF_CONSOLE # Use fprintf instead of OutputDebugString on Windows
SOURCES += $$PWD/QsLogDest.cpp \
$$PWD/QsLog.cpp \
$$PWD/QsLogDestConsole.cpp \
$$PWD/QsLogDestFile.cpp \
$$PWD/QsLogDestFunctor.cpp
HEADERS += $$PWD/QsLogDest.h \
$$PWD/QsLog.h \
$$PWD/QsLogDestConsole.h \
$$PWD/QsLogLevel.h \
$$PWD/QsLogDestFile.h \
$$PWD/QsLogDisableForThisFile.h \
$$PWD/QsLogDestFunctor.h
OTHER_FILES += \
$$PWD/QsLogChanges.txt \
$$PWD/README.md
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QsLogDest.h"
#include "QsLogDestConsole.h"
#include "QsLogDestFile.h"
#include "QsLogDestFunctor.h"
#include <QString>
namespace QsLogging
{
Destination::~Destination()
{
}
//! destination factory
DestinationPtr DestinationFactory::MakeFileDestination(const QString& filePath,
LogRotationOption rotation, const MaxSizeBytes &sizeInBytesToRotateAfter,
const MaxOldLogCount &oldLogsToKeep)
{
if (EnableLogRotation == rotation) {
QScopedPointer<SizeRotationStrategy> logRotation(new SizeRotationStrategy);
logRotation->setMaximumSizeInBytes(sizeInBytesToRotateAfter.size);
logRotation->setBackupCount(oldLogsToKeep.count);
return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(logRotation.take())));
}
return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(new NullRotationStrategy)));
}
DestinationPtr DestinationFactory::MakeDebugOutputDestination()
{
return DestinationPtr(new DebugOutputDestination);
}
DestinationPtr DestinationFactory::MakeFunctorDestination(QsLogging::Destination::LogFunction f)
{
return DestinationPtr(new FunctorDestination(f));
}
DestinationPtr DestinationFactory::MakeFunctorDestination(QObject *receiver, const char *member)
{
return DestinationPtr(new FunctorDestination(receiver, member));
}
} // end namespace
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSLOGDEST_H
#define QSLOGDEST_H
#include "QsLogLevel.h"
#include <QSharedPointer>
#include <QtGlobal>
class QString;
class QObject;
#ifdef QSLOG_IS_SHARED_LIBRARY
#define QSLOG_SHARED_OBJECT Q_DECL_EXPORT
#elif QSLOG_IS_SHARED_LIBRARY_IMPORT
#define QSLOG_SHARED_OBJECT Q_DECL_IMPORT
#else
#define QSLOG_SHARED_OBJECT
#endif
namespace QsLogging
{
class QSLOG_SHARED_OBJECT Destination
{
public:
typedef void (*LogFunction)(const QString &message, Level level);
public:
virtual ~Destination();
virtual void write(const QString& message, Level level) = 0;
//!
//! \brief isValid
//! \return whether the destination was created correctly
//!
virtual bool isValid() = 0;
//!
//! \brief type
//! \return the type as a string e.g: console, file.
//! The returned value may change in different versions of QsLog, but two destinations
//! of the same type will return the same value.
//!
virtual QString type() const = 0;
};
typedef QSharedPointer<Destination> DestinationPtr;
// a series of "named" paramaters, to make the file destination creation more readable
enum LogRotationOption
{
DisableLogRotation = 0,
EnableLogRotation = 1
};
struct QSLOG_SHARED_OBJECT MaxSizeBytes
{
MaxSizeBytes() : size(0) {}
explicit MaxSizeBytes(qint64 size_) : size(size_) {}
qint64 size;
};
struct QSLOG_SHARED_OBJECT MaxOldLogCount
{
MaxOldLogCount() : count(0) {}
explicit MaxOldLogCount(int count_) : count(count_) {}
int count;
};
//! Creates logging destinations/sinks. The caller shares ownership of the destinations with the logger.
//! After being added to a logger, the caller can discard the pointers.
class QSLOG_SHARED_OBJECT DestinationFactory
{
public:
static DestinationPtr MakeFileDestination(const QString& filePath,
LogRotationOption rotation = DisableLogRotation,
const MaxSizeBytes &sizeInBytesToRotateAfter = MaxSizeBytes(),
const MaxOldLogCount &oldLogsToKeep = MaxOldLogCount());
static DestinationPtr MakeDebugOutputDestination();
// takes a pointer to a function
static DestinationPtr MakeFunctorDestination(Destination::LogFunction f);
// takes a QObject + signal/slot
static DestinationPtr MakeFunctorDestination(QObject *receiver, const char *member);
};
} // end namespace
#endif // QSLOGDEST_H
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QsLogDestConsole.h"
#include <QString>
#include <QtGlobal>
#if defined(Q_OS_UNIX) || defined(Q_OS_WIN) && defined(QS_LOG_WIN_PRINTF_CONSOLE)
#include <cstdio>
void QsDebugOutput::output( const QString& message )
{
fprintf(stderr, "%s\n", qPrintable(message));
fflush(stderr);
}
#elif defined(Q_OS_WIN)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
void QsDebugOutput::output( const QString& message )
{
OutputDebugStringW(reinterpret_cast<const WCHAR*>(message.utf16()));
OutputDebugStringW(L"\n");
}
#endif
const char* const QsLogging::DebugOutputDestination::Type = "console";
void QsLogging::DebugOutputDestination::write(const QString& message, Level)
{
QsDebugOutput::output(message);
}
bool QsLogging::DebugOutputDestination::isValid()
{
return true;
}
QString QsLogging::DebugOutputDestination::type() const
{
return QString::fromLatin1(Type);
}
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSLOGDESTCONSOLE_H
#define QSLOGDESTCONSOLE_H
#include "QsLogDest.h"
class QString;
class QsDebugOutput
{
public:
static void output(const QString& a_message);
};
namespace QsLogging
{
// debugger sink
class DebugOutputDestination : public Destination
{
public:
static const char* const Type;
virtual void write(const QString& message, Level level);
virtual bool isValid();
virtual QString type() const;
};
}
#endif // QSLOGDESTCONSOLE_H
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QsLogDestFile.h"
#include <QTextCodec>
#include <QDateTime>
#include <QString>
#include <QtGlobal>
#include <iostream>
const int QsLogging::SizeRotationStrategy::MaxBackupCount = 10;
QsLogging::RotationStrategy::~RotationStrategy()
{
}
QsLogging::SizeRotationStrategy::SizeRotationStrategy()
: mCurrentSizeInBytes(0)
, mMaxSizeInBytes(0)
, mBackupsCount(0)
{
}
void QsLogging::SizeRotationStrategy::setInitialInfo(const QFile &file)
{
mFileName = file.fileName();
mCurrentSizeInBytes = file.size();
}
void QsLogging::SizeRotationStrategy::setInitialInfo(const QString &filePath, int fileSize)
{
mFileName = filePath;
mCurrentSizeInBytes = fileSize;
}
void QsLogging::SizeRotationStrategy::includeMessageInCalculation(const QString &message)
{
mCurrentSizeInBytes += message.toUtf8().size();
}
bool QsLogging::SizeRotationStrategy::shouldRotate()
{
return mCurrentSizeInBytes > mMaxSizeInBytes;
}
// Algorithm assumes backups will be named filename.X, where 1 <= X <= mBackupsCount.
// All X's will be shifted up.
void QsLogging::SizeRotationStrategy::rotate()
{
if (!mBackupsCount) {
if (!removeFileAtPath(mFileName)) {
std::cerr << "QsLog: backup delete failed " << qPrintable(mFileName);
}
return;
}
// 1. find the last existing backup than can be shifted up
const QString logNamePattern = mFileName + QString::fromUtf8(".%1");
int lastExistingBackupIndex = 0;
for (int i = 1;i <= mBackupsCount;++i) {
const QString backupFileName = logNamePattern.arg(i);
if (fileExistsAtPath(backupFileName)) {
lastExistingBackupIndex = qMin(i, mBackupsCount - 1);
}
else {
break;
}
}
// 2. shift up
for (int i = lastExistingBackupIndex;i >= 1;--i) {
const QString oldName = logNamePattern.arg(i);
const QString newName = logNamePattern.arg(i + 1);
removeFileAtPath(newName);
const bool renamed = renameFileFromTo(oldName, newName);
if (!renamed) {
std::cerr << "QsLog: could not rename backup " << qPrintable(oldName)
<< " to " << qPrintable(newName);
}
}
// 3. rename current log file
const QString newName = logNamePattern.arg(1);
if (fileExistsAtPath(newName)) {
removeFileAtPath(newName);
}
if (!renameFileFromTo(mFileName, newName)) {
std::cerr << "QsLog: could not rename log " << qPrintable(mFileName)
<< " to " << qPrintable(newName);
}
}
QIODevice::OpenMode QsLogging::SizeRotationStrategy::recommendedOpenModeFlag()
{
return QIODevice::Append;
}
void QsLogging::SizeRotationStrategy::setMaximumSizeInBytes(qint64 size)
{
Q_ASSERT(size >= 0);
mMaxSizeInBytes = size;
}
void QsLogging::SizeRotationStrategy::setBackupCount(int backups)
{
Q_ASSERT(backups >= 0);
mBackupsCount = qMin(backups, SizeRotationStrategy::MaxBackupCount);
}
bool QsLogging::SizeRotationStrategy::removeFileAtPath(const QString &path)
{
return QFile::remove(path);
}
bool QsLogging::SizeRotationStrategy::fileExistsAtPath(const QString &path)
{
return QFile::exists(path);
}
bool QsLogging::SizeRotationStrategy::renameFileFromTo(const QString &from, const QString &to)
{
return QFile::rename(from, to);
}
const char* const QsLogging::FileDestination::Type = "file";
QsLogging::FileDestination::FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy)
: mRotationStrategy(rotationStrategy)
{
mFile.setFileName(filePath);
if (!mFile.open(QFile::WriteOnly | QFile::Text | mRotationStrategy->recommendedOpenModeFlag())) {
std::cerr << "QsLog: could not open log file " << qPrintable(filePath);
}
mOutputStream.setDevice(&mFile);
mOutputStream.setCodec(QTextCodec::codecForName("UTF-8"));
mRotationStrategy->setInitialInfo(mFile);
}
void QsLogging::FileDestination::write(const QString& message, Level)
{
mRotationStrategy->includeMessageInCalculation(message);
if (mRotationStrategy->shouldRotate()) {
mOutputStream.setDevice(NULL);
mFile.close();
mRotationStrategy->rotate();
if (!mFile.open(QFile::WriteOnly | QFile::Text | mRotationStrategy->recommendedOpenModeFlag())) {
std::cerr << "QsLog: could not reopen log file " << qPrintable(mFile.fileName());
}
mRotationStrategy->setInitialInfo(mFile);
mOutputStream.setDevice(&mFile);
mOutputStream.setCodec(QTextCodec::codecForName("UTF-8"));
}
mOutputStream << message << endl;
mOutputStream.flush();
}
bool QsLogging::FileDestination::isValid()
{
return mFile.isOpen();
}
QString QsLogging::FileDestination::type() const
{
return QString::fromLatin1(Type);
}
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSLOGDESTFILE_H
#define QSLOGDESTFILE_H
#include "QsLogDest.h"
#include <QFile>
#include <QTextStream>
#include <QtGlobal>
#include <QSharedPointer>
namespace QsLogging
{
class RotationStrategy
{
public:
virtual ~RotationStrategy();
virtual void setInitialInfo(const QFile &file) = 0;
virtual void includeMessageInCalculation(const QString &message) = 0;
virtual bool shouldRotate() = 0;
virtual void rotate() = 0;
virtual QIODevice::OpenMode recommendedOpenModeFlag() = 0;
};
// Never rotates file, overwrites existing file.
class NullRotationStrategy : public RotationStrategy
{
public:
virtual void setInitialInfo(const QFile &) {}
virtual void includeMessageInCalculation(const QString &) {}
virtual bool shouldRotate() { return false; }
virtual void rotate() {}
virtual QIODevice::OpenMode recommendedOpenModeFlag() { return QIODevice::Truncate; }
};
// Rotates after a size is reached, keeps a number of <= 10 backups, appends to existing file.
class SizeRotationStrategy : public RotationStrategy
{
public:
SizeRotationStrategy();
static const int MaxBackupCount;
virtual void setInitialInfo(const QFile &file);
void setInitialInfo(const QString& filePath, int fileSize);
virtual void includeMessageInCalculation(const QString &message);
virtual bool shouldRotate();
virtual void rotate();
virtual QIODevice::OpenMode recommendedOpenModeFlag();
void setMaximumSizeInBytes(qint64 size);
void setBackupCount(int backups);
protected:
// can be overridden for testing
virtual bool removeFileAtPath(const QString& path);
virtual bool fileExistsAtPath(const QString& path);
virtual bool renameFileFromTo(const QString& from, const QString& to);
private:
QString mFileName;
qint64 mCurrentSizeInBytes;
qint64 mMaxSizeInBytes;
int mBackupsCount;
};
typedef QSharedPointer<RotationStrategy> RotationStrategyPtr;
// file message sink
class FileDestination : public Destination
{
public:
static const char* const Type;
FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy);
virtual void write(const QString& message, Level level);
virtual bool isValid();
virtual QString type() const;
private:
QFile mFile;
QTextStream mOutputStream;
QSharedPointer<RotationStrategy> mRotationStrategy;
};
}
#endif // QSLOGDESTFILE_H
// Copyright (c) 2014, Razvan Petru
// Copyright (c) 2014, Omar Carey
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#include "QsLogDestFunctor.h"
#include <cstddef>
#include <QtGlobal>
#include <QString>
const char* const QsLogging::FunctorDestination::Type = "functor";
QsLogging::FunctorDestination::FunctorDestination(LogFunction f)
: QObject(NULL)
, mLogFunction(f)
{
}
QsLogging::FunctorDestination::FunctorDestination(QObject *receiver, const char *member)
: QObject(NULL)
, mLogFunction(NULL)
{
connect(this, SIGNAL(logMessageReady(QString,int)), receiver, member, Qt::QueuedConnection);
}
void QsLogging::FunctorDestination::write(const QString &message, QsLogging::Level level)
{
if (mLogFunction)
mLogFunction(message, level);
if (level > QsLogging::TraceLevel)
emit logMessageReady(message, static_cast<int>(level));
}
bool QsLogging::FunctorDestination::isValid()
{
return true;
}
QString QsLogging::FunctorDestination::type() const
{
return QString::fromLatin1(Type);
}
// Copyright (c) 2014, Razvan Petru
// Copyright (c) 2014, Omar Carey
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSLOGDESTFUNCTOR_H
#define QSLOGDESTFUNCTOR_H
#include "QsLogDest.h"
#include <QObject>
namespace QsLogging
{
// Offers various types of function-like sinks.
// This is an advanced destination type. Depending on your configuration, LogFunction might be
// called from a different thread or even a different binary. You should not access QsLog from
// inside LogFunction and should not perform any time-consuming operations.
// logMessageReady is connected through a queued connection and trace messages are not included
class FunctorDestination : public QObject, public Destination
{
Q_OBJECT
public:
static const char* const Type;
explicit FunctorDestination(LogFunction f);
FunctorDestination(QObject *receiver, const char *member);
virtual void write(const QString &message, Level level);
virtual bool isValid();
virtual QString type() const;
protected:
// int used to avoid registering a new enum type
Q_SIGNAL void logMessageReady(const QString &message, int level);
private:
LogFunction mLogFunction;
};
}
#endif // QSLOGDESTFUNCTOR_H
#ifndef QSLOGDISABLEFORTHISFILE_H
#define QSLOGDISABLEFORTHISFILE_H
#include <QtDebug>
// When included AFTER QsLog.h, this file will disable logging in that C++ file. When included
// before, it will lead to compiler warnings or errors about macro redefinitions.
#undef QLOG_TRACE
#undef QLOG_DEBUG
#undef QLOG_INFO()
#undef QLOG_WARN
#undef QLOG_ERROR
#undef QLOG_FATAL
#define QLOG_TRACE() if (1) {} else QLOG_INFO()
#define QLOG_DEBUG() if (1) {} else QLOG_INFO()
#define QLOG_INFO()() if (1) {} else QLOG_INFO()
#define QLOG_WARN() if (1) {} else QLOG_INFO()
#define QLOG_ERROR() if (1) {} else QLOG_INFO()
#define QLOG_FATAL() if (1) {} else QLOG_INFO()
#endif // QSLOGDISABLEFORTHISFILE_H
// Copyright (c) 2013, Razvan Petru
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this
// list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
// * The name of the contributors may not be used to endorse or promote products
// derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef QSLOGLEVEL_H
#define QSLOGLEVEL_H
namespace QsLogging
{
enum Level
{
TraceLevel = 0,
DebugLevel,
InfoLevel,
WarnLevel,
ErrorLevel,
FatalLevel,
OffLevel
};
}
#endif // QSLOGLEVEL_H
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment