Skip to content
New issue

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

Logging to file and console at the same time #246

Open
hirenpatel1207 opened this issue Apr 4, 2023 · 1 comment
Open

Logging to file and console at the same time #246

hirenpatel1207 opened this issue Apr 4, 2023 · 1 comment
Labels

Comments

@hirenpatel1207
Copy link

The logger works nicely for recording to a file.
But is it possible to print the output (logs), on the console at the same time too?

@SergiusTheBest
Copy link
Owner

For that you need to create several appenders:

#include <plog/Log.h>
#include <plog/Init.h>
#include <plog/Formatters/CsvFormatter.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Appenders/ConsoleAppender.h>
#include <plog/Appenders/RollingFileAppender.h>
int main()
{
static plog::RollingFileAppender<plog::CsvFormatter> fileAppender("MultiAppender.csv", 8000, 3); // Create the 1st appender.
static plog::ConsoleAppender<plog::TxtFormatter> consoleAppender; // Create the 2nd appender.
plog::init(plog::debug, &fileAppender).addAppender(&consoleAppender); // Initialize the logger with the both appenders.
// A bunch of log lines that goes to the both appenders: to the file and to the console.
for (int i = 0; i < 100; ++i)
{
PLOG_INFO << "i: " << i;
}
return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants