X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FIOStreamTarget.cc;h=487e508ca01a071377de1138144498f752d34cac;hb=456ee576285b76aa46240f8001f426757810dcc1;hp=f70fdd770119f0ff1f5da872c1665baea4a137f2;hpb=ae06fe86f16fdabb7ffb219d255444d2eb4f4f79;p=senf.git diff --git a/Utils/Logger/IOStreamTarget.cc b/Utils/Logger/IOStreamTarget.cc index f70fdd7..487e508 100644 --- a/Utils/Logger/IOStreamTarget.cc +++ b/Utils/Logger/IOStreamTarget.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer NETwork research (NET) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -28,6 +28,9 @@ // Custom includes #include +#include +#include +#include //#include "IOStreamTarget.mpp" #define prefix_ @@ -36,26 +39,46 @@ /////////////////////////////////////////////////////////////////////////// // senf::log::IOStreamTarget +const char * const senf::log::IOStreamTarget::LEVELNAMES_[8] = { + "NONE", "VERBOSE", "NOTICE", "MESSAGE", "IMPORTANT", "CRITICAL", "FATAL", "DISABLED" }; + prefix_ senf::log::IOStreamTarget::IOStreamTarget(std::ostream & os) : stream_(os) { std::locale const & loc (stream_.getloc()); if (!std::has_facet(loc)) - stream_.imbue( std::locale(loc, new boost::posix_time::time_facet("%Y-%m-%d %H:%M:%S.%f-0000")) ); + stream_.imbue( std::locale( + loc, new boost::posix_time::time_facet("%Y-%m-%d %H:%M:%S.%f-0000")) ); } //////////////////////////////////////// // private members -prefix_ void senf::log::IOStreamTarget::v_write(boost::posix_time::ptime timestamp, +prefix_ void senf::log::IOStreamTarget::v_write(time_type timestamp, std::string const & stream, std::string const & area, unsigned level, std::string const & message) { - stream_ << timestamp << " "; - if (! area.empty()) - stream_ << "[" << area << "] "; - stream_ << message << std::endl; + std::string m (boost::trim_right_copy(message)); + + typedef boost::char_separator Separator; + typedef boost::tokenizer Tokenizer; + Separator separator ("\n"); + Tokenizer tokenizer (m, separator); + Tokenizer::iterator i (tokenizer.begin()); + Tokenizer::iterator const i_end (tokenizer.end()); + + char sep (' '); + + for (; i != i_end; ++i) { + stream_ << timestamp << sep; + stream_ << "[" << LEVELNAMES_[level] << "]"; + if (area != "senf::log::DefaultArea") + stream_ << "[" << area << "]"; + stream_ << " " << *i << "\n"; + sep = '-'; + } + stream_ << std::flush; } ///////////////////////////////cc.e////////////////////////////////////////