wxMaxima
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 
37 class ErrorRedirector : public wxLog
38 {
39 public:
49  explicit ErrorRedirector(std::unique_ptr<wxLog> &&newLog);
50 
52  ~ErrorRedirector() override;
53 
58  void Flush() override;
59 
60  void DoLogRecord(wxLogLevel level,
61  const wxString& msg,
62  const wxLogRecordInfo& info) override;
63 
68  void DetachOldLog();
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 
95 protected:
97  wxLog *m_logNew = {};
99  wxLog *const m_logOld = {};
101  std::unique_ptr<wxLog> m_logOwned;
102 
103  bool m_batchMode = false;
104 
105 private:
107  static bool m_logToStdErr;
108 };
109 
112 {
113 public:
116 };
117 
118 #endif // ERRORREDIRECTOR_H
ErrorRedirector::m_logNew
wxLog * m_logNew
the current log target - equal to m_logOwned or this
Definition: ErrorRedirector.h:97
ErrorRedirector::Flush
void Flush() override
Definition: ErrorRedirector.cpp:103
SuppressErrorDialogs
If a variable of this class is alive errors won't create popup dialogues.
Definition: ErrorRedirector.h:111
ErrorRedirector
Redirect error messages (but not warnings) to a second target.
Definition: ErrorRedirector.h:37
ErrorRedirector::GetOldLog
wxLog * GetOldLog() const
ErrorRedirector::ErrorRedirector
ErrorRedirector(std::unique_ptr< wxLog > &&newLog)
Definition: ErrorRedirector.cpp:36
ErrorRedirector::SetLogThis
void SetLogThis()
Sets ourseves as the log target.
Definition: ErrorRedirector.cpp:62
ErrorRedirector::SetBatchMode
void SetBatchMode()
Sets the "batch mode" flag that causes error messages to be output to stderr, as well.
Definition: ErrorRedirector.h:71
ErrorRedirector::SetLog
void SetLog(std::unique_ptr< wxLog > &&logger)
Definition: ErrorRedirector.cpp:55
ErrorRedirector::m_logOwned
std::unique_ptr< wxLog > m_logOwned
the owned new log, of null if no log is owned
Definition: ErrorRedirector.h:101
ErrorRedirector::LoggingToStdErr
static bool LoggingToStdErr()
Output all log messages to stderr, too.
Definition: ErrorRedirector.h:93
ErrorRedirector::~ErrorRedirector
~ErrorRedirector() override
Restores the previous log target.
Definition: ErrorRedirector.cpp:49
ErrorRedirector::LogToStdErr
static void LogToStdErr()
Output all log messages to stderr, too.
Definition: ErrorRedirector.h:90
ErrorRedirector::m_messages_logPaneOnly
static int m_messages_logPaneOnly
Definition: ErrorRedirector.h:44
ErrorRedirector::m_logOld
wxLog *const m_logOld
the previous log target
Definition: ErrorRedirector.h:99
ErrorRedirector::DetachOldLog
void DetachOldLog()