Goby v2
logger_manipulators.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #include "logger_manipulators.h"
24 #include "flex_ostream.h"
25 #include "goby/common/time.h"
26 
27 std::ostream& operator<<(std::ostream& os, const Group& g)
28 {
29  os << "description: " << g.description() << std::endl;
30  os << "color: " << goby::common::TermColor::str_from_col(g.color());
31  return os;
32 }
33 
34 void GroupSetter::operator()(goby::common::FlexOstream& os) const { os.set_group(group_); }
35 
36 void GroupSetter::operator()(std::ostream& os) const
37 {
38  try
39  {
40  goby::common::FlexOstream& flex = dynamic_cast<goby::common::FlexOstream&>(os);
41  flex.set_group(group_);
42  }
43  catch (...)
44  {
45  basic_log_header(os, group_);
46  }
47 }
48 
49 std::ostream& basic_log_header(std::ostream& os, const std::string& group_name)
50 {
51  os << "[ " << goby::common::goby_time_as_string() << " ]";
52 
53  if (!group_name.empty())
54  os << " " << std::setfill(' ') << std::setw(15) << "{" << group_name << "}";
55 
56  os << ": ";
57  return os;
58 }
59 
61 {
62  os.set_unset_verbosity();
63  gs(os);
64  return (os);
65 }
Helper class for enabling the group(std::string) manipulator.
static std::string str_from_col(const Colors::Color &c)
String from color enumeration (e,g, red -> "red")
Definition: term_color.h:139
Forms the basis of the Goby logger: std::ostream derived class for holding the FlexOStreamBuf.
Definition: flex_ostream.h:43
std::string goby_time_as_string(const boost::posix_time::ptime &t=goby_time())
Simple string representation of goby_time()
Definition: time.h:150
goby::common::Colors::Color color() const
Color to use when displaying this group (for streams that support terminal escape codes only: std::co...
std::string description() const
Human readable description of this group.
Defines a group of messages to be sent to the Goby logger. For Verbosity == verbose streams...