mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
5034348c1a
When a referenced audio resource is not found in a DSL or XDXF dictionary, GoldenDict searches for this resource by filename in all other dictionaries within the current group. Naturally, the file is absent from most dictionaries (see #970). Therefore a "Failed loading resource" warning is printed for almost every dictionary in the current group. These warnings are by far the most frequent on my system. And in the scenario described above there is nothing wrong at all. So the user may want to silence these warnings to help notice less frequent and more important messages. Implement categorized logging to enable this customization. These warnings can now be disabled by adding the following line in the [Rules] section of a logging configuration file (e.g. ~/.config/QtProject/qtlogging.ini on GNU/Linux): goldendict.dictionary.resource.warning=false See also https://doc.qt.io/qt-5/qloggingcategory.html#logging-rules
61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
/* This file is (c) 2022 Igor Kushnir <igorkuo@gmail.com>
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
#ifndef CATEGORIZED_LOGGING_HH_INCLUDED
|
|
#define CATEGORIZED_LOGGING_HH_INCLUDED
|
|
|
|
// Lots of changes have been made to Qt's implementation of categorized logging in versions 5.3 and 5.4.
|
|
// __VA_ARGS__ was introduced in C++11.
|
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 4, 0 ) && __cplusplus >= 201103L
|
|
#include <QLoggingCategory>
|
|
#define GD_CATEGORIZED_LOGGING
|
|
#endif
|
|
|
|
#ifdef GD_CATEGORIZED_LOGGING
|
|
Q_DECLARE_LOGGING_CATEGORY( dictionaryResourceLc )
|
|
|
|
#if !defined(QT_NO_WARNING_OUTPUT)
|
|
/// Print a categorized warning message.
|
|
# define gdCWarning(category, ...) \
|
|
for (bool qt_category_enabled = category().isWarningEnabled(); qt_category_enabled; qt_category_enabled = false) \
|
|
gdCWarningImpl( category(), __VA_ARGS__ )
|
|
#else
|
|
# define qCWarning(category, ...) QT_NO_QDEBUG_MACRO()
|
|
#endif
|
|
|
|
#if !defined(QT_NO_DEBUG_OUTPUT)
|
|
/// Print a categorized debug message.
|
|
# define gdCDebug(category, ...) \
|
|
for (bool qt_category_enabled = category().isDebugEnabled(); qt_category_enabled; qt_category_enabled = false) \
|
|
gdCDebugImpl( category(), __VA_ARGS__ )
|
|
#else
|
|
# define qCDebug(category, ...) QT_NO_QDEBUG_MACRO()
|
|
#endif
|
|
|
|
void gdCWarningImpl( QLoggingCategory const & category, char const * message, ... ) Q_ATTRIBUTE_FORMAT_PRINTF( 2, 3 );
|
|
void gdCDebugImpl( QLoggingCategory const & category, char const * message, ... ) Q_ATTRIBUTE_FORMAT_PRINTF( 2, 3 );
|
|
|
|
#else // GD_CATEGORIZED_LOGGING
|
|
// Compatibility shims.
|
|
|
|
enum GdLoggingCategory
|
|
{
|
|
dictionaryResourceLc,
|
|
};
|
|
|
|
/// Equivalent to gdWarning( @p message, ... )
|
|
void gdCWarning( GdLoggingCategory, char const * message, ... )
|
|
#if defined(Q_CC_GNU) && !defined(__INSURE__)
|
|
__attribute__ ((format (printf, 2, 3)))
|
|
#endif
|
|
;
|
|
/// Equivalent to gdDebug( @p message, ... )
|
|
void gdCDebug( GdLoggingCategory, char const * message, ... )
|
|
#if defined(Q_CC_GNU) && !defined(__INSURE__)
|
|
__attribute__ ((format (printf, 2, 3)))
|
|
#endif
|
|
;
|
|
#endif // GD_CATEGORIZED_LOGGING
|
|
|
|
#endif // CATEGORIZED_LOGGING_HH_INCLUDED
|