Git Product home page Git Product logo

Comments (7)

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

Hi there,

For QString you need to make the corresponding operator<< (take a look at CustomType sample).

For application and DLL: plog cannot write to the same file from both places but you can chain several loggeres together and write resulting info to a file (take a look at Chained Loggers).

from plog.

erakis avatar erakis commented on August 12, 2024

I properly follow the instruction for Chained Loggers but now I'm getting a crash (Access violation) when the shared library is doing the first log operation.

App

QString sApplicationFilePath = QCoreApplication::instance()->applicationFilePath();
QFileInfo fileInfo(sApplicationFilePath);
QString sLogFilePath = QDir::cleanPath( QDir( fileInfo.path() ).filePath( fileInfo.baseName() + ".log" ) );
static plog::RollingFileAppender<plog::TxtFormatter> fileAppender(sLogFilePath.toUtf8(), 1048576, 1);
plog::init(plog::debug, &fileAppender)

// Initialize the logger in the shared library.
CacheInitializePLog(plog::debug, plog::get());

Shared library

void CacheInitializePLog(plog::Severity severity, plog::IAppender* appender) {

    // Initialize the library logger
    plog::init(severity, appender);
}

Stack trace

MyApp.exe!std::char_traits<char>::length(const char * _First) Line 523  C++
MyApp.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign(const char * _Ptr) Line 1169 C++
MyApp.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> >(const char * _Ptr) Line 783 C++
MyApp.exe!plog::util::processFuncName(const char * func) Line 149   C++
MyApp.exe!plog::Record::getFunc() Line 122  C++
MyApp.exe!plog::TxtFormatter::format(const plog::Record & record) Line 25   C++
MyApp.exe!plog::RollingFileAppender<plog::TxtFormatter,plog::UTF8Converter>::write(const plog::Record & record) Line 46 C++
MyApp.exe!plog::Logger<0>::operator+=(const plog::Record & record) Line 54  C++
MyApp.exe!plog::Logger<0>::write(const plog::Record & record) Line 48   C++
MyShared.dll!plog::Logger<0>::operator+=(const plog::Record & record) Line 54   C++
MyShared.dll!DoSomething() Line 61  C++

The stack around Record seem to be corrupted on the line

MyApp.exe!plog::Logger<0>::write(const plog::Record & record) Line 48   C++

Converter on the QT side

plog::Record& plog::operator << (plog::Record& record, const QString& msg)
{
    return record << msg.toStdString();
}

QT Configuration

win32 {
    DEFINES -= UNICODE _UNICODE
    DEFINES += _MBCS _WIN32
}

I'm on this problem since yesterday and I've never found the solution yet. I'm about to give up.

The shared library and the app are build without _UNICODE support/defined. Thus, at the beginning I though that the problem could be here :

    namespace util
    {
#ifdef _WIN32
        typedef std::wstring nstring;
        typedef std::wstringstream nstringstream;
        typedef wchar_t nchar;
#else
        typedef std::string nstring;
        typedef std::stringstream nstringstream;
        typedef char nchar;
#endif

No test are done for _UNICODE macro, but I finally conclude those typedef are probably for your internal string operation. When we are using the << operator for logging, you convert it according the user input type.

from plog.

erakis avatar erakis commented on August 12, 2024

I'm also adding a sample project on Windows (VS2008 and Qt 5.4) (Library + App) to reproduce at 100% the problem. Hope it can help.

https://file.town/download/zoezsczljwmxca8vihalyxtuh

from plog.

erakis avatar erakis commented on August 12, 2024

I found that compiling the shared library with Visual Studio 2013 instead of Visual Studio 2008 do not produce the crash. But I'm stuck with VS 2008 for the time being.

Maybe this ?
Visual C++ change history 2003 - 2015

To implement various optimizations and debugging checks, the C++ Standard Library implementation intentionally breaks binary compatibility among versions of Visual Studio (2005, 2008, 2010, 2012). When the C++ Standard Library is used, this forbids the mixing of object files and static libraries that are compiled by using different versions into one binary (EXE or DLL), and forbids the passing of C++ Standard Library objects between binaries that are compiled by using different versions. The mixing of object files and static libraries (using the C++ Standard Library) that were compiled by using Visual C++ 2010 with those that were compiled by using Visual C++ in Visual Studio 2012 emits linker errors about _MSC_VER mismatch, where _MSC_VER is the macro that contains the compiler's major version (1700 for Visual C++ in Visual Studio 2012). This check cannot detect DLL mixing, and cannot detect mixing that involves Visual C++ 2008 or earlier.

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

I'll take a look at your sample project.

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

Yes, this is due to changes in std::string between Visual Studio versions. I'll fix it.

from plog.

SergiusTheBest avatar SergiusTheBest commented on August 12, 2024

I copied the crash issue to #34.

from plog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.