forked from qt-creator/qt-creator
Android: Improve application output window by adding filters
- allow the user to choose the visible log levels - allow the user to choose which activities/service(s) logs are visible - wakeup the device (API 20+) - use only the most recent logs (API 21+ add "-T 0" to logcat params) - use logcat -v time format, which is the same on all Android versions In the future we can even allow the user to choose which parts of the log line are visible, e.g. time, log level, TAG, PID, Message Task-number: QTCREATORBUG-16887 Change-Id: I07ce00aff59a479660f5ac6da75eef973ba3f627 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -28,9 +28,72 @@
|
||||
#include "android_global.h"
|
||||
|
||||
#include <projectexplorer/runconfiguration.h>
|
||||
#include <qtsupport/qtoutputformatter.h>
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class QToolButton;
|
||||
namespace Android {
|
||||
|
||||
class AndroidOutputFormatter : public QtSupport::QtOutputFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum LogLevel {
|
||||
None = 0,
|
||||
Verbose = 1,
|
||||
Info = 1 << 1,
|
||||
Debug = 1 << 2,
|
||||
Warning = 1 << 3,
|
||||
Error = 1 << 4,
|
||||
Fatal = 1 << 5,
|
||||
All = Verbose | Info | Debug | Warning | Error | Fatal,
|
||||
SkipFiltering = ~All
|
||||
};
|
||||
|
||||
public:
|
||||
explicit AndroidOutputFormatter(ProjectExplorer::Project *project);
|
||||
~AndroidOutputFormatter();
|
||||
|
||||
// OutputFormatter interface
|
||||
QList<QWidget*> toolbarWidgets() const override;
|
||||
void appendMessage(const QString &text, Utils::OutputFormat format) override;
|
||||
void clear() override;
|
||||
|
||||
public slots:
|
||||
void appendPid(qint64 pid, const QString &name);
|
||||
void removePid(qint64 pid);
|
||||
|
||||
private:
|
||||
struct CachedLine {
|
||||
qint64 pid;
|
||||
LogLevel level;
|
||||
QString content;
|
||||
};
|
||||
|
||||
private:
|
||||
void updateLogMenu(LogLevel set = None, LogLevel reset = None);
|
||||
void filterMessage(const CachedLine &line);
|
||||
|
||||
void applyFilter();
|
||||
void addLogAction(LogLevel level, QMenu *logsMenu, const QString &name) {
|
||||
auto action = logsMenu->addAction(name);
|
||||
m_logLevels.push_back(qMakePair(level, action));
|
||||
action->setCheckable(true);
|
||||
connect(action, &QAction::triggered, this, [level, this](bool checked) {
|
||||
updateLogMenu(checked ? level : None , checked ? None : level);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
int m_logLevelFlags = All;
|
||||
QVector<QPair<LogLevel, QAction*>> m_logLevels;
|
||||
QHash<qint64, QAction*> m_pids;
|
||||
QScopedPointer<QToolButton> m_filtersButton;
|
||||
QMenu *m_appsMenu;
|
||||
QList<CachedLine> m_cachedLines;
|
||||
};
|
||||
|
||||
class ANDROID_EXPORT AndroidRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Reference in New Issue
Block a user