SyslogTarget.cc
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 #include "SyslogTarget.hh"
18 //#include "SyslogTarget.ih"
19 
20 // Custom includes
24 
25 //#include "SyslogTarget.mpp"
26 #define prefix_
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 int const senf::log::SyslogTarget::LEVELMAP[8] = {
30  0, LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_CRIT, LOG_EMERG, 0 };
31 
32 prefix_ void senf::log::SyslogTarget::v_write(time_type timestamp, std::string const & stream,
33  std::string const & area, unsigned level,
34  std::string const & message)
35 {
36  if (area != "senf::log::DefaultArea")
37  syslog(facility_ | LEVELMAP[level], "[%s] %s", area.c_str(), message.c_str());
38  else
39  syslog(facility_ | LEVELMAP[level], "%s", message.c_str());
40 }
41 
42 namespace senf {
43 namespace log {
44 
48  (LOCAL6)(LOCAL7));
49 
50 }}
51 
52 prefix_ senf::log::SyslogTarget::RegisterConsole::RegisterConsole()
53 {
54  namespace kw = console::kw;
55  namespace fty = console::factory;
56 
57  detail::TargetRegistry::instance().consoleDir()
58  .add("syslog-target",fty::Command(&RegisterConsole::create)
59  .arg("facility", "syslog facility to send messages to. One of\n"
60  " AUTHPRIV CRON DAEMON FTP KERN LPR MAIL NEWS SYSLOG USER\n"
61  " UUCP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7",
62  kw::default_value = USER)
63  .doc("Create new syslog target. Examples:\n"
64  "\n"
65  "Create new syslog target\n"
66  " $ syslog-target\n"
67  " <Directory '/sys/log/syslog'>\n"
68  "\n"
69  "In a configuration file, create new syslog target and set some parameters (If\n"
70  "written on one line, this works at the console too:\n"
71  " /sys/log/syslog-target LOCAL2 {\n"
72  " route (IMPORTANT); # route all important messages\n"
73  " timeFormat \"\"; # use non-formatted time format\n"
74  " showArea false; # don't show log area\n"
75  " }\n") );
76 }
77 
78 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
79 senf::log::SyslogTarget::RegisterConsole::create(LogFacility facility)
80 {
81  std::unique_ptr<Target> tp (new SyslogTarget(facility));
82  Target & target (*tp.get());
83  detail::TargetRegistry::instance().dynamicTarget(std::move(tp));
84  return target.consoleDir().node().thisptr();
85 }
86 
87 //-/////////////////////////////////////////////////////////////////////////////////////////////////
88 #undef prefix_
89 //#include "SyslogTarget.mpp"
90 
91 
92 // Local Variables:
93 // mode: c++
94 // fill-column: 100
95 // comment-column: 40
96 // c-file-style: "senf"
97 // indent-tabs-mode: nil
98 // ispell-local-dictionary: "american"
99 // compile-command: "scons -u test"
100 // End:
SyslogTarget(int facility=LOG_USER)
static int const LEVELMAP[8]
Definition: SyslogTarget.hh:89
SyslogTarget public header.
SENF_CONSOLE_REGISTER_ENUM_MEMBER(SyslogTarget, LogFacility,(AUTHPRIV)(CRON)(DAEMON)(FTP)(KERN)(LPR)(MAIL)(NEWS)(SYSLOG)(USER)(UUCP)(LOCAL0)(LOCAL1)(LOCAL2)(LOCAL3)(LOCAL4)(LOCAL5)(LOCAL6)(LOCAL7))
config::time_type time_type
Definition: TimeSource.hh:31
#define prefix_
Definition: SyslogTarget.cc:26
Target(std::string const &name)
Definition: Target.cc:45