qt_demoe/control/savelog/savelog.h

155 lines
3.5 KiB
C
Raw Normal View History

#ifndef SAVELOG_H
#define SAVELOG_H
2021-09-26 01:50:09 +00:00
/**
* :feiyangqingyun(QQ:517216493) 2016-12-16
* 1.
* 2.
* 3.
2021-10-13 06:15:18 +00:00
* 4.
2021-10-30 11:20:00 +00:00
* 5. 128kb
* 6.
* 7.
* 8.
* 9. 线
* 10.
* 11. Qt4+Qt5+Qt6
* 12. 使start()stop()
2021-09-26 01:50:09 +00:00
*/
#include <QObject>
class QFile;
class QTcpSocket;
class QTcpServer;
2021-10-30 11:20:00 +00:00
//消息类型
enum MsgType {
MsgType_Debug = 0x0001,
MsgType_Info = 0x0002,
MsgType_Warning = 0x0004,
MsgType_Critical = 0x0008,
MsgType_Fatal = 0x0010,
};
#ifdef quc
2020-12-24 10:00:09 +00:00
class Q_DECL_EXPORT SaveLog : public QObject
#else
class SaveLog : public QObject
#endif
{
Q_OBJECT
public:
static SaveLog *Instance();
explicit SaveLog(QObject *parent = 0);
~SaveLog();
private:
static QScopedPointer<SaveLog> self;
2021-10-30 11:20:00 +00:00
//是否在运行
bool isRun;
//文件最大行数 0表示不启用
int maxRow, currentRow;
//文件最大大小 0表示不启用 单位kb
int maxSize;
//是否重定向到网络
bool toNet;
2021-10-13 06:15:18 +00:00
//是否输出日志上下文
bool useContext;
2021-10-30 11:20:00 +00:00
//文件对象
QFile *file;
//日志文件路径
QString path;
//日志文件名称
QString name;
//日志文件完整名称
QString fileName;
2021-10-30 11:20:00 +00:00
//消息类型
MsgType msgType;
private:
void openFile(const QString &fileName);
2021-10-13 06:15:18 +00:00
public:
bool getUseContext();
2021-10-30 11:20:00 +00:00
MsgType getMsgType();
2021-10-13 06:15:18 +00:00
2021-10-07 02:57:25 +00:00
Q_SIGNALS:
//发送内容信号
void send(const QString &content);
2021-10-07 02:57:25 +00:00
public Q_SLOTS:
//启动日志服务
void start();
//暂停日志服务
void stop();
2021-10-30 11:20:00 +00:00
//清空状态
void clear();
//保存日志
void save(const QString &content);
2021-10-30 11:20:00 +00:00
//设置日志文件最大行数
void setMaxRow(int maxRow);
//设置日志文件最大大小 单位kb
void setMaxSize(int maxSize);
//设置监听端口
void setListenPort(int listenPort);
//设置是否重定向到网络
void setToNet(bool toNet);
2021-10-13 06:15:18 +00:00
//设置是否输出日志上下文
void setUseContext(bool useContext);
2021-10-30 11:20:00 +00:00
//设置日志文件存放路径
void setPath(const QString &path);
//设置日志文件名称
void setName(const QString &name);
2021-10-30 11:20:00 +00:00
//设置消息类型
void setMsgType(const MsgType &msgType);
};
2021-10-30 11:20:00 +00:00
#ifdef quc
class Q_DECL_EXPORT SendLog : public QObject
#else
class SendLog : public QObject
2021-10-30 11:20:00 +00:00
#endif
{
Q_OBJECT
public:
static SendLog *Instance();
explicit SendLog(QObject *parent = 0);
~SendLog();
private:
static QScopedPointer<SendLog> self;
2021-10-07 02:57:25 +00:00
2021-10-30 11:20:00 +00:00
//监听端口
int listenPort;
2021-10-07 02:57:25 +00:00
//网络通信对象
QTcpSocket *socket;
2021-10-07 02:57:25 +00:00
//网络监听服务器
QTcpServer *server;
private slots:
2021-10-07 02:57:25 +00:00
//新连接到来
void newConnection();
2021-10-07 02:57:25 +00:00
public Q_SLOTS:
2021-10-30 11:20:00 +00:00
//设置监听端口
void setListenPort(int listenPort);
//启动和停止服务
void start();
void stop();
//发送日志
void send(const QString &content);
};
#endif // SAVELOG_H