2
0
forked from Ivasoft/DSView

add: Log setting dialog

This commit is contained in:
dreamsourcelabTAI
2022-08-17 13:46:02 +08:00
parent e07673dcae
commit 0df2da582d
9 changed files with 109 additions and 14 deletions

View File

@@ -185,20 +185,30 @@ bool bHighScale = true;
#ifdef DEBUG_INFO
if (XLOG_LEVEL_INFO > logLevel){
dsv_log_level(XLOG_LEVEL_INFO); // on develop mode, set the default log ldevel
logLevel = XLOG_LEVEL_INFO;
}
#endif
if (bStoreLog){
dsv_log_enalbe_logfile();
dsv_log_enalbe_logfile(true);
}
AppControl *control = AppControl::Instance();
AppConfig &app = AppConfig::Instance();
app.LoadAll(); //load app config
if (app._appOptions.ableSaveLog){
dsv_log_enalbe_logfile(false);
if (app._appOptions.logLevel >= logLevel){
dsv_log_level(app._appOptions.logLevel);
}
}
//----------------------run
dsv_info("----------------- version: %s-----------------", DS_VERSION_STRING);
dsv_info("Qt:%s", QT_VERSION_STR);
AppControl *control = AppControl::Instance();
AppConfig::Instance().LoadAll(); //load app config
//init core
if (!control->Init()){
dsv_err("%s", "init error!");

View File

@@ -94,6 +94,8 @@ void _loadApp(AppOptions &o, QSettings &st){
getFiled("quickScroll", st, o.quickScroll, true);
getFiled("warnofMultiTrig", st, o.warnofMultiTrig, true);
getFiled("originalData", st, o.originalData, false);
getFiled("ableSaveLog", st, o.ableSaveLog, false);
getFiled("logLevel", st, o.logLevel, 3);
QString fmt;
getFiled("protocalFormats", st, fmt, "");
@@ -109,6 +111,8 @@ void _saveApp(AppOptions &o, QSettings &st){
setFiled("quickScroll", st, o.quickScroll);
setFiled("warnofMultiTrig", st, o.warnofMultiTrig);
setFiled("originalData", st, o.originalData);
setFiled("ableSaveLog", st, o.ableSaveLog);
setFiled("logLevel", st, o.logLevel);
QString fmt = FormatArrayToString(o.m_protocolFormats);
setFiled("protocalFormats", st, fmt);
@@ -238,6 +242,8 @@ void AppConfig::LoadAll()
_loadApp(_appOptions, st);
_loadHistory(_userHistory, st);
_loadFrame(_frameOptions, st);
//dsv_dbg("Config file path:\"%s\"", st.fileName().toUtf8().data());
}
void AppConfig::SaveApp()

View File

@@ -57,6 +57,8 @@ struct AppOptions
bool quickScroll;
bool warnofMultiTrig;
bool originalData;
bool ableSaveLog;
int logLevel;
std::vector<StringPair> m_protocolFormats;
};

View File

@@ -26,7 +26,8 @@
xlog_writer *dsv_log = nullptr;
static xlog_context *log_ctx = nullptr;
bool b_logfile = false;
static bool b_logfile = false;
static int log_file_index = -1;
void dsv_log_init()
{
@@ -52,10 +53,10 @@ xlog_context* dsv_log_context()
void dsv_log_level(int l)
{
xlog_set_level(log_ctx, l);
dsv_info("%s%d", "set log level: ", l);
dsv_info("%s%d", "Set log level: ", l);
}
void dsv_log_enalbe_logfile()
void dsv_log_enalbe_logfile(bool append)
{
if (!b_logfile && log_ctx){
b_logfile = true;
@@ -68,11 +69,20 @@ void dsv_log_enalbe_logfile()
lf = GetAppDataDir() + "/DSView.log";
#endif
dsv_info("%s\"%s\"", "store log to file: ", lf.toUtf8().data());
dsv_info("%s\"%s\"", "Store log to file: ", lf.toUtf8().data());
int ret = xlog_add_receiver_from_file(log_ctx, lf.toUtf8().data(), 0);
int ret = xlog_add_receiver_from_file(log_ctx, lf.toUtf8().data(), &log_file_index, append);
if (ret != 0){
dsv_err("%s", "create log file error!");
dsv_err("%s", "Create log file error!");
}
}
}
void dsv_remove_log_file()
{
if (b_logfile && log_ctx)
{
b_logfile = false;
xlog_remove_receiver_by_index(log_ctx, log_file_index);
}
}

View File

@@ -32,7 +32,8 @@ void dsv_log_uninit();
xlog_context* dsv_log_context();
void dsv_log_level(int l);
void dsv_log_enalbe_logfile();
void dsv_log_enalbe_logfile(bool append);
void dsv_remove_log_file();
#define LOG_PREFIX ""
#define dsv_err(fmt, args...) xlog_err(dsv_log, LOG_PREFIX fmt, ## args)

View File

@@ -28,11 +28,18 @@
#include <QUrl>
#include <QApplication>
#include <assert.h>
#include <QComboBox>
#include <QFormLayout>
#include <QWidget>
#include <QCheckBox>
#include "logobar.h"
#include "../dialogs/about.h"
#include "../dialogs/dsmessagebox.h"
#include "../config/appconfig.h"
#include "../dialogs/dsdialog.h"
#include "../appcontrol.h"
#include "../log.h"
namespace pv {
namespace toolbars {
@@ -76,6 +83,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
_logo_button.addAction(_issue);
_update = new QAction(this);
_log = new QAction(this);
_menu = new QMenu(this);
_menu->addMenu(_language);
@@ -83,6 +91,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
_menu->addAction(_manual);
_menu->addAction(_issue);
_menu->addAction(_update);
_menu->addAction(_log);
_logo_button.setMenu(_menu);
_logo_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
@@ -104,6 +113,7 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
connect(_manual, SIGNAL(triggered()), this, SIGNAL(sig_open_doc()));
connect(_issue, SIGNAL(triggered()), this, SLOT(on_actionIssue_triggered()));
connect(_update, SIGNAL(triggered()), this, SLOT(on_action_update()));
connect(_log, SIGNAL(triggered()), this, SLOT(on_action_setting_log()));
}
void LogoBar::changeEvent(QEvent *event)
@@ -125,6 +135,7 @@ void LogoBar::retranslateUi()
_manual->setText(tr("&Manual"));
_issue->setText(tr("&Bug Report"));
_update->setText(tr("&Update"));
_log->setText(tr("L&og Options"));
AppConfig &app = AppConfig::Instance();
if (app._frameOptions.language == LAN_CN)
@@ -141,6 +152,7 @@ void LogoBar::reStyle()
_manual->setIcon(QIcon(iconPath+"/manual.svg"));
_issue->setIcon(QIcon(iconPath+"/bug.svg"));
_update->setIcon(QIcon(iconPath+"/update.svg"));
_log->setIcon(QIcon(iconPath+"/file.svg"));
if (_connected)
_logo_button.setIcon(QIcon(iconPath+"/logo_color.svg"));
@@ -226,5 +238,53 @@ void LogoBar::enable_toggle(bool enable)
_logo_button.setDisabled(!enable);
}
void LogoBar::on_action_setting_log()
{
AppConfig &app = AppConfig::Instance();
auto *topWind = AppControl::Instance()->GetTopWindow();
dialogs::DSDialog dlg(topWind, false, true);
dlg.setTitle(tr("Log Options"));
dlg.setMinimumSize(260, 120);
QWidget *panel = new QWidget(&dlg);
dlg.layout()->addWidget(panel);
panel->setMinimumSize(250, 110);
QFormLayout *lay = new QFormLayout();
panel->setLayout(lay);
lay->setVerticalSpacing(15);
QComboBox *cbBox = new QComboBox();
cbBox->setMinimumWidth(40);
lay->addRow(tr("Log Level"), cbBox);
for (int i=0; i<=5; i++){
cbBox->addItem(QString::number(i));
}
cbBox->setCurrentIndex(app._appOptions.logLevel);
QCheckBox *ckBox = new QCheckBox();
ckBox->setChecked(app._appOptions.ableSaveLog);
lay->addRow(tr("Save To File"), ckBox);
dlg.exec();
if (dlg.IsClickYes()){
bool ableSave = ckBox->isChecked();
int level = cbBox->currentIndex();
if (ableSave != app._appOptions.ableSaveLog || level != app._appOptions.logLevel){
app._appOptions.ableSaveLog = ableSave;
app._appOptions.logLevel = level;
app.SaveApp();
dsv_log_level(level);
if (ableSave)
dsv_log_enalbe_logfile(false);
else
dsv_remove_log_file();
}
}
}
} // namespace toolbars
} // namespace pv

View File

@@ -75,6 +75,7 @@ private slots:
void on_actionManual_triggered();
void on_actionIssue_triggered();
void on_action_update();
void on_action_setting_log();
private:
bool _enable;
@@ -93,6 +94,7 @@ private:
QAction *_manual;
QAction *_issue;
QAction *_update;
QAction *_log;
IMainForm *_mainForm;
};

View File

@@ -232,7 +232,7 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receiver rev, int *out_in
* append a log data receiver, return 0 if success.
* the log data will be writed to file.
*/
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index)
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index, int bAppend)
{
int i;
FILE *fh = NULL;
@@ -258,7 +258,11 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat
return -1;
}
fh = fopen(file_path, "a+");
if (bAppend)
fh = fopen(file_path, "a+");
else
fh = fopen(file_path, "w+");
if (fh == NULL){
strcpy(ctx->_error, "open file error");
pthread_mutex_unlock(&ctx->_mutext);

View File

@@ -85,7 +85,7 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receiver rev, int *out_in
* append a log data receiver, return 0 if success.
* the log data will be writed to file.
*/
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index);
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index, int bAppend);
/**
* remove a log data receiver,return 0 if success.