Comment by frickler24
Wednesday Apr 12, 2017 at 09:00 GMT
Following the article mentioned above, I played a bit with QDebug class.
Standard function is to decide between 5 modes:
- qFatal() is used if you cannot do anything more than exiting. This method needs a special handler and I think we should not use it, because of handling notify-channels etc.
- qCritical() is for really critical situations (eg unknown usb events, closed pipes, no more memory, SIGSEGV and so on). I Think we have some error-handling in the code (some handling may be anhanced :-)) to use this mode.
- qWarning() is less than critical and may be used if we could not load new firmware etc.
- qInfo() is less again and might be used for messages like our standard message "Downloaded new firmware list. 12 entries found."
- qDebug() should be used for debugging only. Here we can produce lots of raw data for our purposes.
The handling of these modes is easy and brings a second option: More info about the source of the message.
If we run "make" a Qt-Parameter QT_NO_DEBUG is set - if we run "make debug" it is not set.
We can use this to generate shorter or longer debug info. As a first implementation I added filename, lineno and function-name in the long part.
Then I added a CLI parameter -d / --debuglevel \<num>
To be compatible with the value range of the verbosity in Qt in general, I created 8 debug-modes (0..7):
/// \brief debugLevel controls the amount of debug output.
/// 0 = no debug output, just hard errors (Fatal) are displayed in a short form
/// 1 = no debug output, just hard errors (Fatal) are displayed in a long form
/// 2 = Error-handling and inconsistencies (Fatal + Critical = default value) in short form
/// 3 = as 2 but in long form
/// 4 = as 2 + Warnings (in short form)
/// 5 = as 4 but in long form
/// 6 = All info, but no debug data (eg logging from usb) in short form
/// 7 = full debug output with complete logging runtime data (eg logging from usb) in long form
By adding one test-message per mode to main (), you get the following amount of information - depending on the debug level:
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d0
DebugLevel is set to 0
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d1
DebugLevel is set to 1
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d2
DebugLevel is set to 2
Critical: Critical messages are shown
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d3
DebugLevel is set to 3
Critical: Critical messages are shown (main.cpp:319, int main(int, char**))
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d4
DebugLevel is set to 4
Warning: Warnings are shown
Critical: Critical messages are shown
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d5
DebugLevel is set to 5
Warning: Warnings are shown (main.cpp:318, int main(int, char**))
Critical: Critical messages are shown (main.cpp:319, int main(int, char**))
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d6
DebugLevel is set to 6
Info: Info messages are shown
Warning: Warnings are shown
Critical: Critical messages are shown
lutz ~/Projekte/ckb-next/src/ckb $ ../../bin/ckb -d7
DebugLevel is set to 7
Debug: Debug messages are shown (main.cpp:316, int main(int, char**))
Info: Info messages are shown (main.cpp:317, int main(int, char**))
Warning: Warnings are shown (main.cpp:318, int main(int, char**))
Critical: Critical messages are shown (main.cpp:319, int main(int, char**))
Debug: Scanning "/usr/lib/ckb-animations/ckb-gradient" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-heat" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-mviz" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-pinwheel" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-rain" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-random" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-ripple" (animscript.cpp:81, bool AnimScript::load())
Debug: Scanning "/usr/lib/ckb-animations/ckb-wave" (animscript.cpp:81, bool AnimScript::load())
Debug: Starting "/usr/lib/ckb-animations/ckb-gradient" (animscript.cpp:315, void AnimScript::begin(quint64))
Debug: Downloaded new firmware list. 12 entries found. (kbfirmware.cpp:141, void KbFirmware::processDownload(QNetworkReply*))
Any comments on this?