Is there a way to configure some log level go to file and others to GUI? Topic is solved
Is there a way to configure some log level go to file and others to GUI?
For example, I want make verbose log go to file.log. And status, message, error go GUI.
No, I know everything.
Re: Is there a way to configure some log level go to file and others to GUI?
Hi,
Why not check the docs?
Use different classes derived from wxLog.
Thank you.
Why not check the docs?
Use different classes derived from wxLog.
Thank you.
Re: Is there a way to configure some log level go to file and others to GUI?
Hi ONEEYEMAN,
Thank you for the reply.
I have read the document, but it says:
"Only one log target is active at any moment"
So that it is impossible to create multiple target and using them at the same time.
I also tried subclass wxLog, and dispatch logs to wxLogGUI and wxLogStderr.
But nothing come after calling LogGUI's LogRecord(level, log, info), while LogStderr's LogRecord(level, log, info) works.
In wxApp:
Thank you for the reply.
I have read the document, but it says:
"Only one log target is active at any moment"
So that it is impossible to create multiple target and using them at the same time.
I also tried subclass wxLog, and dispatch logs to wxLogGUI and wxLogStderr.
But nothing come after calling LogGUI's LogRecord(level, log, info), while LogStderr's LogRecord(level, log, info) works.
Code: Select all
CommonLogTarget::CommonLogTarget(wxLog *pGuiLog) : m_pGuiLog(pGuiLog)
{
m_pLogFile = fopen("log.txt", "a+");
m_pFileLog = new wxLogStderr(m_pLogFile);
if(m_pGuiLog == NULL)
{
m_pGuiLog = new wxLogGui();
}
}
void CommonLogTarget::DoLogRecord(wxLogLevel level, const wxString &msg, const wxLogRecordInfo &info)
{
wxString log;
wxDateTime time(info.timestamp);
log.Printf("%s:%hu %s: %s", time.FormatISOCombined(' '), time.GetMillisecond(), info.func, msg);
if(level < wxLOG_Info)
{
m_pGuiLog->LogRecord(level, log, info);
}
m_pFileLog->LogRecord(level, log, info);
}
Code: Select all
wxLog::SetActiveTarget(new CommonLogTarget(new wxLogGui()));
wxLog::SetVerbose();
Last edited by JohnKnow on Sat Oct 16, 2021 9:59 am, edited 1 time in total.
No, I know everything.
Re: Is there a way to configure some log level go to file and others to GUI?
Hi PB,
Thank you for the reply.
All logs will go to both GUI and file by using wxLogChain.
I'm trying to make verbose log go to file and message,warning,error,status go GUI.
Thank you for the reply.
All logs will go to both GUI and file by using wxLogChain.
I'm trying to make verbose log go to file and message,warning,error,status go GUI.
No, I know everything.
Re: Is there a way to configure some log level go to file and others to GUI?
I found the reason.
It is because wxLogGui needs a flush to show logs.
Add below code to CommonLog then it works
It is because wxLogGui needs a flush to show logs.
Add below code to CommonLog then it works
Code: Select all
void CommonLogTarget::Flush()
{
m_pGuiLog->Flush();
m_pFileLog->Flush();
}
No, I know everything.
Re: Is there a way to configure some log level go to file and others to GUI?
Sorry, I misread your post. Adding a "filter" log target while using the default GUI target indeed seems impossible.
Re: Is there a way to configure some log level go to file and others to GUI?
Thank you for telling me filter, PB.
I think filter can achieve my precious goal.
Besides previous goal, I find subclassing wxlog can also change log format handy, I plan to keep current implementation.
I think filter can achieve my precious goal.
Besides previous goal, I find subclassing wxlog can also change log format handy, I plan to keep current implementation.
No, I know everything.