[libcalamares] Convenience for logging subentries

For methods that log a bunch of things, and which want to
consistently use SubEntry, but don't know when the **first**
log entry is within the method, Logger::Once can be used
to log one regular message (with function info) and the
rest are subentries.
This commit is contained in:
Adriaan de Groot 2021-03-15 22:45:29 +01:00
parent 72f67286a4
commit a90f510b85
2 changed files with 35 additions and 5 deletions

View File

@ -22,6 +22,8 @@
namespace Logger namespace Logger
{ {
class Once;
struct FuncSuppressor struct FuncSuppressor
{ {
explicit constexpr FuncSuppressor( const char[] ); explicit constexpr FuncSuppressor( const char[] );
@ -58,6 +60,7 @@ public:
virtual ~CDebug(); virtual ~CDebug();
friend CDebug& operator<<( CDebug&&, const FuncSuppressor& ); friend CDebug& operator<<( CDebug&&, const FuncSuppressor& );
friend CDebug& operator<<( CDebug&&, Once& );
private: private:
QString m_msg; QString m_msg;
@ -286,6 +289,33 @@ operator<<( QDebug& s, const Pointer& p )
s << '@' << p.ptr << Quote; s << '@' << p.ptr << Quote;
return s; return s;
} }
class Once
{
public:
Once()
: m( true )
{
}
friend CDebug& operator<<( CDebug&&, Once& );
private:
bool m = false;
};
inline CDebug&
operator<<( CDebug&& s, Once& o )
{
if ( o.m )
{
o.m = false;
return s;
}
s.m_funcinfo = nullptr;
s << SubEntry;
return s;
}
} // namespace Logger } // namespace Logger
#define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO ) #define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO )

View File

@ -61,7 +61,6 @@ ModuleManager::init()
QTimer::singleShot( 0, this, &ModuleManager::doInit ); QTimer::singleShot( 0, this, &ModuleManager::doInit );
} }
void void
ModuleManager::doInit() ModuleManager::doInit()
{ {
@ -72,6 +71,7 @@ ModuleManager::doInit()
// the module name, and must contain a settings file named module.desc. // the module name, and must contain a settings file named module.desc.
// If at any time the module loading procedure finds something unexpected, it // If at any time the module loading procedure finds something unexpected, it
// silently skips to the next module or search path. --Teo 6/2014 // silently skips to the next module or search path. --Teo 6/2014
Logger::Once deb;
for ( const QString& path : m_paths ) for ( const QString& path : m_paths )
{ {
QDir currentDir( path ); QDir currentDir( path );
@ -88,12 +88,12 @@ ModuleManager::doInit()
QFileInfo descriptorFileInfo( currentDir.absoluteFilePath( QLatin1String( "module.desc" ) ) ); QFileInfo descriptorFileInfo( currentDir.absoluteFilePath( QLatin1String( "module.desc" ) ) );
if ( !descriptorFileInfo.exists() ) if ( !descriptorFileInfo.exists() )
{ {
cDebug() << bad_descriptor << descriptorFileInfo.absoluteFilePath() << "(missing)"; cDebug() << deb << bad_descriptor << descriptorFileInfo.absoluteFilePath() << "(missing)";
continue; continue;
} }
if ( !descriptorFileInfo.isReadable() ) if ( !descriptorFileInfo.isReadable() )
{ {
cDebug() << bad_descriptor << descriptorFileInfo.absoluteFilePath() << "(unreadable)"; cDebug() << deb << bad_descriptor << descriptorFileInfo.absoluteFilePath() << "(unreadable)";
continue; continue;
} }
@ -118,12 +118,12 @@ ModuleManager::doInit()
} }
else else
{ {
cDebug() << "ModuleManager module search path does not exist:" << path; cDebug() << deb << "ModuleManager module search path does not exist:" << path;
} }
} }
// At this point m_availableDescriptorsByModuleName is filled with // At this point m_availableDescriptorsByModuleName is filled with
// the modules that were found in the search paths. // the modules that were found in the search paths.
cDebug() << "Found" << m_availableDescriptorsByModuleName.count() << "modules"; cDebug() << deb << "Found" << m_availableDescriptorsByModuleName.count() << "modules";
QTimer::singleShot( 10, this, &ModuleManager::initDone ); QTimer::singleShot( 10, this, &ModuleManager::initDone );
} }