Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

SyslogTarget.cc

Go to the documentation of this file.
00001 // $Id: SyslogTarget.cc 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "SyslogTarget.hh"
00027 //#include "SyslogTarget.ih"
00028 
00029 // Custom includes
00030 #include <senf/Utils/Console/ParsedCommand.hh>
00031 #include <senf/Utils/Console/Traits.hh>
00032 #include <senf/Utils/Console/ScopedDirectory.hh>
00033 
00034 //#include "SyslogTarget.mpp"
00035 #define prefix_
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 int const senf::log::SyslogTarget::LEVELMAP[8] = {
00039     0, LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_CRIT, LOG_EMERG, 0 };
00040 
00041 prefix_ void senf::log::SyslogTarget::v_write(time_type timestamp, std::string const & stream,
00042                                               std::string const & area, unsigned level,
00043                                               std::string const & message)
00044 {
00045     if (area != "senf::log::DefaultArea")
00046         syslog(facility_ | LEVELMAP[level], "[%s] %s", area.c_str(), message.c_str());
00047     else
00048         syslog(facility_ | LEVELMAP[level], "%s", message.c_str());
00049 }
00050 
00051 namespace senf {
00052 namespace log {
00053 
00054     SENF_CONSOLE_REGISTER_ENUM_MEMBER(SyslogTarget, LogFacility,
00055                                       (AUTHPRIV)(CRON)(DAEMON)(FTP)(KERN)(LPR)(MAIL)(NEWS)(SYSLOG)
00056                                       (USER)(UUCP)(LOCAL0)(LOCAL1)(LOCAL2)(LOCAL3)(LOCAL4)(LOCAL5)
00057                                       (LOCAL6)(LOCAL7));
00058 
00059 }}
00060 
00061 prefix_ senf::log::SyslogTarget::RegisterConsole::RegisterConsole()
00062 {
00063     namespace kw = console::kw;
00064     namespace fty = console::factory;
00065 
00066     detail::TargetRegistry::instance().consoleDir()
00067         .add("syslog-target",fty::Command(&RegisterConsole::create)
00068              .arg("facility", "syslog facility to send messages to. One of\n"
00069                   "                  AUTHPRIV CRON DAEMON FTP KERN LPR MAIL NEWS SYSLOG USER\n"
00070                   "                  UUCP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7",
00071                   kw::default_value = USER)
00072              .doc("Create new syslog target. Examples:\n"
00073                   "\n"
00074                   "Create new syslog target\n"
00075                   "    $ syslog-target\n"
00076                   "    <Directory '/sys/log/syslog'>\n"
00077                   "\n"
00078                   "In a configuration file, create new syslog target and set some parameters (If\n"
00079                   "written on one line, this works at the console too:\n"
00080                   "    /sys/log/syslog-target LOCAL2 {\n"
00081                   "        route (IMPORTANT);             # route all important messages\n"
00082                   "        timeFormat \"\";               # use non-formatted time format\n"
00083                   "        showArea false;                # don't show log area\n"
00084                   "    }\n") );
00085 }
00086 
00087 prefix_ boost::shared_ptr<senf::console::DirectoryNode>
00088 senf::log::SyslogTarget::RegisterConsole::create(LogFacility facility)
00089 {
00090     std::auto_ptr<Target> tp (new SyslogTarget(facility));
00091     Target & target (*tp.get());
00092     detail::TargetRegistry::instance().dynamicTarget(tp);
00093     return target.consoleDir().node().thisptr();
00094 }
00095 
00096 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00097 #undef prefix_
00098 //#include "SyslogTarget.mpp"
00099 
00100 
00101 // Local Variables:
00102 // mode: c++
00103 // fill-column: 100
00104 // comment-column: 40
00105 // c-file-style: "senf"
00106 // indent-tabs-mode: nil
00107 // ispell-local-dictionary: "american"
00108 // compile-command: "scons -u test"
00109 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research