Code::Blocks  SVN r11506
loggers.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  */
5 
6 #ifndef LOGGERS_H
7 #define LOGGERS_H
8 
9 #include "logger.h"
10 
11 #include <wx/colour.h>
12 #include <wx/font.h>
13 #include <wx/ffile.h>
14 #include <wx/textctrl.h>
15 
16 class wxListCtrl;
17 
18 // this file contains some kinds of loggers, they can save/record messages to different kind of devices
19 // all these specific logger classes are derived from Logger class defined in logger.h
20 
22 class DLLIMPORT NullLogger : public Logger
23 {
24 public:
25  void Append(cb_unused const wxString& msg, cb_unused Logger::level lv) override{};
26 };
27 
30 {
31 public:
32  void Append(const wxString& msg, Logger::level lv) override
33  {
34  fputs(wxSafeConvertWX2MB(msg.wc_str()), lv < error ? stdout : stderr);
35  fputs(::newline_string.mb_str(), lv < error ? stdout : stderr);
36  }
37 };
38 
40 class DLLIMPORT FileLogger : public Logger
41 {
42 protected:
44 public:
45  FileLogger(const wxString& filename) : f(filename, _T("wb")) {};
46  FileLogger() {};
47 
48  void Append(const wxString& msg, cb_unused Logger::level lv) override
49  {
50  fputs(wxSafeConvertWX2MB(msg.wc_str()), f.fp());
51  fputs(::newline_string.mb_str(), f.fp());
52  };
53 
54  virtual void Open(const wxString& filename) { Close(); f.Open(filename, _T("wb")); };
55  virtual void Close(){ if(f.IsOpened()) f.Close(); };
56 };
57 
59 struct CSS
60 {
71 
72  CSS();
73  operator wxString();
74 };
75 
78 {
80 public:
81  HTMLFileLogger(const wxString& filename);
82  void SetCSS(const CSS& in_css) { css = in_css; };
83 
84  void Append(const wxString& msg, Logger::level lv) override;
85  void Open(const wxString& filename) override;
86  void Close() override;
87 };
88 
91 {
92 protected:
93 
95  bool fixed;
96  wxTextAttr style[num_levels];
97 
98 public:
99  TextCtrlLogger(bool fixedPitchFont = false);
100  ~TextCtrlLogger() override;
101 
102  void CopyContentsToClipboard(bool selectionOnly = false) override;
103  void UpdateSettings() override;
104  void Append(const wxString& msg, Logger::level lv = info) override;
105  void Clear() override;
106  wxWindow* CreateControl(wxWindow* parent) override;
107  bool GetWrapMode() const override;
108  virtual void ToggleWrapMode();
109  bool HasFeature(Feature::Enum feature) const override;
110 };
111 
114 {
115 public:
116  void Append(const wxString& msg, Logger::level lv = info) override;
117 };
118 
121 {
122 protected:
123 
125  bool fixed;
128 
129  struct ListStyles
130  {
133  };
134  ListStyles style[num_levels];
135 
136  wxString GetItemAsText(long item) const;
137 public:
138 
139  ListCtrlLogger(const wxArrayString& titles, const wxArrayInt& widths, bool fixedPitchFont = false);
140  ~ListCtrlLogger() override;
141 
142  void CopyContentsToClipboard(bool selectionOnly = false) override;
143  void UpdateSettings() override;
144  void Append(const wxString& msg, Logger::level lv = info) override;
145  virtual void Append(const wxArrayString& colValues, Logger::level lv = info, int autoSize = -1);
146  virtual size_t GetItemsCount() const;
147  void Clear() override;
148  wxWindow* CreateControl(wxWindow* parent) override;
149  bool HasFeature(Feature::Enum feature) const override;
150  virtual void AutoFitColumns(int column);
151 };
152 
153 #endif // LOGGERS_H
FileLogger(const wxString &filename)
Definition: loggers.h:45
wxArrayString titles
Definition: loggers.h:126
bool Close()
void Append(cb_unused const wxString &msg, cb_unused Logger::level lv) override
Definition: loggers.h:25
bool IsOpened() const
wxString spacer
Definition: loggers.h:69
a logger which prints messages to a wxListCtrl
Definition: loggers.h:120
a logger simply does nothing
Definition: loggers.h:22
wxString failure
Definition: loggers.h:67
#define _T(string)
Cascading Style Sheets class for HTML logger.
Definition: loggers.h:59
The base class for all kinds of loggers, see loggers.h for its derived classes.
Definition: logger.h:23
wxString critical
Definition: loggers.h:66
virtual void Close()
Definition: loggers.h:55
wxString asterisk
Definition: loggers.h:70
bool Open(const wxString &filename, const wxString &mode="r")
virtual void Open(const wxString &filename)
Definition: loggers.h:54
FileLogger()
Definition: loggers.h:46
#define DLLIMPORT
Definition: settings.h:16
void SetCSS(const CSS &in_css)
Definition: loggers.h:82
void Append(const wxString &msg, cb_unused Logger::level lv) override
Definition: loggers.h:48
an extended logger from TextCtrlLogger, since it add time stamps for each log message ...
Definition: loggers.h:113
wxString success
Definition: loggers.h:64
wxString info
Definition: loggers.h:62
a logger which prints messages to a wxTextCtrl
Definition: loggers.h:90
a logger which prints messages to the standard console IO
Definition: loggers.h:29
wxString pagetitle
Definition: loggers.h:68
wxTextCtrl * control
Definition: loggers.h:94
const wchar_t * wc_str() const
wxListCtrl * control
Definition: loggers.h:124
wxArray< int > wxArrayInt
a logger which prints messages to a file
Definition: loggers.h:40
level
Definition: logger.h:37
wxArrayInt widths
Definition: loggers.h:127
wxString warning
Definition: loggers.h:63
FILE * fp() const
a logger which prints messages to an HTML file
Definition: loggers.h:77
wxString error
Definition: loggers.h:65
bool fixed
Definition: loggers.h:95
wxFFile f
Definition: loggers.h:43
wxString caption
Definition: loggers.h:61
void Append(const wxString &msg, Logger::level lv) override
Definition: loggers.h:32