LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
LogFormatter.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2016 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
32 #ifndef LSST_PEX_LOGFORMATTER_H
33 #define LSST_PEX_LOGFORMATTER_H
34 
35 #include <string>
36 #include <map>
37 #include <ostream>
38 
40 #include "boost/any.hpp"
41 
42 namespace lsst {
43 namespace pex {
44 namespace logging {
45 
46 // forward declaration
47 class LogRecord;
48 
74 class LogFormatter {
75 public:
76 
78 
79  LogFormatter(LogFormatter const& that) {}
80 
81  virtual ~LogFormatter();
82 
83  LogFormatter& operator=(LogFormatter const& that) { return *this; }
84 
91  virtual void write(std::ostream *strm, LogRecord const& rec) = 0;
92 
93 };
94 
103 class BriefFormatter : public LogFormatter {
104 public:
105 
109  explicit BriefFormatter(bool verbose=false)
110  : LogFormatter(), _doAll(verbose)
111  {}
112 
114  : LogFormatter(that), _doAll(that._doAll)
115  {}
116 
117  virtual ~BriefFormatter();
118 
120  if (this == &that) return *this;
121 
122  dynamic_cast<LogFormatter*>(this)->operator=(that);
123  _doAll = that._doAll;
124  return *this;
125  }
126 
133  bool isVerbose() { return _doAll; }
134 
142  void setVerbose(bool printAll) { _doAll = printAll; }
143 
149  virtual void write(std::ostream *strm, LogRecord const& rec);
150 
151 private:
152 
153  bool _doAll;
154 };
155 
163 public:
164 
168  explicit IndentedFormatter(bool verbose=false)
169  : BriefFormatter(verbose)
170  {}
171 
173  : BriefFormatter(that)
174  {}
175 
176  virtual ~IndentedFormatter();
177 
179  if (this == &that) return *this;
180 
181  dynamic_cast<BriefFormatter*>(this)->operator=(that);
182  return *this;
183  }
184 
190  virtual void write(std::ostream *strm, LogRecord const& rec);
191 };
192 
199 public:
200 
206  explicit NetLoggerFormatter(std::string const& valueDelim = defaultValDelim);
207 
209  : LogFormatter(that), _tplookup(), _midfix(that._midfix)
210  {
211  loadTypeLookup();
212  }
213 
214  virtual ~NetLoggerFormatter();
215 
217 
222  const std::string& getValueDelimiter() const { return _midfix; }
223 
229  virtual void write(std::ostream *strm, LogRecord const& rec);
230 
231  static const std::string defaultValDelim;
232 
233 private:
234  typedef std::map<std::string, char> TypeSymbolMap;
235  void loadTypeLookup();
236 
238  std::string _midfix;
239 };
240 
251 public:
252 
253  explicit PrependedFormatter(bool verbose=false)
254  : BriefFormatter(verbose)
255  {}
256 
258  : BriefFormatter(that)
259  {}
260 
261  virtual ~PrependedFormatter();
262 
264  if (this == &that) return *this;
265 
266  dynamic_cast<BriefFormatter*>(this)->operator=(that);
267  return *this;
268  }
269 
275  virtual void write(std::ostream *strm, LogRecord const& rec);
276 };
277 
278 
279 }}} // end lsst::pex::logging
280 
281 #endif // end LSST_PEX_LOGFORMATTER_H
PrependedFormatter(PrependedFormatter const &that)
Definition: LogFormatter.h:257
virtual void write(std::ostream *strm, LogRecord const &rec)
IndentedFormatter(bool verbose=false)
Definition: LogFormatter.h:168
BriefFormatter(BriefFormatter const &that)
Definition: LogFormatter.h:113
NetLoggerFormatter(NetLoggerFormatter const &that)
Definition: LogFormatter.h:208
PrependedFormatter & operator=(PrependedFormatter const &that)
Definition: LogFormatter.h:263
virtual void write(std::ostream *strm, LogRecord const &rec)=0
NetLoggerFormatter(std::string const &valueDelim=defaultValDelim)
std::map< std::string, char > TypeSymbolMap
Definition: LogFormatter.h:234
void setVerbose(bool printAll)
Definition: LogFormatter.h:142
a container for constructing a single Log record
Definition: LogRecord.h:100
static const std::string defaultValDelim
Definition: LogFormatter.h:231
a formatter that renders records in a netlogger-like format.
Definition: LogFormatter.h:198
virtual void write(std::ostream *strm, LogRecord const &rec)
Definition: LogFormatter.cc:68
LogFormatter(LogFormatter const &that)
Definition: LogFormatter.h:79
virtual void write(std::ostream *strm, LogRecord const &rec)
BriefFormatter & operator=(BriefFormatter const &that)
Definition: LogFormatter.h:119
NetLoggerFormatter & operator=(NetLoggerFormatter const &that)
LogFormatter & operator=(LogFormatter const &that)
Definition: LogFormatter.h:83
BriefFormatter(bool verbose=false)
Definition: LogFormatter.h:109
IndentedFormatter(IndentedFormatter const &that)
Definition: LogFormatter.h:172
virtual void write(std::ostream *strm, LogRecord const &rec)
PrependedFormatter(bool verbose=false)
Definition: LogFormatter.h:253
const std::string & getValueDelimiter() const
Definition: LogFormatter.h:222
Interface for PropertySet class.
a formatter that renders records in a brief format for screen display.
Definition: LogFormatter.h:103
a formatter that prepends some preamble properties with each log record to help disentangle the messa...
Definition: LogFormatter.h:250
IndentedFormatter & operator=(IndentedFormatter const &that)
Definition: LogFormatter.h:178
an abstract class for formatting log records into a text stream.
Definition: LogFormatter.h:74