mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-13 13:32:53 +08:00
Log file operation
This commit is contained in:
parent
403f48b9be
commit
1f56410405
@ -77,13 +77,32 @@ void dsv_log_enalbe_logfile(bool append)
|
||||
}
|
||||
|
||||
void dsv_clear_log_file()
|
||||
{
|
||||
QString lf = get_dsv_log_path();
|
||||
std::string log_file = pv::path::ToUnicodePath(lf);
|
||||
int ret = xlog_reset_log_file(log_ctx, log_file_index, log_file.c_str());
|
||||
{
|
||||
if (b_logfile && log_ctx)
|
||||
{
|
||||
QString lf = get_dsv_log_path();
|
||||
std::string log_file = pv::path::ToUnicodePath(lf);
|
||||
int ret = xlog_reset_log_file(log_ctx, log_file_index, log_file.c_str());
|
||||
|
||||
if (ret != 0){
|
||||
dsv_err("%s", "Clear log file error!");
|
||||
if (ret != 0){
|
||||
dsv_err("%s", "Clear log file error!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
QDir dir;
|
||||
QString filePath = get_dsv_log_path();
|
||||
if (dir.exists(filePath))
|
||||
{
|
||||
dir.remove(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dsv_set_log_file_enable(bool flag)
|
||||
{
|
||||
if (b_logfile && log_ctx)
|
||||
{
|
||||
xlog_set_receiver_enable(log_ctx, log_file_index, flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ void dsv_log_level(int l);
|
||||
void dsv_log_enalbe_logfile(bool append);
|
||||
void dsv_remove_log_file();
|
||||
void dsv_clear_log_file();
|
||||
void dsv_set_log_file_enable(bool flag);
|
||||
|
||||
QString get_dsv_log_path();
|
||||
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <QWidget>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QFile>
|
||||
#include <QLabel>
|
||||
@ -60,6 +59,8 @@ LogoBar::LogoBar(SigSession *session, QWidget *parent) :
|
||||
_logo_button(this)
|
||||
{
|
||||
_mainForm = NULL;
|
||||
_log_open_bt = NULL;
|
||||
_log_clear_bt = NULL;
|
||||
|
||||
setMovable(false);
|
||||
setContentsMargins(0,0,0,0);
|
||||
@ -261,10 +262,12 @@ void LogoBar::on_action_setting_log()
|
||||
|
||||
QPushButton *btOpen = new QPushButton();
|
||||
btOpen->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_OPEN), "Open"));
|
||||
connect(btOpen, SIGNAL(released()), this, SLOT(on_open_log_file()));
|
||||
_log_open_bt = btOpen;
|
||||
connect(btOpen, SIGNAL(released()), this, SLOT(on_open_log_file()));
|
||||
|
||||
QPushButton *btClear = new QPushButton();
|
||||
btClear->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_CLEARE), "Clear"));
|
||||
_log_clear_bt = btClear;
|
||||
connect(btClear, SIGNAL(released()), this, SLOT(on_clear_log_file()));
|
||||
|
||||
QWidget *btWid = new QWidget();
|
||||
@ -299,10 +302,11 @@ void LogoBar::on_action_setting_log()
|
||||
|
||||
dsv_log_level(level);
|
||||
|
||||
if (ableSave)
|
||||
if (ableSave){
|
||||
dsv_log_enalbe_logfile(false);
|
||||
else
|
||||
dsv_remove_log_file();
|
||||
}
|
||||
|
||||
dsv_set_log_file_enable(ableSave);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -326,6 +330,14 @@ void LogoBar::on_clear_log_file()
|
||||
QString strMsg(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_TO_CLEAR_LOG), "Confirm!"));
|
||||
if (MsgBox::Confirm(strMsg)){
|
||||
dsv_clear_log_file();
|
||||
|
||||
if (_log_open_bt != NULL && _log_clear_bt != NULL){
|
||||
QFile qf(get_dsv_log_path());
|
||||
if (qf.exists() == false){
|
||||
_log_open_bt->setEnabled(false);
|
||||
_log_clear_bt->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <libsigrok.h>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "../sigsession.h"
|
||||
#include "../interface/icallbacks.h"
|
||||
@ -93,6 +94,9 @@ private:
|
||||
QAction *_update;
|
||||
QAction *_log;
|
||||
|
||||
QPushButton *_log_open_bt;
|
||||
QPushButton *_log_clear_bt;
|
||||
|
||||
IMainForm *_mainForm;
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,8 @@ typedef void (*xlog_print_func)(struct xlog_receiver_info *info, const char *dom
|
||||
|
||||
struct xlog_receiver_info
|
||||
{
|
||||
int _type; //see enum xlog_receiver_type
|
||||
int _type; //see enum xlog_receiver_type
|
||||
int _enable;
|
||||
FILE *_file;
|
||||
xlog_print_func _fn; // print function
|
||||
xlog_receive_callback _rev; //user callback
|
||||
@ -149,13 +150,17 @@ static xlog_context* xlog_new_context(int bConsole)
|
||||
for(i=0; i< RECEIVER_MAX_COUNT; i++){
|
||||
ctx->_receivers[i]._fn = NULL;
|
||||
ctx->_receivers[i]._file = NULL;
|
||||
ctx->_receivers[i]._enable = 0;
|
||||
ctx->_receivers[i]._rev = NULL;
|
||||
ctx->_receivers[i]._type = -1;
|
||||
}
|
||||
ctx->_count = 0;
|
||||
ctx->_log_level = XLOG_LEVEL_INFO;
|
||||
|
||||
if (bConsole){
|
||||
ctx->_receivers[0]._fn = print_to_console;
|
||||
ctx->_receivers[0]._type = RECEIVER_TYPE_CONSOLE;
|
||||
ctx->_receivers[0]._type = RECEIVER_TYPE_CONSOLE;
|
||||
ctx->_receivers[0]._enable = 1;
|
||||
ctx->_count = 1;
|
||||
}
|
||||
|
||||
@ -236,6 +241,7 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receive_callback rev, int
|
||||
ctx->_receivers[i]._type = RECEIVER_TYPE_CALLBACK;
|
||||
ctx->_receivers[i]._rev = rev;
|
||||
ctx->_receivers[i]._fn = print_to_user_callback;
|
||||
ctx->_receivers[i]._enable = 1;
|
||||
ctx->_count++;
|
||||
|
||||
if (out_index)
|
||||
@ -290,6 +296,7 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat
|
||||
ctx->_receivers[i]._type = RECEIVER_TYPE_FILE;
|
||||
ctx->_receivers[i]._fn = print_to_file;
|
||||
ctx->_receivers[i]._file = fh;
|
||||
ctx->_receivers[i]._enable = 1;
|
||||
ctx->_count++;
|
||||
|
||||
if (out_index)
|
||||
@ -355,6 +362,7 @@ XLOG_API int xlog_remove_receiver_by_index(xlog_context* ctx, int index)
|
||||
}
|
||||
|
||||
ctx->_receivers[index]._fn = NULL;
|
||||
ctx->_receivers[index]._enable = 0;
|
||||
index++;
|
||||
|
||||
while (index < RECEIVER_MAX_COUNT)
|
||||
@ -363,6 +371,7 @@ XLOG_API int xlog_remove_receiver_by_index(xlog_context* ctx, int index)
|
||||
ctx->_receivers[index-1]._type = ctx->_receivers[index]._type;
|
||||
ctx->_receivers[index-1]._rev = ctx->_receivers[index]._rev;
|
||||
ctx->_receivers[index-1]._file = ctx->_receivers[index]._file;
|
||||
ctx->_receivers[index-1]._enable = ctx->_receivers[index]._enable;
|
||||
index++;
|
||||
}
|
||||
ctx->_count--;
|
||||
@ -372,6 +381,30 @@ XLOG_API int xlog_remove_receiver_by_index(xlog_context* ctx, int index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log receiver enable to disable.
|
||||
*/
|
||||
XLOG_API int xlog_set_receiver_enable(xlog_context* ctx, int index, int bEnable)
|
||||
{
|
||||
if (ctx == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&ctx->_mutext);
|
||||
|
||||
if (index < 0 || index >= ctx->_count){
|
||||
strcpy(ctx->_error, "index out of range");
|
||||
pthread_mutex_unlock(&ctx->_mutext);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->_receivers[index]._enable = bEnable > 0 ? 1 : 0;
|
||||
|
||||
pthread_mutex_unlock(&ctx->_mutext);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all receiver,return 0 if success.
|
||||
*/
|
||||
@ -386,6 +419,12 @@ XLOG_API int xlog_clear_all_receiver(xlog_context* ctx)
|
||||
|
||||
for (i = 0; i < RECEIVER_MAX_COUNT; i++){
|
||||
ctx->_receivers[i]._fn = NULL;
|
||||
ctx->_receivers[i]._enable = 0;
|
||||
|
||||
if (ctx->_receivers[i]._file != NULL){
|
||||
fclose(ctx->_receivers[i]._file);
|
||||
ctx->_receivers[i]._file = NULL;
|
||||
}
|
||||
}
|
||||
ctx->_count = 0;
|
||||
|
||||
@ -492,7 +531,7 @@ XLOG_API int xlog_err(xlog_writer *wr, const char *format, ...)
|
||||
for (i = 0; i < ctx->_count; i++){
|
||||
inf = &ctx->_receivers[i];
|
||||
|
||||
if (inf->_fn != NULL){
|
||||
if (inf->_fn != NULL && inf->_enable){
|
||||
va_start(args, format);
|
||||
inf->_fn(inf, wr->_domain, format, args);
|
||||
va_end(args);
|
||||
@ -528,7 +567,7 @@ XLOG_API int xlog_warn(xlog_writer *wr, const char *format, ...)
|
||||
for (i = 0; i < ctx->_count; i++){
|
||||
inf = &ctx->_receivers[i];
|
||||
|
||||
if (inf->_fn != NULL){
|
||||
if (inf->_fn != NULL && inf->_enable){
|
||||
va_start(args, format);
|
||||
inf->_fn(inf, wr->_domain, format, args);
|
||||
va_end(args);
|
||||
@ -564,7 +603,7 @@ XLOG_API int xlog_info(xlog_writer *wr, const char *format, ...)
|
||||
for (i = 0; i < ctx->_count; i++){
|
||||
inf = &ctx->_receivers[i];
|
||||
|
||||
if (inf->_fn != NULL){
|
||||
if (inf->_fn != NULL && inf->_enable){
|
||||
va_start(args, format);
|
||||
inf->_fn(inf, wr->_domain, format, args);
|
||||
va_end(args);
|
||||
@ -600,7 +639,7 @@ XLOG_API int xlog_dbg(xlog_writer *wr, const char *format, ...)
|
||||
for (i = 0; i < ctx->_count; i++){
|
||||
inf = &ctx->_receivers[i];
|
||||
|
||||
if (inf->_fn != NULL){
|
||||
if (inf->_fn != NULL && inf->_enable){
|
||||
va_start(args, format);
|
||||
inf->_fn(inf, wr->_domain, format, args);
|
||||
va_end(args);
|
||||
@ -636,7 +675,7 @@ XLOG_API int xlog_detail(xlog_writer *wr, const char *format, ...)
|
||||
for (i = 0; i < ctx->_count; i++){
|
||||
inf = &ctx->_receivers[i];
|
||||
|
||||
if (inf->_fn != NULL){
|
||||
if (inf->_fn != NULL && inf->_enable){
|
||||
va_start(args, format);
|
||||
inf->_fn(inf, wr->_domain, format, args);
|
||||
va_end(args);
|
||||
|
@ -102,6 +102,11 @@ XLOG_API int xlog_reset_log_file(xlog_context* ctx, int receiver_index, const ch
|
||||
*/
|
||||
XLOG_API int xlog_remove_receiver_by_index(xlog_context* ctx, int index);
|
||||
|
||||
/**
|
||||
* Set the log receiver enable to disable.
|
||||
*/
|
||||
XLOG_API int xlog_set_receiver_enable(xlog_context* ctx, int index, int bEnable);
|
||||
|
||||
/**
|
||||
* clear all receiver,return 0 if success.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user