Skip to content

Commit

Permalink
Log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 14, 2021
1 parent ec23c24 commit 44d5a15
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 76 deletions.
16 changes: 8 additions & 8 deletions external/libdxfrw/drw_base.h
Expand Up @@ -112,14 +112,14 @@ namespace DRW
*/
class DebugPrinter {
public:
virtual void printS(const std::string &s){(void)s;}
virtual void printI(long long int i){(void)i;}
virtual void printUI(long long unsigned int i){(void)i;}
virtual void printD(double d){(void)d;}
virtual void printH(long long int i){(void)i;}
virtual void printB(int i){(void)i;}
virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;}
virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;}
virtual void printS(const std::string &s, const char *file, const char *function, int line){(void)s;(void)file;(void)function;(void)line;}
virtual void printI(long long int i, const char *file, const char *function, int line){(void)i;(void)file;(void)function;(void)line;}
virtual void printUI(long long unsigned int i, const char *file, const char *function, int line){(void)i;(void)file;(void)function;(void)line;}
virtual void printD(double d, const char *file, const char *function, int line){(void)d;(void)file;(void)function;(void)line;}
virtual void printH(long long int i, const char *file, const char *function, int line){(void)i;(void)file;(void)function;(void)line;}
virtual void printB(int i, const char *file, const char *function, int line){(void)i;(void)file;(void)function;(void)line;}
virtual void printHL(int c, int s, int h, const char *file, const char *function, int line){(void)c;(void)s;(void)h;(void)file;(void)function;(void)line;}
virtual void printPT(double x, double y, double z, const char *file, const char *function, int line){(void)x;(void)y;(void)z;(void)file;(void)function;(void)line;}
DebugPrinter()=default;
virtual ~DebugPrinter();
};
Expand Down
76 changes: 38 additions & 38 deletions external/libdxfrw/intern/drw_dbg.cpp
Expand Up @@ -20,14 +20,14 @@ DRW_dbg *DRW_dbg::instance{nullptr};

class print_debug : public DRW::DebugPrinter {
public:
void printS(const std::string& s) override;
void printI(long long int i) override;
void printUI(long long unsigned int i) override;
void printD(double d) override;
void printH(long long int i) override;
void printB(int i) override;
void printHL(int c, int s, int h) override;
void printPT(double x, double y, double z) override;
void printS(const std::string& s, const char *file, const char *function, int line) override;
void printI(long long int i, const char *file, const char *function, int line) override;
void printUI(long long unsigned int i, const char *file, const char *function, int line) override;
void printD(double d, const char *file, const char *function, int line) override;
void printH(long long int i, const char *file, const char *function, int line) override;
void printB(int i, const char *file, const char *function, int line) override;
void printHL(int c, int s, int h, const char *file, const char *function, int line) override;
void printPT(double x, double y, double z, const char *file, const char *function, int line) override;
private:
std::ios_base::fmtflags flags{std::cerr.flags()};
};
Expand Down Expand Up @@ -69,84 +69,84 @@ DRW_dbg::Level DRW_dbg::getLevel(){
return level;
}

void DRW_dbg::print(const std::string &s){
currentPrinter->printS(s);
void DRW_dbg::print(const std::string &s, const char *file, const char *function, int line){
currentPrinter->printS(s,file,function,line);
}

void DRW_dbg::print(int i){
currentPrinter->printI(i);
void DRW_dbg::print(int i, const char *file, const char *function, int line){
currentPrinter->printI(i,file,function,line);
}

void DRW_dbg::print(unsigned int i){
currentPrinter->printUI(i);
void DRW_dbg::print(unsigned int i, const char *file, const char *function, int line){
currentPrinter->printUI(i,file,function,line);
}

void DRW_dbg::print(long long int i){
currentPrinter->printI(i);
void DRW_dbg::print(long long int i, const char *file, const char *function, int line){
currentPrinter->printI(i,file,function,line);
}

void DRW_dbg::print(long unsigned int i){
currentPrinter->printUI(i);
void DRW_dbg::print(long unsigned int i, const char *file, const char *function, int line){
currentPrinter->printUI(i,file,function,line);
}

void DRW_dbg::print(long long unsigned int i){
currentPrinter->printUI(i);
void DRW_dbg::print(long long unsigned int i, const char *file, const char *function, int line){
currentPrinter->printUI(i,file,function,line);
}

void DRW_dbg::print(double d){
currentPrinter->printD(d);
void DRW_dbg::print(double d, const char *file, const char *function, int line){
currentPrinter->printD(d,file,function,line);
}

void DRW_dbg::printH(long long int i){
currentPrinter->printH(i);
void DRW_dbg::printH(long long int i, const char *file, const char *function, int line){
currentPrinter->printH(i,file,function,line);
}

void DRW_dbg::printB(int i){
currentPrinter->printB(i);
void DRW_dbg::printB(int i, const char *file, const char *function, int line){
currentPrinter->printB(i,file,function,line);
}
void DRW_dbg::printHL(int c, int s, int h){
currentPrinter->printHL(c, s, h);
void DRW_dbg::printHL(int c, int s, int h, const char *file, const char *function, int line){
currentPrinter->printHL(c, s, h,file,function,line);
}

void DRW_dbg::printPT(double x, double y, double z){
currentPrinter->printPT(x, y, z);
void DRW_dbg::printPT(double x, double y, double z, const char *file, const char *function, int line){
currentPrinter->printPT(x, y, z,file,function,line);
}

void print_debug::printS(const std::string& s){
void print_debug::printS(const std::string& s, const char *, const char *, int ){
std::cerr << s;
}

void print_debug::printI(long long int i){
void print_debug::printI(long long int i, const char *, const char *, int ){
std::cerr << i;
}

void print_debug::printUI(long long unsigned int i){
void print_debug::printUI(long long unsigned int i, const char *, const char *, int ){
std::cerr << i;
}

void print_debug::printD(double d){
void print_debug::printD(double d, const char *, const char *, int ){
std::cerr << std::fixed << d;
}

void print_debug::printH(long long i){
void print_debug::printH(long long i, const char *, const char *, int ){
std::cerr << "0x" << std::setw(2) << std::setfill('0');
std::cerr << std::hex << i;
std::cerr.flags(flags);
}

void print_debug::printB(int i){
void print_debug::printB(int i, const char *, const char *, int ){
std::cerr << std::setw(8) << std::setfill('0');
std::cerr << std::setbase(2) << i;
std::cerr.flags(flags);
}

void print_debug::printHL(int c, int s, int h){
void print_debug::printHL(int c, int s, int h, const char *, const char *, int ){
std::cerr << c << '.' << s << '.';
std::cerr << "0x" << std::setw(2) << std::setfill('0');
std::cerr << std::hex << h;
std::cerr.flags(flags);
}

void print_debug::printPT(double x, double y, double z){
void print_debug::printPT(double x, double y, double z, const char *, const char *, int ){
std::cerr << std::fixed << "x: " << x << ", y: " << y << ", z: "<< z;
}
32 changes: 16 additions & 16 deletions external/libdxfrw/intern/drw_dbg.h
Expand Up @@ -21,11 +21,11 @@

#define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a)
#define DRW_DBGGL DRW_dbg::getInstance()->getLevel()
#define DRW_DBG(a) DRW_dbg::getInstance()->print(a)
#define DRW_DBGH(a) DRW_dbg::getInstance()->printH(a)
#define DRW_DBGB(a) DRW_dbg::getInstance()->printB(a)
#define DRW_DBGHL(a, b, c) DRW_dbg::getInstance()->printHL(a, b ,c)
#define DRW_DBGPT(a, b, c) DRW_dbg::getInstance()->printPT(a, b, c)
#define DRW_DBG(a) DRW_dbg::getInstance()->print(a, __FILE__, __FUNCTION__, __LINE__)
#define DRW_DBGH(a) DRW_dbg::getInstance()->printH(a, __FILE__, __FUNCTION__, __LINE__)
#define DRW_DBGB(a) DRW_dbg::getInstance()->printB(a, __FILE__, __FUNCTION__, __LINE__)
#define DRW_DBGHL(a, b, c) DRW_dbg::getInstance()->printHL(a, b ,c, __FILE__, __FUNCTION__, __LINE__)
#define DRW_DBGPT(a, b, c) DRW_dbg::getInstance()->printPT(a, b, c, __FILE__, __FUNCTION__, __LINE__)

class DRW_dbg {
public:
Expand All @@ -41,17 +41,17 @@ class DRW_dbg {
void setCustomDebugPrinter(std::unique_ptr<DRW::DebugPrinter> printer);
Level getLevel();
static DRW_dbg *getInstance();
void print(const std::string& s);
void print(int i);
void print(unsigned int i);
void print(long long int i);
void print(long unsigned int i);
void print(long long unsigned int i);
void print(double d);
void printH(long long int i);
void printB(int i);
void printHL(int c, int s, int h);
void printPT(double x, double y, double z);
void print(const std::string& s, const char *file, const char *function, int line);
void print(int i, const char *file, const char *function, int line);
void print(unsigned int i, const char *file, const char *function, int line);
void print(long long int i, const char *file, const char *function, int line);
void print(long unsigned int i, const char *file, const char *function, int line);
void print(long long unsigned int i, const char *file, const char *function, int line);
void print(double d, const char *file, const char *function, int line);
void printH(long long int i, const char *file, const char *function, int line);
void printB(int i, const char *file, const char *function, int line);
void printHL(int c, int s, int h, const char *file, const char *function, int line);
void printPT(double x, double y, double z, const char *file, const char *function, int line);

private:
DRW_dbg();
Expand Down
83 changes: 69 additions & 14 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -69,58 +69,108 @@ class QgsDrwDebugPrinter : public DRW::DebugPrinter
{
public:

QgsDrwDebugPrinter()
explicit QgsDrwDebugPrinter( int debugLevel = 4 )
: mTS( &mBuf )
, mLevel( debugLevel )
{ }

~QgsDrwDebugPrinter() override
{
QgsDebugMsgLevel( mBuf, 4 );
QgsDebugMsgLevel( mBuf, mLevel );
}

void printS( const std::string &s ) override
void printS( const std::string &s, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << QString::fromStdString( s );
flush();
}

void printI( long long int i ) override
void printI( long long int i, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << i;
flush();
}

void printUI( long long unsigned int i ) override
void printUI( long long unsigned int i, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << i;
flush();
}

void printD( double d ) override
void printD( double d, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << QStringLiteral( "%1 " ).arg( d, 0, 'g' );
flush();
}

void printH( long long int i ) override
void printH( long long int i, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << QStringLiteral( "0x%1" ).arg( i, 0, 16 );
flush();
}

void printB( int i ) override
void printB( int i, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << QStringLiteral( "0%1" ).arg( i, 0, 8 );
flush();
}

void printHL( int c, int s, int h ) override
void printHL( int c, int s, int h, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << QStringLiteral( "%1.%2 0x%3" ).arg( c ).arg( s ).arg( h, 0, 16 );
flush();
}

void printPT( double x, double y, double z ) override
void printPT( double x, double y, double z, const char *file, const char *function, int line ) override
{
if ( mLevel > QgsLogger::debugLevel() )
return;

mFile = file;
mFunction = function;
mLine = line;
mTS << QStringLiteral( "x:%1 y:%2 z:%3" ).arg( x, 0, 'g' ).arg( y, 0, 'g' ).arg( z, 0, 'g' );
flush();
}
Expand All @@ -129,12 +179,17 @@ class QgsDrwDebugPrinter : public DRW::DebugPrinter
std::ios_base::fmtflags flags{std::cerr.flags()};
QString mBuf;
QTextStream mTS;
QString mFile;
QString mFunction;
int mLine = 0;
int mLevel = 4;

void flush()
{
QStringList lines = mBuf.split( '\n' );
for ( int i = 0; i < lines.size() - 1; i++ )
const QStringList lines = mBuf.split( '\n' );
for ( int i = 0; i < lines.size() - 1; ++i )
{
QgsDebugMsgLevel( lines[i], 4 );
QgsLogger::debug( lines.at( i ), mLevel, mFile.toLocal8Bit().constData(), mFunction.toLocal8Bit().constData(), mLine );
}
mBuf = lines.last();
}
Expand All @@ -157,7 +212,7 @@ QgsDwgImporter::QgsDwgImporter( const QString &database, const QgsCoordinateRefe
static std::once_flag initialized;
std::call_once( initialized, [ = ]( )
{
DRW::setCustomDebugPrinter( new QgsDrwDebugPrinter() );
DRW::setCustomDebugPrinter( new QgsDrwDebugPrinter( 4 ) );
} );

const QString crswkt( crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL ) );
Expand Down

0 comments on commit 44d5a15

Please sign in to comment.