4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief FileTarget non-inline non-template implementation */
26 #include "FileTarget.hh"
27 //#include "FileTarget.ih"
30 #include "../Console/Console.hh"
32 //#include "FileTarget.mpp"
34 ///////////////////////////////cc.p////////////////////////////////////////
38 std::string quoteFilename(std::string filename)
40 for (std::string::iterator i (filename.begin()); i != filename.end(); ++i)
41 if (! senf::console::CommandParser::isWordChar(*i))
48 prefix_ senf::log::FileTarget::FileTarget(std::string const & file)
49 : ofstream_t(file.c_str(), std::ofstream::app),
50 IOStreamTarget(quoteFilename(file), ofstream_t::member),
53 consoleDir().add( "reopen", senf::membind(
54 static_cast<void (FileTarget::*)()>(&FileTarget::reopen),
56 .doc("Reopen logfile");
57 consoleDir().add("reopen", senf::membind(
58 static_cast<void (FileTarget::*)(std::string const &)>(&FileTarget::reopen),
60 .arg("filename","new filename")
61 .overloadDoc("Reopen logfile under new name");
64 prefix_ void senf::log::FileTarget::reopen()
66 ofstream_t::member.close();
67 ofstream_t::member.open(file_.c_str(), std::ofstream::app);
70 prefix_ void senf::log::FileTarget::reopen(std::string const & file)
74 // Rename console directory
75 console::DirectoryNode::ptr parent (consoleDir().node().parent());
77 parent->add(file, consoleDir().node().unlink());
80 prefix_ senf::log::FileTarget::RegisterConsole::RegisterConsole()
82 detail::TargetRegistry::instance().consoleDir().add("file-target",&RegisterConsole::create)
83 .arg("filename", "name of logfile")
84 .doc("Create new file target. Examples:\n"
86 "Create new file target '/var/log/example.log\n"
87 " $ file-target \"/var/log/example.log\"\n"
88 " <Directory '/sys/log/_var_log_example.log'>\n"
90 "In a configuration file, create new file target '/var/log/example.log' and set\n"
91 "some parameters (If written on one line, this works at the console too:\n"
92 " /sys/log/file-target \"/var/log/example.log\" {\n"
93 " route (IMPORTANT); # route all important messages\n"
94 " timeFormat \"\"; # use non-formatted time format\n"
95 " showArea false; # don't show log area\n"
99 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
100 senf::log::FileTarget::RegisterConsole::create(std::string const & filename)
102 std::auto_ptr<Target> tp (new FileTarget(filename));
103 Target & target (*tp.get());
104 detail::TargetRegistry::instance().dynamicTarget(tp);
105 return target.consoleDir().node().thisptr();
108 ///////////////////////////////cc.e////////////////////////////////////////
110 //#include "FileTarget.mpp"
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"