Library of Assembled Shared Sources
logger.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44/** @class lass::io::Logger
45 * @brief Logs proxy streams to files.
46 * @date 2003
47 *
48 * Construct a logger and subscribe it to proxy streams so it can log them. All output to all proxy
49 * streams it is subscribed to will be saved to a file. Per proxy stream you can set a filter
50 * of what messages should be logged. The logger will unsubscribe itself on destruction.
51 *
52 * @code
53 * Logger logger("logfile.txt"); // construct logger\n
54 * logger.subscribe(proxyOut()); // subsribe to the proxy out stream.\n
55 * ...\n
56 * logger.unsubscribe(proxyOut());\n
57 * @endcode
58 */
59
60
61
62#ifndef LASS_GUARDIAN_OF_INCLUSION_IO_LOGGER_H
63#define LASS_GUARDIAN_OF_INCLUSION_IO_LOGGER_H
64
65#include "io_common.h"
66#include "proxy_o_stream.h"
67#include <fstream>
68
69#if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
70# pragma warning(push)
71# pragma warning(disable: 4251) // on STL in dll interface ...
72#endif
73
74
75namespace lass
76{
77namespace io
78{
79
81{
82public:
83
84 enum LogMode
85 {
86 lmAppend, // append to existing file
87 lmClear // on construction of the logger, clear the specified logfile
88 };
89
90 typedef ProxyOStream::TMask TMask;
91
92 //Logger();
93 Logger(const std::string& iLogFile, LogMode iLogMode = lmClear);
94 ~Logger();
95
96 void subscribeTo(ProxyOStream* iProxy, TMask iFilter = ProxyOStream::acceptAll);
97 void unsubscribeTo(ProxyOStream* iProxy);
98
99 TMask filter(ProxyOStream* iProxy);
100 void setFilter(ProxyOStream* iProxy, TMask iFilter);
101
102private:
103
104 typedef std::list<ProxyOStream*> TProxyList;
105
106 void openLog(const std::string& iLogFile, LogMode iLogMode = lmClear);
107
108 std::ofstream logFile_;
109 TProxyList proxyList_;
110
111};
112
113}
114
115}
116
117#if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
118# pragma warning(pop)
119#endif
120
121#endif
122
123// EOF
void setFilter(ProxyOStream *iProxy, TMask iFilter)
Set filter between proxy and logger.
Definition logger.cpp:121
void unsubscribeTo(ProxyOStream *iProxy)
Unsubscribe this logger to a proxy stream.
Definition logger.cpp:97
TMask filter(ProxyOStream *iProxy)
return the filter between proxy and logger
Definition logger.cpp:109
void subscribeTo(ProxyOStream *iProxy, TMask iFilter=ProxyOStream::acceptAll)
Subscribe this logger to a proxy stream and set the filter on it.
Definition logger.cpp:86
Logger(const std::string &iLogFile, LogMode iLogMode=lmClear)
Default constructor for the sake of static library.
Definition logger.cpp:62
A proxy output stream can distribute output to multiple destination streams.
#define LASS_DLL
DLL interface: import or export symbols?
streams, binary streams, vrmlstreams, ...
Library for Assembled Shared Sources.
Definition config.h:53