Log panel added
This commit is contained in:
parent
1a7fa3746d
commit
6d1c9edc24
12 changed files with 186 additions and 12 deletions
|
|
@ -79,6 +79,8 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr
|
|||
}
|
||||
|
||||
qDebug().noquote() << "EXEC" << lineToExec;
|
||||
Debug::appendSshLog("Run command:" + lineToExec);
|
||||
|
||||
QSharedPointer<SshRemoteProcess> proc = client->createRemoteProcess(lineToExec.toUtf8());
|
||||
|
||||
if (!proc) {
|
||||
|
|
@ -101,7 +103,9 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr
|
|||
|
||||
QObject::connect(proc.data(), &SshRemoteProcess::readyReadStandardOutput, &wait, [proc, cbReadStdOut](){
|
||||
QString s = proc->readAllStandardOutput();
|
||||
|
||||
if (s != "." && !s.isEmpty()) {
|
||||
Debug::appendSshLog("Output: " + s);
|
||||
qDebug().noquote() << "stdout" << s;
|
||||
}
|
||||
if (cbReadStdOut) cbReadStdOut(s, proc);
|
||||
|
|
@ -110,6 +114,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr
|
|||
QObject::connect(proc.data(), &SshRemoteProcess::readyReadStandardError, &wait, [proc, cbReadStdErr](){
|
||||
QString s = proc->readAllStandardError();
|
||||
if (s != "." && !s.isEmpty()) {
|
||||
Debug::appendSshLog("Output: " + s);
|
||||
qDebug().noquote() << "stderr" << s;
|
||||
}
|
||||
if (cbReadStdErr) cbReadStdErr(s, proc);
|
||||
|
|
@ -135,6 +140,7 @@ ErrorCode ServerController::runContainerScript(const ServerCredentials &credenti
|
|||
const std::function<void (const QString &, QSharedPointer<QSsh::SshRemoteProcess>)> &cbReadStdErr)
|
||||
{
|
||||
QString fileName = "/opt/amnezia/" + Utils::getRandomString(16) + ".sh";
|
||||
Debug::appendSshLog("Run container script for " + ContainerProps::containerToString(container) + ":\n" + script);
|
||||
|
||||
ErrorCode e = uploadTextFileToContainer(container, credentials, script, fileName);
|
||||
if (e) return e;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QObject>
|
||||
#include "sshconnection.h"
|
||||
#include "sshremoteprocess.h"
|
||||
#include "debug.h"
|
||||
#include "defs.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,30 @@ void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
|
|||
}
|
||||
|
||||
Debug::m_textStream << qFormatLogMessage(type, context, msg) << endl << flush;
|
||||
Debug::appendAllLog(qFormatLogMessage(type, context, msg));
|
||||
|
||||
std::cout << qFormatLogMessage(type, context, msg).toStdString() << std::endl << std::flush;
|
||||
}
|
||||
|
||||
Debug &Debug::Instance()
|
||||
{
|
||||
static Debug s;
|
||||
return s;
|
||||
}
|
||||
|
||||
void Debug::appendSshLog(const QString &log)
|
||||
{
|
||||
QString dt = QDateTime::currentDateTime().toString();
|
||||
Instance().m_sshLog.append(dt + ": " + log + "\n");
|
||||
emit Instance().sshLogChanged(Instance().sshLog());
|
||||
}
|
||||
|
||||
void Debug::appendAllLog(const QString &log)
|
||||
{
|
||||
Instance().m_allLog.append(log + "\n");
|
||||
emit Instance().allLogChanged(Instance().allLog());
|
||||
}
|
||||
|
||||
bool Debug::init()
|
||||
{
|
||||
qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss} %{type} %{message}");
|
||||
|
|
@ -67,7 +87,7 @@ QString Debug::userLogsFilePath()
|
|||
return userLogsDir() + QDir::separator() + m_logFileName;
|
||||
}
|
||||
|
||||
QString Debug::getLogs()
|
||||
QString Debug::getLogFile()
|
||||
{
|
||||
m_file.flush();
|
||||
QFile file(userLogsFilePath());
|
||||
|
|
|
|||
|
|
@ -7,9 +7,21 @@
|
|||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
class Debug
|
||||
#include "ui/property_helper.h"
|
||||
|
||||
class Debug : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
AUTO_PROPERTY(QString, sshLog)
|
||||
AUTO_PROPERTY(QString, allLog)
|
||||
|
||||
public:
|
||||
static Debug& Instance();
|
||||
|
||||
static void appendSshLog(const QString &log);
|
||||
static void appendAllLog(const QString &log);
|
||||
|
||||
|
||||
static bool init();
|
||||
static bool openLogsFolder();
|
||||
static bool openServiceLogsFolder();
|
||||
|
|
@ -19,9 +31,13 @@ public:
|
|||
static void cleanUp();
|
||||
|
||||
static QString userLogsFilePath();
|
||||
static QString getLogs();
|
||||
static QString getLogFile();
|
||||
|
||||
private:
|
||||
Debug() {}
|
||||
Debug(Debug const &) = delete;
|
||||
Debug& operator= (Debug const&) = delete;
|
||||
|
||||
static QString userLogsDir();
|
||||
|
||||
static QFile m_file;
|
||||
|
|
|
|||
|
|
@ -181,6 +181,8 @@ int main(int argc, char *argv[])
|
|||
QCoreApplication::exit(-1);
|
||||
}, Qt::QueuedConnection);
|
||||
|
||||
engine->rootContext()->setContextProperty("Debug", &Debug::Instance());
|
||||
|
||||
engine->rootContext()->setContextProperty("UiLogic", uiLogic);
|
||||
|
||||
engine->rootContext()->setContextProperty("AppSettingsLogic", uiLogic->appSettingsLogic());
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ void AppSettingsLogic::onPushButtonOpenLogsClicked()
|
|||
|
||||
void AppSettingsLogic::onPushButtonExportLogsClicked()
|
||||
{
|
||||
QString log = Debug::getLogs();
|
||||
QString log = Debug::getLogFile();
|
||||
QString ext = ".log";
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Save log"),
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ import QtQuick.Controls 2.12
|
|||
|
||||
CheckBox {
|
||||
id: root
|
||||
property int imageWidth : 20
|
||||
property int imageHeight : 20
|
||||
indicator: Image {
|
||||
// y: 5
|
||||
id: indicator
|
||||
anchors.verticalCenter: root.verticalCenter
|
||||
height: 20
|
||||
width: 20
|
||||
height: imageHeight
|
||||
width: imageWidth
|
||||
source: root.checked ? "qrc:/images/controls/check_on.png"
|
||||
: "qrc:/images/controls/check_off.png"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,10 @@ PageBase {
|
|||
|
||||
SelectContainer {
|
||||
id: container_selector
|
||||
onAboutToHide: {
|
||||
pageLoader.focus = true
|
||||
}
|
||||
|
||||
onContainerSelected: {
|
||||
var containerProto = ContainerProps.defaultProtocol(c_index)
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ PageBase {
|
|||
SelectContainer {
|
||||
id: container_selector
|
||||
|
||||
onAboutToHide: {
|
||||
pageLoader.focus = true
|
||||
}
|
||||
|
||||
onContainerSelected: {
|
||||
var containerProto = ContainerProps.defaultProtocol(c_index)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import QtQuick 2.14
|
||||
import QtQuick.Window 2.14
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Controls.Material 2.12
|
||||
import PageEnum 1.0
|
||||
import PageType 1.0
|
||||
|
|
@ -8,6 +9,7 @@ import Qt.labs.platform 1.1
|
|||
import Qt.labs.folderlistmodel 2.12
|
||||
import QtQuick.Dialogs 1.1
|
||||
import "./"
|
||||
import "Controls"
|
||||
import "Pages"
|
||||
import "Pages/Protocols"
|
||||
import "Pages/Share"
|
||||
|
|
@ -38,7 +40,7 @@ Window {
|
|||
else if (type === PageType.ShareProto) p_obj = sharePages[page]
|
||||
else return
|
||||
|
||||
console.debug("QML gotoPage " + type + " " + page + " " + p_obj)
|
||||
//console.debug("QML gotoPage " + type + " " + page + " " + p_obj)
|
||||
|
||||
if (pageLoader.depth > 0) {
|
||||
pageLoader.currentItem.deactivated()
|
||||
|
|
@ -118,7 +120,7 @@ Window {
|
|||
focus: true
|
||||
|
||||
onCurrentItemChanged: {
|
||||
console.debug("QML onCurrentItemChanged " + pageLoader.currentItem)
|
||||
//console.debug("QML onCurrentItemChanged " + pageLoader.currentItem)
|
||||
UiLogic.currentPageValue = currentItem.page
|
||||
}
|
||||
|
||||
|
|
@ -213,15 +215,15 @@ Window {
|
|||
Connections {
|
||||
target: UiLogic
|
||||
function onGoToPage(page, reset, slide) {
|
||||
console.debug("Qml Connections onGoToPage " + page);
|
||||
//console.debug("Qml Connections onGoToPage " + page);
|
||||
root.gotoPage(PageType.Basic, page, reset, slide)
|
||||
}
|
||||
function onGoToProtocolPage(protocol, reset, slide) {
|
||||
console.debug("Qml Connections onGoToProtocolPage " + protocol);
|
||||
//console.debug("Qml Connections onGoToProtocolPage " + protocol);
|
||||
root.gotoPage(PageType.Proto, protocol, reset, slide)
|
||||
}
|
||||
function onGoToShareProtocolPage(protocol, reset, slide) {
|
||||
console.debug("Qml Connections onGoToShareProtocolPage " + protocol);
|
||||
//console.debug("Qml Connections onGoToShareProtocolPage " + protocol);
|
||||
root.gotoPage(PageType.ShareProto, protocol, reset, slide)
|
||||
}
|
||||
|
||||
|
|
@ -249,6 +251,9 @@ Window {
|
|||
root.raise()
|
||||
root.requestActivate()
|
||||
}
|
||||
function onToggleLogPanel() {
|
||||
drawer_log.visible = !drawer_log.visible
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
|
|
@ -275,4 +280,114 @@ Window {
|
|||
text: UiLogic.dialogConnectErrorText
|
||||
visible: false
|
||||
}
|
||||
|
||||
Drawer {
|
||||
id: drawer_log
|
||||
|
||||
z: -3
|
||||
y: 0
|
||||
x: 0
|
||||
edge: Qt.BottomEdge
|
||||
width: parent.width
|
||||
height: parent.height * 0.85
|
||||
|
||||
modal: true
|
||||
//interactive: activeFocus
|
||||
|
||||
onAboutToHide: {
|
||||
pageLoader.focus = true
|
||||
}
|
||||
onAboutToShow: {
|
||||
tfSshLog.focus = true
|
||||
}
|
||||
|
||||
Item {
|
||||
id: itemLog
|
||||
anchors.fill: parent
|
||||
|
||||
Keys.onPressed: {
|
||||
UiLogic.keyPressEvent(event.key)
|
||||
event.accepted = true
|
||||
}
|
||||
|
||||
RadioButtonType {
|
||||
id: rbSshLog
|
||||
focus: false
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 10
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 2
|
||||
|
||||
height: 25
|
||||
text: qsTr("Ssh log")
|
||||
}
|
||||
RadioButtonType {
|
||||
id: rbAllLog
|
||||
focus: false
|
||||
checked: true
|
||||
anchors.left: rbSshLog.right
|
||||
anchors.bottom: rbSshLog.bottom
|
||||
anchors.top: rbSshLog.top
|
||||
height: rbSshLog.height
|
||||
text: qsTr("App log")
|
||||
}
|
||||
CheckBoxType {
|
||||
id: cbLogWrap
|
||||
text: qsTr("Wrap words")
|
||||
checked: true
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: rbAllLog.bottom
|
||||
anchors.top: rbAllLog.top
|
||||
height: 15
|
||||
imageHeight: 15
|
||||
imageWidth: 15
|
||||
|
||||
onCheckedChanged: {
|
||||
tfSshLog
|
||||
}
|
||||
}
|
||||
|
||||
TextAreaType {
|
||||
id: tfSshLog
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: rbSshLog.top
|
||||
|
||||
flickableDirection: Flickable.AutoFlickIfNeeded
|
||||
|
||||
textArea.readOnly: true
|
||||
textArea.selectByMouse: true
|
||||
|
||||
textArea.verticalAlignment: Text.AlignTop
|
||||
textArea.text: {
|
||||
if (!drawer_log.visible) return ""
|
||||
else if (rbSshLog.checked ) return Debug.sshLog
|
||||
else return Debug.allLog
|
||||
}
|
||||
textArea.wrapMode: cbLogWrap.checked ? TextEdit.WordWrap: TextEdit.NoWrap
|
||||
|
||||
Keys.onPressed: {
|
||||
UiLogic.keyPressEvent(event.key)
|
||||
event.accepted = true
|
||||
}
|
||||
|
||||
textArea.onTextChanged: {
|
||||
textArea.cursorPosition = textArea.length-1
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
enabled: GC.isDesktop()
|
||||
acceptedButtons: Qt.RightButton
|
||||
onClicked: contextMenu.open()
|
||||
}
|
||||
|
||||
ContextMenu {
|
||||
id: contextMenu
|
||||
textObj: tfSshLog.textArea
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,6 +214,9 @@ void UiLogic::onUpdateAllPages()
|
|||
void UiLogic::keyPressEvent(Qt::Key key)
|
||||
{
|
||||
switch (key) {
|
||||
case Qt::Key_AsciiTilde:
|
||||
case Qt::Key_QuoteLeft: emit toggleLogPanel();
|
||||
break;
|
||||
case Qt::Key_L: Debug::openLogsFolder();
|
||||
break;
|
||||
case Qt::Key_K: Debug::openServiceLogsFolder();
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ signals:
|
|||
void show();
|
||||
void hide();
|
||||
void raise();
|
||||
void toggleLogPanel();
|
||||
|
||||
private:
|
||||
QString m_dialogConnectErrorText;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue