wxMaxima
Loading...
Searching...
No Matches
ErrorRedirector.h
Go to the documentation of this file.
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2014-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// SPDX-License-Identifier: GPL-2.0+
21
29#ifndef ERRORREDIRECTOR_H
30#define ERRORREDIRECTOR_H
31
32#include "precomp.h"
33#include <wx/log.h>
34#include <memory>
35
37class ErrorRedirector : public wxLog
38{
39public:
49 explicit ErrorRedirector(std::unique_ptr<wxLog> &&newLog);
50
52 virtual ~ErrorRedirector() override;
53
58 void Flush() override;
59
60 void DoLogRecord(wxLogLevel level,
61 const wxString& msg,
62 const wxLogRecordInfo& info) override;
63
69
71 void SetBatchMode(){m_batchMode = true;}
75 wxLog* GetOldLog() const;
76
85 void SetLog(std::unique_ptr<wxLog> &&logger);
87 void SetLogThis();
88
90 static void LogToStdErr(){m_logToStdErr = true;}
91
93 static bool LoggingToStdErr(){return m_logToStdErr;}
94
95protected:
97 wxLog *m_logNew = {};
99 wxLog *const m_logOld = {};
101 std::unique_ptr<wxLog> m_logOwned;
102
103 bool m_batchMode = false;
104
105private:
107 static bool m_logToStdErr;
108};
109
112{
113public:
116};
117
118#endif // ERRORREDIRECTOR_H
Redirect error messages (but not warnings) to a second target.
Definition: ErrorRedirector.h:38
void SetLog(std::unique_ptr< wxLog > &&logger)
Sets and takes ownership of another log target to use (may be nullptr).
Definition: ErrorRedirector.cpp:57
void Flush() override
This method is called from the idle loop.
Definition: ErrorRedirector.cpp:97
virtual ~ErrorRedirector() override
Restores the previous log target.
Definition: ErrorRedirector.cpp:51
static int m_messages_logPaneOnly
A variable used by the SuppressErrorDialogs class.
Definition: ErrorRedirector.h:44
void SetLogThis()
Sets ourseves as the log target.
Definition: ErrorRedirector.cpp:64
wxLog * GetOldLog() const
Returns the pointer to the previously active log target (which may be NULL).
void DetachOldLog()
Detaches the old log target so it won't be destroyed when the wxLogChain object is destroyed.
static bool LoggingToStdErr()
Output all log messages to stderr, too.
Definition: ErrorRedirector.h:93
static void LogToStdErr()
Output all log messages to stderr, too.
Definition: ErrorRedirector.h:90
void SetBatchMode()
Sets the "batch mode" flag that causes error messages to be output to stderr, as well.
Definition: ErrorRedirector.h:71
wxLog * m_logNew
the current log target - equal to m_logOwned or this
Definition: ErrorRedirector.h:97
wxLog *const m_logOld
the previous log target
Definition: ErrorRedirector.h:99
std::unique_ptr< wxLog > m_logOwned
the owned new log, of null if no log is owned
Definition: ErrorRedirector.h:101
If a variable of this class is alive errors won't create popup dialogues.
Definition: ErrorRedirector.h:112