FileTarget.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_Logger_FileTarget_
18 #define HH_SENF_Utils_Logger_FileTarget_ 1
19 
20 // Custom includes
21 #include <fstream>
22 #include <boost/utility/base_from_member.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include "IOStreamTarget.hh"
25 
26 //#include "FileTarget.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 
31  namespace console { class DirectoryNode; }
32 
33 namespace log {
34 
52  class FileTarget
53  : private boost::base_from_member<std::ofstream>,
54  public IOStreamTarget
55  {
56  typedef boost::base_from_member<std::ofstream> ofstream_t;
57 
58  public:
59  //-////////////////////////////////////////////////////////////////////////
61  //\{
62 
63  explicit FileTarget(std::string const & filename, std::string const & nodename = "");
65 
66  //\}
67  //-////////////////////////////////////////////////////////////////////////
68 
69  void reopen();
70  void reopen(std::string const & file);
71 
72  std::string const & filename() const;
73 
74  private:
75  std::string file_;
76 
77  struct RegisterConsole {
78  RegisterConsole();
79  static boost::shared_ptr<senf::console::DirectoryNode> create(
80  std::string const & filename, std::string const & nodename);
81  static RegisterConsole instance;
82  };
83  };
84 
85 }}
86 
87 //-/////////////////////////////////////////////////////////////////////////////////////////////////
88 //#include "FileTarget.cci"
89 //#include "FileTarget.ct"
90 //#include "FileTarget.cti"
91 #endif
92 
93 
94 // Local Variables:
95 // mode: c++
96 // fill-column: 100
97 // comment-column: 40
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"
102 // End:
Write log messages to arbitrary std::ostream.
Log target writing to a log file.
Definition: FileTarget.hh:52
IOStreamTarget public header.