We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want use MessageOnlyFormatter first, then switch to TxtFormatter, but following code is not working
static plog::DynamicAppender dynamicAppender; static plog::RollingFileAppender<plog::MessageOnlyFormatter> startupAppender(logFileName.c_str(), logMaxSize, logMaxCount); static plog::RollingFileAppender<plog::TxtFormatter> normalAppender(logFileName.c_str(), logMaxSize, logMaxCount); dynamicAppender.addAppender(&startupAppender); #ifdef QT_DEBUG plog::init(plog::debug, &dynamicAppender); #else plog::init(plog::info, &dynamicAppender); #endif PLOG(plog::info) << ""; PLOG(plog::info) << ""; PLOG(plog::info) << "======================================"; PLOG(plog::info) << "Start time: " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString(); PLOG(plog::info) << "OS: " << QSysInfo::prettyProductName().toStdString(); PLOG(plog::info) << "Command: " << QCoreApplication::arguments().join(" ").toStdString(); PLOG(plog::info) << "Version: " << QCoreApplication::applicationVersion().toStdString(); PLOG(plog::info) << "======================================"; PLOG(plog::info) << ""; dynamicAppender.removeAppender(&startupAppender); dynamicAppender.addAppender(&normalAppender); PLOG(plog::info)<<"Normal mesage";
The text was updated successfully, but these errors were encountered:
I guess if you're on Windows you need to close a file handle in the startupAppender. Here is the sample code:
startupAppender
#include <plog/Log.h> #include <plog/Initializers/RollingFileInitializer.h> #include <plog/Appenders/DynamicAppender.h> #include <plog/Formatters/MessageOnlyFormatter.h> int main() { const char logFileName[] = "mylog.log"; const int logMaxSize = 10000000; const int logMaxCount = 3; static plog::DynamicAppender dynamicAppender; static plog::RollingFileAppender<plog::MessageOnlyFormatter> startupAppender(logFileName, logMaxSize, logMaxCount); static plog::RollingFileAppender<plog::TxtFormatter> normalAppender(logFileName, logMaxSize, logMaxCount); dynamicAppender.addAppender(&startupAppender); plog::init(plog::info, &dynamicAppender); PLOG(plog::info) << ""; PLOG(plog::info) << ""; PLOG(plog::info) << "======================================"; PLOG(plog::info) << "Start time: "; PLOG(plog::info) << "OS: "; PLOG(plog::info) << "Command: "; PLOG(plog::info) << "Version: "; PLOG(plog::info) << "======================================"; PLOG(plog::info) << ""; dynamicAppender.removeAppender(&startupAppender); startupAppender.setFileName(""); // set a new file name to close a file handle for the original file name dynamicAppender.addAppender(&normalAppender); PLOG(plog::info)<< "Normal mesage"; return 0; }
Sorry, something went wrong.
Note startupAppender.setFileName(""); part.
startupAppender.setFileName("");
The resulting log file is:
====================================== Start time: OS: Command: Version: ====================================== 2024-05-13 19:34:12.022 INFO [45812] [main@38] Normal mesage
SergiusTheBest
No branches or pull requests
I want use MessageOnlyFormatter first, then switch to TxtFormatter, but following code is not working
The text was updated successfully, but these errors were encountered: