File tree Expand file tree Collapse file tree 4 files changed +76
-2
lines changed
Expand file tree Collapse file tree 4 files changed +76
-2
lines changed Original file line number Diff line number Diff 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
3839HEADERS += \
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
4951FORMS +=
5052
Original file line number Diff line number Diff line change 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
527int main (int argc, char *argv[])
628{
29+ checkHomePath ();
730 QApplication a (argc, argv);
31+
832 MainWindow w;
933 w.show ();
1034
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments