Merge branch 'improve-logging'
This commit is contained in:
commit
1f34460d39
@ -44,6 +44,10 @@ static unsigned int s_threshold =
|
||||
#endif
|
||||
static QMutex s_mutex;
|
||||
|
||||
static const char s_Continuation[] = "\n ";
|
||||
static const char s_SubEntry[] = " .. ";
|
||||
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
|
||||
@ -172,22 +176,39 @@ setupLogfile()
|
||||
qInstallMessageHandler( CalamaresLogHandler );
|
||||
}
|
||||
|
||||
CLog::CLog( unsigned int debugLevel )
|
||||
CDebug::CDebug( unsigned int debugLevel, const char* func )
|
||||
: QDebug( &m_msg )
|
||||
, m_debugLevel( debugLevel )
|
||||
, m_funcinfo( func )
|
||||
{
|
||||
if ( debugLevel <= LOGERROR )
|
||||
{
|
||||
m_msg = QStringLiteral( "ERROR:" );
|
||||
}
|
||||
else if ( debugLevel <= LOGWARNING )
|
||||
{
|
||||
m_msg = QStringLiteral( "WARNING:" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CLog::~CLog()
|
||||
CDebug::~CDebug()
|
||||
{
|
||||
if ( m_funcinfo )
|
||||
{
|
||||
m_msg.prepend( s_Continuation ); // Prepending, so back-to-front
|
||||
m_msg.prepend( m_funcinfo );
|
||||
}
|
||||
log( m_msg.toUtf8().data(), m_debugLevel );
|
||||
}
|
||||
|
||||
CDebug::~CDebug() {}
|
||||
constexpr FuncSuppressor::FuncSuppressor( const char s[] )
|
||||
: m_s( s )
|
||||
{
|
||||
}
|
||||
|
||||
const char Continuation[] = "\n ";
|
||||
const char SubEntry[] = " .. ";
|
||||
const constexpr FuncSuppressor Continuation( s_Continuation );
|
||||
const constexpr FuncSuppressor SubEntry( s_SubEntry );
|
||||
|
||||
QString
|
||||
toString( const QVariant& v )
|
||||
|
@ -27,8 +27,14 @@
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
DLLEXPORT extern const char Continuation[];
|
||||
DLLEXPORT extern const char SubEntry[];
|
||||
struct FuncSuppressor
|
||||
{
|
||||
explicit constexpr FuncSuppressor( const char[] );
|
||||
const char* m_s;
|
||||
};
|
||||
|
||||
DLLEXPORT extern const FuncSuppressor Continuation;
|
||||
DLLEXPORT extern const FuncSuppressor SubEntry;
|
||||
|
||||
enum
|
||||
{
|
||||
@ -41,34 +47,32 @@ enum
|
||||
LOGVERBOSE = 8
|
||||
};
|
||||
|
||||
class DLLEXPORT CLog : public QDebug
|
||||
class DLLEXPORT CDebug : public QDebug
|
||||
{
|
||||
public:
|
||||
explicit CLog( unsigned int debugLevel );
|
||||
virtual ~CLog();
|
||||
explicit CDebug( unsigned int debugLevel = LOGDEBUG, const char* func = nullptr );
|
||||
virtual ~CDebug();
|
||||
|
||||
friend QDebug& operator<<( CDebug&&, const FuncSuppressor& );
|
||||
|
||||
private:
|
||||
QString m_msg;
|
||||
unsigned int m_debugLevel;
|
||||
const char* m_funcinfo = nullptr;
|
||||
};
|
||||
|
||||
class DLLEXPORT CDebug : public CLog
|
||||
inline QDebug&
|
||||
operator<<( CDebug&& s, const FuncSuppressor& f )
|
||||
{
|
||||
public:
|
||||
CDebug( unsigned int debugLevel = LOGDEBUG )
|
||||
: CLog( debugLevel )
|
||||
{
|
||||
if ( debugLevel <= LOGERROR )
|
||||
{
|
||||
*this << "ERROR:";
|
||||
}
|
||||
else if ( debugLevel <= LOGWARNING )
|
||||
{
|
||||
*this << "WARNING:";
|
||||
}
|
||||
}
|
||||
virtual ~CDebug();
|
||||
};
|
||||
s.m_funcinfo = nullptr;
|
||||
return s << f.m_s;
|
||||
}
|
||||
|
||||
inline QDebug&
|
||||
operator<<( QDebug& s, const FuncSuppressor& f )
|
||||
{
|
||||
return s << f.m_s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The full path of the log file.
|
||||
@ -219,8 +223,8 @@ operator<<( QDebug& s, const DebugMap& t )
|
||||
}
|
||||
} // namespace Logger
|
||||
|
||||
#define cDebug() (Logger::CDebug( Logger::LOGDEBUG ) << Q_FUNC_INFO << Logger::Continuation)
|
||||
#define cWarning() Logger::CDebug( Logger::LOGWARNING )
|
||||
#define cError() Logger::CDebug( Logger::LOGERROR )
|
||||
#define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO )
|
||||
#define cWarning() Logger::CDebug( Logger::LOGWARNING, Q_FUNC_INFO )
|
||||
#define cError() Logger::CDebug( Logger::LOGERROR, Q_FUNC_INFO )
|
||||
|
||||
#endif
|
||||
|
@ -69,7 +69,7 @@ CreatePartitionTableJob::prettyStatusMessage() const
|
||||
|
||||
|
||||
static inline QDebug&
|
||||
operator <<( QDebug& s, PartitionIterator& it )
|
||||
operator <<( QDebug&& s, PartitionIterator& it )
|
||||
{
|
||||
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
|
||||
return s;
|
||||
|
Loading…
Reference in New Issue
Block a user