-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logging #331
base: master
Are you sure you want to change the base?
Add logging #331
Conversation
I think the additions look good so far! My main comment would be that we might want some logging in parts of the codebase that don't have a Qt dependency (e.g. looking for existing usage of |
Ah good point! I'll check that out, and poke you again for a check, thanks! |
Any traction here ? |
Considering holidays are coming, it might be a nice time to resume my
work on here. Possibly end of month, I'll give another jab at this.
…On Tue, Dec 05, 2023 at 08:14:56AM -0800, luzpaz wrote:
Any traction here ?
--
Reply to this email directly or view it on GitHub:
#331 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
16f68c1
to
9d69185
Compare
162ab39
to
3961ac8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall so far! Just left a few miscellaneous comments
source/app/powertabeditor.cpp
Outdated
@@ -260,14 +261,14 @@ void PowerTabEditor::openFile(QString filename) | |||
int validationResult = myDocumentManager->findDocument(path); | |||
if (validationResult > -1) | |||
{ | |||
qDebug() << "File: " << filename << " is already open"; | |||
Log::d("file: {} is already open", filename.toStdString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One possible extension would be adding format support for QString
(e.g. https://www.cppstories.com/2022/custom-stdformat-cpp20/#single-values) to avoid the toStdString() calls
This could go in an <app/log.h>
wrapper which adds Qt-specific stuff that doesn't belong in the core util
library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tried this out but I'm still getting compilation errors. I'm assuming that I should include this (app/log.h
) after including util/log.h
:
template <>
struct std::formatter<QString> : std::formatter<std::string>
{
auto format(const QString& qstr, std::format_context& ctx) const {
return std::formatter<std::string>(qstr.toStdString(), ctx);
}
};
This gives me a compilation error; I'm going to go over this this weekend if I have the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe it needs to be in the fmt
namespace rather than std
to work with the fmt library?
I'd also be fine having app/log.h
include util/log.h
so that code in the UI libraries just needs to include one header to get access to logging plus the Qt format conversions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I just realized that I basically forgot to rename the guard of the previous app/log.h
in util/log.h
. This resulted into a few hours of insanity of why do these two headers flip each other off or on (haha).
Got this to work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
source/util/log.h
Outdated
#ifndef APP_LOG_H | ||
#define APP_LOG_H | ||
|
||
#include <chrono> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid pulling in a bunch of includes in the header, one thought is that the backend function could just take the final formatted string (e.g. call vformat()
beforehand), and then it can just go in the .cpp file since it doesn't need to be templated. Then most of the related members like the mutex don't need to be accessible in the header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this too! I have to AFK for a bit, but once I'm back, I'll make sure that this works on windows too and tick that.
4942db1
to
387f58b
Compare
Partially inspired by rfc5424, along with a few other idioms I picked up along the way. This should allow one to tweak the log level by setting a minimum log level in the `Log' namespace. Right now I've set the log level to debug in the main entry point.
387f58b
to
abfb9ad
Compare
Users should be able to copy the logs from the infodialog box, along with version information for slightly easier troubleshooting.
I'm leaving this commit here instead of squashing, so that in the future, we could technically just reverse this commit.
12318dd
to
e11f0b4
Compare
This implements a very simple circular buffer that will take the last N lines in a log file, and keep those instead. Right now the maximum N is hardcoded, but the code is written in a fashion that we can revisit some of this, and add toggles where we see fit (for example in a settings dialog or so). I tested out the functionality this way: $ yes some-log-line | nl | head -5000 > log.txt And then running PTE2 with a max log size of 1000, I noticed the logfile like so: $ head -10 log.txt 4001 some-log-line 4002 some-log-line 4003 some-log-line 4004 some-log-line 4005 some-log-line 4006 some-log-line 4007 some-log-line 4008 some-log-line 4009 some-log-line 4010 some-log-line and the bottom: $ tail -10 log.txt 2023-12-30T14:38:32Z: [debug]: finding translations for locale: 2023-12-30T14:38:32Z: [debug]: locale: en-US 2023-12-30T14:38:32Z: [debug]: locale: en 2023-12-30T14:38:32Z: [debug]: locale: en-Latn-US 2023-12-30T14:38:32Z: [debug]: - checking: /home/psyomn/.local/share/powertab/powertabeditor/translations 2023-12-30T14:38:32Z: [debug]: - checking: /usr/local/share/powertab/powertabeditor/translations 2023-12-30T14:38:32Z: [debug]: - checking: /usr/share/powertab/powertabeditor/translations 2023-12-30T14:38:32Z: [debug]: - checking: /home/psyomn/programming/cc/fork/powertabeditor/build/bin/data/translations 2023-12-30T14:38:32Z: [debug]: - checking: /usr/share/qt/translations 2023-12-30T14:38:32Z: [debug]: loaded qt base translations from /usr/share/qt/translations/qtbase_en.qm and last checks: $ nl log.txt | head -1 1 4001 some-log-line $ nl log.txt | tail -1 1011 2023-12-30T14:38:32Z: [debug]: loaded qt base translations from /usr/share/qt/translations/qtbase_en.qm
This adds a custom format wrapper for QString objects, so that they can be logged directly.
Windows: so I'm getting radio silence from logs on windows, and I don't get it. I'm guessing stdout/stderr don't emit like in sane, normal, programming environments too, so I really can't gauge where exactly the fail is happening. I've read here and there that on Windows GUI programs can actually mute these unless you Linux works fine. |
Yeah I think that's probably the expected behaviour and is kinda tricky to change: e.g. https://stackoverflow.com/questions/3360548/console-output-in-a-qt-gui-app IIRC, with |
Ah, I was merely complaining that `cout` was not available as a
fallback; but that doesn't allow me to figure out why the log file is
not being created currently (I checked the paths, and APPDATA in theory
should've had this file). This will be something I'll take a look at
next weekend.
…On Sun, Jan 07, 2024 at 06:56:10PM -0800, Cameron White wrote:
Yeah I think that's probably the expected behaviour and is kinda tricky to change: e.g. https://stackoverflow.com/questions/3360548/console-output-in-a-qt-gui-app
IIRC, with `qDebug()` the behaviour was the same, but the logs did show up in the Visual Studio debugger. I think it might be using a Windows API like `OutputDebugString()`
--
Reply to this email directly or view it on GitHub:
#331 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
Description of Change(s)
Adds a very primitive and simple way to log stuff. Currently I see we don't use a lot of qDebug
and friends, but maybe we can leverage around this in the future, if we need to debug some
sort of weird behavior.
Feel free to request any sort of changes -- I'd like to keep the style and thoughts as close to the rest
of the repo, and I feel I may have overlooked something.
Thanks!
Fixes Issue(s)
N/A
check logs exist on: