switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Logger / FileTarget.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief FileTarget public header */
30
31 #ifndef HH_SENF_Utils_Logger_FileTarget_
32 #define HH_SENF_Utils_Logger_FileTarget_ 1
33
34 // Custom includes
35 #include <boost/utility.hpp>
36 #include <boost/shared_ptr.hpp>
37 #include <fstream>
38 #include "IOStreamTarget.hh"
39
40 //#include "FileTarget.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 namespace senf {
44
45     namespace console { class DirectoryNode; }
46
47 namespace log {
48
49     /** \brief Log target writing to a %log file.
50
51         The FileTarget will save all %log messages in the given file. Messages will be appended at
52         the end of the file.
53
54         \code
55         senf::log::FileTarget target ("file.name");
56
57         // Route all messages to this file.
58         target.route();
59         \endcode
60
61         After %log files have been rotated, the reopen() member should be called to create a new %log
62         file.
63
64         \ingroup targets
65       */
66     class FileTarget
67         : private boost::base_from_member<std::ofstream>,
68           public IOStreamTarget
69     {
70         typedef boost::base_from_member<std::ofstream> ofstream_t;
71
72     public:
73         //-////////////////////////////////////////////////////////////////////////
74         ///\name Structors and default members
75         //\{
76
77         explicit FileTarget(std::string const & filename, std::string const & nodename = "");
78                                         ///< Construct FileTarget writing to \a file
79
80         //\}
81         //-////////////////////////////////////////////////////////////////////////
82
83         void reopen();                  ///< Reopen %log after log-file rotation
84         void reopen(std::string const & file);  ///< Reopen %log under a new name
85
86         std::string const & filename() const; ///< Return current log file name
87
88     private:
89         std::string file_;
90
91         struct RegisterConsole {
92             RegisterConsole();
93             static boost::shared_ptr<senf::console::DirectoryNode> create(
94                 std::string const & filename, std::string const & nodename);
95             static RegisterConsole instance;
96         };
97     };
98
99 }}
100
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 //#include "FileTarget.cci"
103 //#include "FileTarget.ct"
104 //#include "FileTarget.cti"
105 #endif
106
107 \f
108 // Local Variables:
109 // mode: c++
110 // fill-column: 100
111 // comment-column: 40
112 // c-file-style: "senf"
113 // indent-tabs-mode: nil
114 // ispell-local-dictionary: "american"
115 // compile-command: "scons -u test"
116 // End: