Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
util/liblogger/flex_ostream.cpp
00001 // copyright 2009 t. schneider tes@mit.edu
00002 //
00003 // this file is part of flex-ostream, a terminal display library
00004 // that provides an ostream with both terminal display and file logging
00005 //
00006 // This program is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This software is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #include "flex_ostream.h"
00020 #include "logger_manipulators.h"
00021 
00022 boost::shared_ptr<goby::util::FlexOstream> goby::util::FlexOstream::inst_;
00023 
00024 goby::util::FlexOstream& goby::util::glogger(logger_lock::LockAction lock_action /*= none*/)
00025 {    
00026     if(!FlexOstream::inst_) FlexOstream::inst_.reset(new FlexOstream());
00027     
00028     if(lock_action == logger_lock::lock)
00029     {
00030         goby::util::Logger::mutex.lock(); 
00031     }
00032 
00033     return(*FlexOstream::inst_);
00034 }
00035 
00036 void goby::util::FlexOstream::add_group(const std::string& name,
00037                                         Colors::Color color /*= Colors::nocolor*/,
00038                                         const std::string& description /*= ""*/)
00039 {
00040 
00041     if(description.empty())
00042     {
00043         Group ng(name, name, color);
00044         sb_.add_group(name, ng);
00045     }
00046     else
00047     {
00048         Group ng(name, description, color);
00049         sb_.add_group(name, ng);
00050     }
00051     
00052     
00053     *this << "Adding FlexOstream group: " << sb_.color2esc_code(color) << name
00054           << sb_.color2esc_code(Colors::nocolor) << " (" << description << ")" << std::endl;
00055 }
00056 
00057 
00058 std::ostream& goby::util::FlexOstream::operator<<(std::ostream& (*pf) (std::ostream&))
00059 {
00060     if(pf == die)   sb_.set_die_flag(true);
00061     if(pf == debug) sb_.set_debug_flag(true);
00062     if(pf == warn)  sb_.set_warn_flag(true);
00063 
00064     return std::ostream::operator<<(pf);
00065 }            
00066 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends