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 LogFormat non-inline non-template implementation */
26 #include "LogFormat.hh"
27 //#include "LogFormat.ih"
33 #include <boost/date_time/posix_time/posix_time.hpp>
34 #include "../Scheduler/ClockService.hh"
36 //#include "LogFormat.mpp"
38 ///////////////////////////////cc.p////////////////////////////////////////
40 prefix_ senf::log::detail::LogFormat::LogFormat()
41 : tag_ (detail::getDefaultTag()), noformat_ (false), showTime_ (true),
42 showStream_ (false), showLevel_ (true), showArea_ (true), timeBase_ (-1)
44 std::locale const & loc (datestream_.getloc());
45 datestream_.imbue( std::locale(
46 loc, new boost::posix_time::time_facet("%Y-%m-%d %H:%M:%S.%f-0000")) );
49 prefix_ void senf::log::detail::LogFormat::timeFormat(std::string const & format)
56 std::locale const & loc (datestream_.getloc());
57 datestream_.imbue( std::locale(
58 loc, new boost::posix_time::time_facet(format.c_str())) );
62 prefix_ std::string senf::log::detail::LogFormat::prefix(time_type timestamp,
63 std::string const & stream,
64 std::string const & area,
71 if (timeBase_ == -1) timeBase_ = timestamp;
72 time_type delta (timestamp - timeBase_);
73 datestream_ << std::setfill('0') << std::setw(10)
74 << (delta / 1000000000ll) << '.'
75 << std::setfill('0') << std::setw(9)
76 << (delta % 1000000000ll);
79 datestream_ << senf::ClockService::abstime(timestamp);
83 datestream_ << tag_ << ": ";
85 datestream_ << '[' << stream << "] ";
87 datestream_ << '[' << LEVELNAMES[level] << "] ";
88 if (showArea_ && area != "senf::log::DefaultArea")
89 datestream_ << '[' << area << "] ";
91 return datestream_.str();
94 ///////////////////////////////////////////////////////////////////////////
96 prefix_ void senf::log::detail::quoteNonPrintable(std::string & s)
98 for (std::string::iterator i (s.begin()); i != s.end(); ++i)
99 if (*i < ' ' && *i != '\n')
103 prefix_ std::string senf::log::detail::getDefaultTag()
105 std::stringstream ss;
106 ss << ::program_invocation_short_name << '[' << ::getpid() << ']';
110 ///////////////////////////////cc.e////////////////////////////////////////
112 //#include "LogFormat.mpp"
118 // comment-column: 40
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"