Skip to content

Commit 6449b27

Browse files
committed
1.add log manager for project
2.add home dir for visual log
1 parent 0940ad4 commit 6449b27

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

VisualLog.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ SOURCES += \
3333
logviewer/logviewport.cpp \
3434
highlighter/logfilter.cpp \
3535
highlighter/jsonhighlighter.cpp \
36-
highlighter/jsontextedit.cpp
36+
highlighter/jsontextedit.cpp \
37+
utils/logutil.cpp
3738

3839
HEADERS += \
3940
mainwindow.h \
@@ -44,7 +45,8 @@ HEADERS += \
4445
logviewer/logviewport.h \
4546
highlighter/logfilter.h \
4647
highlighter/jsonhighlighter.h \
47-
highlighter/jsontextedit.h
48+
highlighter/jsontextedit.h \
49+
utils/logutil.h
4850

4951
FORMS +=
5052

main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
#include "mainwindow.h"
22
#include <QApplication>
3+
#include <QDir>
4+
#include <QString>
5+
#include <utils/logutil.h>
36

7+
const QString TAG = "main";
8+
9+
10+
void checkHomePath()
11+
{
12+
LogUtil::i(TAG, "init working directory");
13+
QDir wd = QDir::home();
14+
15+
if (!wd.exists(".VisualLog")) {
16+
if (wd.mkdir(".VisualLog"))
17+
wd.cd(".VisualLog");
18+
} else {
19+
wd.cd(".VisualLog");
20+
}
21+
22+
if (QDir::setCurrent(wd.path())) {
23+
LogUtil::i(TAG, "cd to dir:"+wd.path());
24+
}
25+
}
426

527
int main(int argc, char *argv[])
628
{
29+
checkHomePath();
730
QApplication a(argc, argv);
31+
832
MainWindow w;
933
w.show();
1034

utils/logutil.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "logutil.h"
2+
3+
LogUtil::LogUtil()
4+
{
5+
}
6+
7+
void LogUtil::i(const QString &tag, const QString &msg)
8+
{
9+
if (sDebug && !tag.isNull()) {
10+
qInfo()<<qPrintable(QString("[%1]: %2").arg(tag).arg(msg));
11+
}
12+
}
13+
14+
void LogUtil::d(const QString &tag, const QString &msg)
15+
{
16+
if (sDebug && !tag.isNull()) {
17+
qDebug()<<qPrintable(QString("[%1]: %2").arg(tag).arg(msg));
18+
}
19+
}
20+
21+
void LogUtil::e(const QString &tag, const QString &msg)
22+
{
23+
if (sDebug && !tag.isNull()) {
24+
qWarning()<<qPrintable(QString("[%1]: %2").arg(tag).arg(msg));
25+
}
26+
}

utils/logutil.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef LOGUTIL_H
2+
#define LOGUTIL_H
3+
4+
#include <QDebug>
5+
#include <QString>
6+
7+
8+
class LogUtil
9+
{
10+
public:
11+
static void i(const QString &tag, const QString &msg);
12+
static void d(const QString &tag, const QString &msg);
13+
static void e(const QString &tag, const QString &msg);
14+
15+
private:
16+
LogUtil();
17+
18+
private:
19+
static const bool sDebug = true;
20+
};
21+
22+
#endif // LOGUTIL_H

0 commit comments

Comments
 (0)