24 #include <boost/filesystem/path.hpp> 25 #include <boost/version.hpp> 33 std::string getNodename(std::string
const & filename, std::string
const & nodename)
35 if (! nodename.empty())
37 #if BOOST_VERSION >= 104600 38 return boost::filesystem::path(filename).leaf().string();
40 return boost::filesystem::path(filename).leaf();
47 std::string
const & nodename)
48 : ofstream_t (filename.c_str(),
std::ofstream::app),
49 IOStreamTarget (getNodename(filename, nodename), ofstream_t::member),
52 namespace fty = console::factory;
54 if (! ofstream_t::member)
59 .doc(
"Reopen logfile") );
63 .arg(
"filename",
"new filename")
64 .overloadDoc(
"Reopen logfile under new name") );
66 .
add(
"file", fty::Variable(boost::cref(file_))
67 .doc(
"Show filename log messages are sent to") );
72 ofstream_t::member.close();
73 ofstream_t::member.open(file_.c_str(), std::ofstream::app);
83 parent->add(file,
consoleDir().node().unlink());
92 prefix_ senf::log::FileTarget::RegisterConsole::RegisterConsole()
94 namespace kw = console::kw;
95 namespace fty = console::factory;
97 detail::TargetRegistry::instance().consoleDir()
98 .add(
"file-target", fty::Command(&RegisterConsole::create)
99 .arg(
"filename",
"name of logfile")
100 .arg(
"nodename",
"name of node in console. Defaults to the files basename",
101 kw::default_value =
"")
102 .doc(
"Create new file target. Examples:\n" 104 "Create new file target '/var/log/example.log\n" 105 " $ file-target \"/var/log/example.log\"\n" 106 " <Directory '/sys/log/example.log'>\n" 108 "In a configuration file, create new file target '/var/log/example.log' and set\n" 109 "some parameters (If written on one line, this works at the console too:\n" 110 " /sys/log/file-target \"/var/log/example.log\" mainlog {\n" 111 " route (IMPORTANT); # route all important messages\n" 112 " timeFormat \"\"; # use non-formatted time format\n" 113 " showArea false; # don't show log area\n" 117 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
118 senf::log::FileTarget::RegisterConsole::create(std::string
const &
filename,
119 std::string
const & nodename)
122 Target & target (*tp.get());
123 detail::TargetRegistry::instance().dynamicTarget(std::move(tp));
FileTarget(std::string const &filename, std::string const &nodename="")
Construct FileTarget writing to file.
#define SENF_MEMBINDFNP(ret, cls, fn, args)
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
boost::shared_ptr< DirectoryNode > ptr
Write log messages to arbitrary std::ostream.
senf::console::ScopedDirectory & consoleDir()
Get console/config directory.
Log target writing to a log file.
FileTarget public header.
void reopen()
Reopen log after log-file rotation.
DirectoryNode & node() const
std::string const & filename() const
Return current log file name.
Logging target base class.
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)