LogChannel.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: LogChannel.cpp 2942 2011-10-25 16:43:21Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Wei Yan - Chinese Academy of Sciences . 2011
00027 //
00028 //============================================================================
00029 
00030 #include "LogChannel.hpp"
00031 #include "NumberFormatter.hpp"
00032 
00033 namespace gpstk
00034 {
00035    using namespace std;
00036 
00037 
00038    std::string LogChannel::getLogText(const LogMessage& msg)
00039    {
00040       string text;
00041 
00042       DayTime time = msg.time;
00043       
00044       string::const_iterator it = pattern.begin();
00045       string::const_iterator end = pattern.end();
00046       while (it != end)
00047       {
00048          if (*it == '%')
00049          {
00050             if (++it != end)
00051             {
00052                switch (*it)
00053                {
00054                case 's': text.append(msg.source); break;
00055                case 't': text.append(msg.text); break;
00056                case 'l': NumberFormatter::append(text, (int) msg.level); break;
00057                case 'p': text.append(LogLevelName(msg.level)); break;
00058                case 'q': text += LogLevelName(msg.level).at(0); break;
00059                case 'U': text.append(msg.file); break;
00060                case 'u': NumberFormatter::append(text, msg.line); break;
00061                case 'd': NumberFormatter::append0(text, time.day(), 2); break;
00062                case 'e': NumberFormatter::append(text, time.day()); break;
00063                case 'f': NumberFormatter::append(text, time.day(), 2); break;
00064                case 'm': NumberFormatter::append0(text, time.month(), 2); break;
00065                case 'n': NumberFormatter::append(text, time.month()); break;
00066                case 'o': NumberFormatter::append(text, time.month(), 2); break;
00067                case 'y': NumberFormatter::append0(text, time.year() % 100, 2); break;
00068                case 'Y': NumberFormatter::append0(text, time.year(), 4); break;
00069                case 'H': NumberFormatter::append0(text, time.hour(), 2); break;
00070                case 'M': NumberFormatter::append0(text, time.minute(), 2); break;
00071                case 'S': NumberFormatter::append0(text, (int)time.second(), 2); break;
00072                default: text += *it;
00073                }
00074                ++it;
00075             }
00076          }
00077          else text += *it++;
00078       }
00079 
00080       return text; 
00081    }  // LogChannel::log(const LogMessage& msg)
00082    
00083 }   // End of namespace gpstk
00084 

Generated on Tue May 22 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1