Comments (7)
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.
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.
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.
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.
I'll take a look at your sample project.
from plog.
Yes, this is due to changes in std::string
between Visual Studio versions. I'll fix it.
from plog.
I copied the crash issue to #34.
from plog.
Related Issues (20)
- [Feature Request] Single logger, but each appender has a different level HOT 4
- [Question] How to use Chained for multiple Classes within many DLL's
- \r\n for TxtFormatter in raw consoles HOT 4
- [Question] How to add custom prefix (record) information? HOT 2
- Can't add ConsoleAppender in a if statement HOT 2
- std::filesystem::path issue with new utf-8 mode on MSVC/Windows HOT 5
- Capture stdout and redirect to plog HOT 11
- How to use plog library in mac, its not working in mac for me HOT 5
- Please add instruction how to run samples HOT 3
- Features say doesnt require c++11 but code uses c++11 HOT 3
- Plog not initializing with too long of a file name? HOT 3
- License + create custom logger for open62541 HOT 2
- How to log an indented multiline text? HOT 2
- SyslogFormatter HOT 1
- write to /var/log/syslog HOT 1
- Cannot resolve symbol "init" HOT 2
- README does not talk about "Initializers" at https://github.com/SergiusTheBest/plog?tab=readme-ov-file#step-2-initialization HOT 2
- How to chain multiple shared lib's log, and identify log content using log header or instance id? HOT 2
- DynamicAppender can not work good HOT 2
- hexdump .to_string / ascdump .to_string HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plog.