LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotLogger.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 325 0.0 %
Date: 2025-08-21 08:01:32 Functions: 0 82 0.0 %

          Line data    Source code
       1             : //# PlotLogger.cc: Classes to perform various logging actions for the plotter.
       2             : //# Copyright (C) 2009
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id: $
      27             : #include <graphics/GenericPlotter/PlotLogger.h>
      28             : 
      29             : #include <casacore/casa/Logging/LogFilter.h>
      30             : #include <casacore/casa/Logging/LogSink.h>
      31             : #include <casacore/casa/Logging/StreamLogSink.h>
      32             : #include <graphics/GenericPlotter/Plotter.h>
      33             : 
      34             : #include <fstream>
      35             : #include <ctime>
      36             : 
      37             : using namespace std;
      38             : 
      39             : using namespace casacore;
      40             : namespace casa {
      41             : 
      42             : ////////////////////////////////
      43             : // PLOTLOGMESSAGE DEFINITIONS //
      44             : ////////////////////////////////
      45             : 
      46             : // Static //
      47             : 
      48             : const int PlotLogMessage::DEFAULT_EVENT_TYPE = PlotLogger::MSG_INFO;
      49             : 
      50             : 
      51             : // Non-Static //
      52             : 
      53           0 : PlotLogMessage::PlotLogMessage(int eventType) :
      54             :         LogMessage(PlotLogger::EVENT_PRIORITY(eventType)),
      55           0 :         m_eventType(eventType) { }
      56             : 
      57           0 : PlotLogMessage::PlotLogMessage(const String& origin1, const String& origin2,
      58           0 :         int eventType) :
      59           0 :         LogMessage(LogOrigin(origin1, origin2),
      60             :                    PlotLogger::EVENT_PRIORITY(eventType)),
      61           0 :         m_eventType(eventType) { }
      62             : 
      63           0 : PlotLogMessage::PlotLogMessage(const String& origin1, const String& origin2,
      64           0 :         const String& message, int eventType) :
      65           0 :         LogMessage(message, LogOrigin(origin1, origin2),
      66             :                    PlotLogger::EVENT_PRIORITY(eventType)),
      67           0 :         m_eventType(eventType) { }
      68             : 
      69           0 : PlotLogMessage::PlotLogMessage(const PlotLogMessage& copy) : LogMessage(copy),
      70           0 :         m_eventType(copy.eventType()) { }
      71             : 
      72           0 : PlotLogMessage::~PlotLogMessage() { }
      73             : 
      74           0 : int PlotLogMessage::eventType() const { return m_eventType; }
      75             : 
      76             : 
      77             : ////////////////////////////////////
      78             : // PLOTLOGMEASUREMENT DEFINITIONS //
      79             : ////////////////////////////////////
      80             : 
      81             : // Static //
      82             : 
      83             : const PlotLogMeasurement::TimeUnit PlotLogMeasurement::DEFAULT_TIME_UNIT =
      84             :     SECOND;
      85             : 
      86           0 : String PlotLogMeasurement::timeUnits(TimeUnit t) {
      87           0 :     switch(t) {
      88           0 :     case SECOND: return "seconds";
      89             :     
      90           0 :     default: return "";
      91             :     }
      92             : }
      93             : 
      94             : 
      95             : // Non-Static //
      96             : 
      97           0 : PlotLogMeasurement::PlotLogMeasurement(const String& origin1,
      98             :         const String& origin2, TimeUnit timeUnit,
      99           0 :         int eventType) : PlotLogMessage(origin1, origin2, eventType),
     100           0 :         m_time(-1), m_timeUnit(timeUnit){
     101           0 :     startMeasurement();
     102           0 : }
     103             : 
     104           0 : PlotLogMeasurement::PlotLogMeasurement(const PlotLogMeasurement& copy) :
     105           0 :         PlotLogMessage(copy), m_startTime(copy.m_startTime),
     106           0 :         m_time(copy.m_time),
     107           0 :         m_timeUnit(copy.m_timeUnit) { }
     108             : 
     109           0 : PlotLogMeasurement::~PlotLogMeasurement() { }
     110             : 
     111             : 
     112           0 : time_t PlotLogMeasurement::startTime() const { return m_startTime; }
     113           0 : double PlotLogMeasurement::time() const { return m_time; }
     114           0 : PlotLogMeasurement::TimeUnit PlotLogMeasurement::timeUnit() const {
     115           0 :     return m_timeUnit; }
     116             : 
     117           0 : void PlotLogMeasurement::startMeasurement() {
     118           0 :     m_startTime = std::time(NULL);
     119           0 : }
     120             : 
     121           0 : void PlotLogMeasurement::stopMeasurement() {
     122             :     // Get measurement values.
     123           0 :     time_t t = std::time(NULL);
     124           0 :     m_time = t - m_startTime;
     125             :     
     126             :     // Set string message.
     127           0 :     stringstream ss;
     128           0 :     ss << "END       Time: ";
     129           0 :     if(m_time >= 0) ss << "+" << m_time << " " << timeUnits(m_timeUnit);
     130           0 :     else ss << "unreported";
     131           0 :     ss << ".";
     132           0 :     message(ss.str(), true);
     133             : 
     134           0 :     startMeasurement();
     135           0 : }
     136             : 
     137             : 
     138             : ///////////////////////////////
     139             : // PLOTLOGLOCATE DEFINITIONS //
     140             : ///////////////////////////////
     141             : 
     142             : // Static //
     143             : 
     144           0 : PlotLogLocate PlotLogLocate::canvasLocate(PlotCanvas* canv,
     145             :         const PlotRegion& reg) {
     146           0 :     if(canv == NULL)
     147           0 :         return PlotLogLocate("PlotLogLocate", "canvasLocate", reg, NULL);
     148             :     
     149           0 :     return PlotLogLocate("PlotLogLocate","canvasLocate",reg,canv->locate(reg));
     150             : }
     151             : 
     152             : 
     153             : // Non-Static //
     154             : 
     155           0 : PlotLogLocate::PlotLogLocate(const String& origin1, const String& origin2,
     156             :         const PlotRegion& locateRegion,
     157             :         vector<vector<pair<unsigned int,unsigned int> > >* locatedIndices,
     158           0 :         int eventType, bool deleteIndicesOnDestruction) :
     159           0 :         PlotLogMessage(origin1, origin2, eventType), m_region(locateRegion),
     160           0 :         m_indices(locatedIndices), m_shouldDelete(deleteIndicesOnDestruction) {
     161             :     // Generate message.
     162           0 :     stringstream ss;
     163           0 :     unsigned int np = numSearchedPlots(), ni = numLocatedIndices();
     164           0 :     ss << "Locating indices with x in [" << m_region.left() << ", "
     165           0 :        << m_region.right() << "] and y in [" << m_region.bottom() << ", "
     166           0 :        << m_region.top() << ".  Searched " << np << " plots and found " << ni
     167           0 :        << " indices.";
     168           0 :     if(np > 0 && ni > 0) ss << '\n';
     169             :     
     170           0 :     bool first = true;
     171             :     unsigned int n, from, to;
     172           0 :     for(unsigned int i = 0; i < np; i++) {
     173           0 :         n = m_indices->at(i).size();
     174           0 :         if(n > 0) {
     175           0 :             if(!first) ss << '\n';
     176           0 :             first = false;
     177             :         }
     178           0 :         if(np > 0 && n > 0) ss << "Plot " << i << ": ";
     179           0 :         if(n > 0) ss << "[";
     180             :         
     181           0 :         for(unsigned int j = 0; j < n; ++j) {
     182           0 :             from = (*m_indices)[i][j].first;
     183           0 :             to = (*m_indices)[i][j].second;
     184           0 :             ss << from;
     185           0 :             if(to != from) ss << "-" << to;
     186           0 :             if(j < n - 1) ss << ", ";
     187             :         }
     188           0 :         if(n > 0) ss << "]";
     189             :     }
     190             :     
     191           0 :     message(ss.str(), true);
     192           0 : }
     193             : 
     194           0 : PlotLogLocate::PlotLogLocate(const PlotLogLocate& copy) : PlotLogMessage(copy),
     195           0 :         m_region(copy.locateRegion()), m_indices(copy.indices()),
     196           0 :         m_shouldDelete(copy.willDeleteIndices()) {
     197           0 :     const_cast<PlotLogLocate&>(copy).m_shouldDelete = false;
     198           0 : }
     199             : 
     200           0 : PlotLogLocate::~PlotLogLocate() {
     201           0 :     if(m_shouldDelete && m_indices != NULL) delete m_indices;
     202           0 : }
     203             : 
     204             : 
     205           0 : const PlotRegion& PlotLogLocate::locateRegion() const { return m_region; }
     206           0 : unsigned int PlotLogLocate::numLocatedIndices() const {
     207           0 :     if(m_indices == NULL) return 0;
     208           0 :     unsigned int n = 0;
     209           0 :     for(unsigned int i = 0; i < m_indices->size(); i++)
     210           0 :         for(unsigned int j = 0; j < m_indices->at(i).size(); j++)
     211           0 :             n += (*m_indices)[i][j].second - (*m_indices)[i][j].first + 1;
     212             : 
     213           0 :     return n;
     214             : }
     215             : 
     216           0 : unsigned int PlotLogLocate::numSearchedPlots() const {
     217           0 :     return (m_indices != NULL) ? m_indices->size() : 0; }
     218             : 
     219             : vector<vector<pair<unsigned int, unsigned int> > >*
     220           0 : PlotLogLocate::indices() const { return m_indices; }
     221             : 
     222             : vector<pair<unsigned int, unsigned int> >*
     223           0 : PlotLogLocate::plotIndices(unsigned int index) const {
     224           0 :     if(m_indices == NULL || index >= m_indices->size()) return NULL;
     225           0 :     else return &(*m_indices)[index];
     226             : }
     227             : 
     228           0 : bool PlotLogLocate::willDeleteIndices() const { return m_shouldDelete; }
     229             : 
     230             : 
     231             : ///////////////////////////////
     232             : // PLOTLOGMETHOD DEFINITIONS //
     233             : ///////////////////////////////
     234             : 
     235           0 : PlotLogMethod::PlotLogMethod(const String& className, const String& methodName,
     236           0 :         bool entering, const String& message, int eventType) :
     237           0 :         PlotLogMessage(className, methodName, eventType) {
     238           0 :     stringstream ss;
     239           0 :     if(entering) ss << "ENTERING.";
     240           0 :     else         ss << "EXITING. ";    
     241           0 :     if(!message.empty()) ss << "  " << message;
     242             :     
     243           0 :     PlotLogMessage::message(ss.str(), true);
     244           0 : }
     245             : 
     246           0 : PlotLogMethod::~PlotLogMethod() { }
     247             : 
     248             : 
     249             : ///////////////////////////////
     250             : // PLOTLOGOBJECT DEFINITIONS //
     251             : ///////////////////////////////
     252             : 
     253           0 : PlotLogObject::PlotLogObject(const String& className, void* address,
     254           0 :         bool creation, const String& message, int eventType) :
     255           0 :         PlotLogMessage(className, creation ? "alloc" : "dealloc", eventType) {
     256           0 :     stringstream ss;
     257           0 :     if(creation) ss << "Creating";
     258           0 :     else         ss << "Destroying";
     259           0 :     ss << " object at " << address << ".";    
     260           0 :     if(!message.empty()) ss << " " << message;
     261             :     
     262           0 :     PlotLogMessage::message(ss.str(), true);
     263           0 : }
     264             : 
     265           0 : PlotLogObject::~PlotLogObject() { }
     266             : 
     267             : 
     268             : //////////////////////////////////
     269             : // PLOTLOGGERFILTER DEFINITIONS //
     270             : //////////////////////////////////
     271             : 
     272           0 : PlotLoggerFilter::PlotLoggerFilter(int eventFlags,
     273           0 :         LogMessage::Priority minPriority) : m_eventFlags(eventFlags),
     274           0 :         m_minPriority(minPriority) { }
     275             : 
     276           0 : PlotLoggerFilter::~PlotLoggerFilter() { }
     277             : 
     278           0 : LogFilterInterface* PlotLoggerFilter::clone() const {
     279           0 :     return new PlotLoggerFilter(m_eventFlags, m_minPriority); }
     280             : 
     281           0 : Bool PlotLoggerFilter::pass(const LogMessage& message) const {
     282           0 :     if(message.priority() < m_minPriority) return false;
     283             :     
     284             :     /*
     285             :      * This causes an error when a non-PlotLogMessage is sent into the filter.
     286             :      * Cannot dynamic cast because LogMessage is not polymorphic. :(
     287             :      * Instead, moved this functionality to PlotLogger::postMessage()...
     288             :     try {
     289             :         int type = ((const PlotLogMessage&)message).eventType();
     290             :         return type <= 0 || m_eventFlags & type;
     291             :     } catch(...) { return true; }
     292             :     */
     293           0 :     return true;
     294             : }
     295             : 
     296           0 : int PlotLoggerFilter::eventFlags() const { return m_eventFlags; }
     297           0 : void PlotLoggerFilter::setEventFlags(int flags) { m_eventFlags = flags; }
     298             : 
     299           0 : LogMessage::Priority PlotLoggerFilter::minimumPriority() const {
     300           0 :     return m_minPriority; }
     301           0 : void PlotLoggerFilter::setMinimumPriority(LogMessage::Priority minPriority) {
     302           0 :     m_minPriority = minPriority; }
     303             : 
     304             : 
     305             : ////////////////////////////
     306             : // PLOTLOGGER DEFINITIONS //
     307             : ////////////////////////////
     308             : 
     309             : // Static //
     310             : 
     311           0 : int PlotLogger::ALL_EVENTS_FLAG() {
     312           0 :     int flag = 0;
     313           0 :     vector<int> v = ALL_EVENTS();
     314           0 :     for(unsigned int i = 0; i < v.size(); i++) flag |= v[i];
     315           0 :     return flag;
     316           0 : }
     317             : 
     318           0 : vector<int> PlotLogger::ALL_EVENTS() {
     319           0 :     vector<int> v(6 + EXTENDED_TYPES.size());
     320           0 :     v[0] = MSG_DEBUG; v[1] = DRAW_TOTAL;
     321           0 :     v[2] = DRAW_INDIVIDUAL; v[3] = METHODS_MAJOR;
     322           0 :     v[4] = OBJECTS_MAJOR; v[5] = EXPORT_TOTAL;
     323           0 :     for(unsigned int i = 6; i < v.size(); i++)
     324           0 :         v[i] = EXTENDED_TYPES[i - 6];
     325           0 :     return v;
     326             : }
     327             : 
     328           0 : int PlotLogger::REGISTER_EVENT_TYPE(const String& name,
     329             :         LogMessage::Priority priority) {
     330             :     static int value = EXPORT_TOTAL;
     331           0 :     value *= 2;
     332           0 :     EXTENDED_TYPES.push_back(value);
     333           0 :     EXTENDED_NAMES.push_back(name);
     334           0 :     SET_EVENT_PRIORITY(value, priority);
     335           0 :     return value;
     336             : }
     337             : 
     338           0 : void PlotLogger::UNREGISTER_EVENT_TYPE(int event) {
     339           0 :     for(unsigned int i = 0; i < EXTENDED_TYPES.size(); i++) {
     340           0 :         if(event == EXTENDED_TYPES[i]) {
     341           0 :             EXTENDED_TYPES.erase(EXTENDED_TYPES.begin() + i);
     342           0 :             EXTENDED_NAMES.erase(EXTENDED_NAMES.begin() + i);
     343             :         }
     344             :     }
     345           0 : }
     346             : 
     347           0 : void PlotLogger::UNREGISTER_EVENT_TYPE(const String& name) {
     348           0 :     for(unsigned int i = 0; i < EXTENDED_TYPES.size(); i++) {
     349           0 :         if(name == EXTENDED_NAMES[i]) {
     350           0 :             EXTENDED_TYPES.erase(EXTENDED_TYPES.begin() + i);
     351           0 :             EXTENDED_NAMES.erase(EXTENDED_NAMES.begin() + i);
     352             :         }
     353             :     }
     354           0 : }
     355             : 
     356           0 : vector<String> PlotLogger::EVENT_NAMES() {
     357           0 :     vector<int> e = ALL_EVENTS();
     358           0 :     vector<String> v(e.size());
     359           0 :     for(unsigned int i = 0; i < v.size(); i++) v[i] = EVENT(e[i]);
     360           0 :     return v;
     361           0 : }
     362             : 
     363           0 : String PlotLogger::EVENT(int type) {
     364           0 :     if(type == MSG_INFO)             return "MSG_INFO";
     365           0 :     else if(type == MSG_WARN)        return "MSG_WARN";
     366           0 :     else if(type == MSG_ERROR)       return "MSG_ERROR";
     367           0 :     else if(type == MSG_DEBUG)       return "MSG_DEBUG";
     368           0 :     else if(type == DRAW_TOTAL)      return "DRAW_TOTAL";
     369           0 :     else if(type == DRAW_INDIVIDUAL) return "DRAW_INDIVIDUAL";
     370           0 :     else if(type == METHODS_MAJOR)   return "METHODS_MAJOR";
     371           0 :     else if(type == OBJECTS_MAJOR)   return "OBJECTS_MAJOR";
     372           0 :     else if(type == EXPORT_TOTAL)    return "EXPORT_TOTAL";
     373             :     else {
     374           0 :         for(unsigned int i = 0; i < EXTENDED_TYPES.size(); i++)
     375           0 :             if(type == EXTENDED_TYPES[i]) return EXTENDED_NAMES[i];
     376           0 :         return "";
     377             :     }
     378             : }
     379             : 
     380           0 : int PlotLogger::EVENT(const String& name) {
     381           0 :     if(name == EVENT(MSG_INFO))             return MSG_INFO;
     382           0 :     else if(name == EVENT(MSG_WARN))        return MSG_WARN;
     383           0 :     else if(name == EVENT(MSG_ERROR))       return MSG_ERROR;
     384           0 :     else if(name == EVENT(MSG_DEBUG))       return MSG_DEBUG;
     385           0 :     else if(name == EVENT(DRAW_TOTAL))      return DRAW_TOTAL;
     386           0 :     else if(name == EVENT(DRAW_INDIVIDUAL)) return DRAW_INDIVIDUAL;
     387           0 :     else if(name == EVENT(METHODS_MAJOR))   return METHODS_MAJOR;
     388           0 :     else if(name == EVENT(OBJECTS_MAJOR))   return OBJECTS_MAJOR;
     389           0 :     else if(name == EVENT(EXPORT_TOTAL))    return EXPORT_TOTAL;
     390             :     else {
     391           0 :         for(unsigned int i = 0; i < EXTENDED_NAMES.size(); i++)
     392           0 :             if(name == EXTENDED_NAMES[i]) return EXTENDED_TYPES[i];
     393           0 :         return NO_EVENTS;
     394             :     }
     395             : }
     396             : 
     397           0 : int PlotLogger::FLAG_FROM_EVENTS(const vector<int>& events) {
     398           0 :     int flag = 0;
     399           0 :     for(unsigned int i = 0; i < events.size(); i++) flag |= events[i];
     400           0 :     return flag;
     401             : }
     402             : 
     403           0 : int PlotLogger::FLAG_FROM_EVENTS(const vector<String>& names) {
     404           0 :     int flag = 0;
     405           0 :     for(unsigned int i = 0; i < names.size(); i++) flag |= EVENT(names[i]);
     406           0 :     return flag;
     407             : }
     408             : 
     409           0 : int PlotLogger::FLAG_FROM_PRIORITY(LogMessage::Priority minPriority) {
     410           0 :     int flag = 0;
     411           0 :     vector<int> v = ALL_EVENTS();
     412           0 :     for(unsigned int i = 0; i < v.size(); i++)
     413           0 :         if(EVENT_PRIORITY(v[i]) >= minPriority) flag |= v[i];
     414           0 :     return flag;
     415           0 : }
     416             : 
     417           0 : LogMessage::Priority PlotLogger::EVENT_PRIORITY(int event) {
     418           0 :     if(EVENT_PRIORITIES.find(event) == EVENT_PRIORITIES.end()) {
     419           0 :         LogMessage::Priority p = LogMessage::NORMAL;
     420           0 :         if(event == MSG_DEBUG || event == METHODS_MAJOR ||
     421           0 :            event == OBJECTS_MAJOR)        p = LogMessage::DEBUGGING;
     422           0 :         else if(event == DRAW_INDIVIDUAL) p = LogMessage::NORMAL5;
     423           0 :         else if(event == MSG_WARN)        p = LogMessage::WARN;
     424           0 :         else if(event == MSG_ERROR)       p = LogMessage::SEVERE;
     425           0 :         EVENT_PRIORITIES[event] = p;
     426             :     }
     427           0 :     return EVENT_PRIORITIES[event];
     428             : }
     429             : 
     430           0 : void PlotLogger::SET_EVENT_PRIORITY(int event, LogMessage::Priority priority) {
     431           0 :     EVENT_PRIORITIES[event] = priority; }
     432             : 
     433             : 
     434             : // Subclass of LogFilterInterface that refuses all messages.  Used to disable
     435             : // the global log sink temporarily.
     436             : // <group>
     437             : class NullLogFilter : public LogFilterInterface {
     438             : public:
     439           0 :     NullLogFilter() { }
     440             :   NullLogFilter(const NullLogFilter& copy): 
     441             :     LogFilterInterface()
     442             :     { (void)copy; }
     443           0 :     ~NullLogFilter() { }
     444           0 :     LogFilterInterface* clone()   const { 
     445           0 :             return new NullLogFilter(); 
     446             :             }
     447           0 :     Bool pass(const LogMessage& message) const   {
     448             :             (void)message;
     449           0 :             return false; 
     450             :             }
     451             : };
     452             : // </group>
     453             : 
     454             : 
     455           0 : void PlotLogger::disableGlobalSink() {
     456           0 :     if(DISABLED_GLOBAL_FILTER == NULL) {
     457           0 :         DISABLED_GLOBAL_FILTER = LogSink::globalSink().filter().clone();
     458           0 :         LogSink::globalSink().filter(NullLogFilter());
     459             :     }
     460           0 : }
     461             : 
     462           0 : void PlotLogger::enableGlobalSink() {
     463           0 :     if(DISABLED_GLOBAL_FILTER != NULL) {
     464           0 :         LogSink::globalSink().filter(*DISABLED_GLOBAL_FILTER);
     465           0 :         delete DISABLED_GLOBAL_FILTER;
     466           0 :         DISABLED_GLOBAL_FILTER = NULL;
     467             :     }
     468           0 : }
     469             : 
     470             : 
     471             : vector<int> PlotLogger::EXTENDED_TYPES = vector<int>();
     472             : 
     473             : vector<String> PlotLogger::EXTENDED_NAMES = vector<String>();
     474             : 
     475             : map<int, LogMessage::Priority> PlotLogger::EVENT_PRIORITIES =
     476             :     map<int, LogMessage::Priority>();
     477             : 
     478             : LogFilterInterface* PlotLogger::DISABLED_GLOBAL_FILTER = NULL;
     479             : 
     480             : 
     481             : // Non-Static //
     482             : 
     483           0 : PlotLogger::PlotLogger(Plotter*, int filterEventFlags,
     484           0 :         LogMessage::Priority filterMinPriority) : 
     485           0 :         m_logger(&LogSink::globalSink(), false),
     486           0 :         m_filter(filterEventFlags, filterMinPriority) {
     487           0 :     m_logger->filter(m_filter);
     488           0 : }
     489             : 
     490           0 : PlotLogger::~PlotLogger() { }
     491             : 
     492           0 : CountedPtr<LogSinkInterface> PlotLogger::sink() { return m_logger; }
     493           0 : const CountedPtr<LogSinkInterface> PlotLogger::sink() const {
     494           0 :     return m_logger; }
     495             : 
     496           0 : LogSinkInterface* PlotLogger::localSinkCopy() const {
     497           0 :     if(m_loggerLocation.empty()) return &LogSink::globalSink();
     498           0 :     else if(m_logger.null()) return NULL;
     499             :     else {
     500           0 :         const StreamLogSink* s= dynamic_cast<const StreamLogSink*>(&*m_logger);
     501           0 :         if(s == NULL) return const_cast<LogSinkInterface*>(&*m_logger);
     502           0 :         else return new StreamLogSink(*s);
     503             :     }
     504             : }
     505             : 
     506           0 : const String& PlotLogger::sinkLocation() const { return m_loggerLocation; }
     507           0 : void PlotLogger::setSinkLocation(const String& logFile) {
     508           0 :     CountedPtr<LogSinkInterface> oldSink = m_logger;
     509             :     try {
     510           0 :         if(logFile.empty())
     511           0 :             m_logger = CountedPtr<LogSinkInterface>(&LogSink::globalSink(),
     512           0 :                        false);
     513             :         else
     514             :             m_logger = new StreamLogSink(LogMessage::NORMAL,
     515           0 :                        new ofstream(logFile.c_str(), ios::app), true);
     516           0 :         m_logger->filter(m_filter);
     517           0 :         m_loggerLocation = logFile;
     518           0 :     } catch(...) {
     519           0 :         m_logger = oldSink;
     520           0 :     }
     521           0 : }
     522             : 
     523             : 
     524           0 : LogMessage::Priority PlotLogger::filterMinPriority() const {
     525           0 :     return m_filter.minimumPriority(); }
     526           0 : void PlotLogger::setFilterMinPriority(PlotLogMessage::Priority minPriority) {
     527           0 :     if(minPriority != m_filter.minimumPriority()) {
     528           0 :         m_filter.setMinimumPriority(minPriority);
     529           0 :         if(!m_logger.null()) m_logger->filter(m_filter);
     530             :     }
     531           0 : }
     532             : 
     533           0 : bool PlotLogger::filterEventFlag(int flag) const {
     534           0 :     return flag <= 0 || flag & m_filter.eventFlags(); }
     535           0 : void PlotLogger::setFilterEventFlag(int flag, bool on) {
     536           0 :     int flags = m_filter.eventFlags();    
     537           0 :     if(on && !(flags & flag)) setFilterEventFlags(flags | flag);
     538           0 :     else if(!on && (flags & flag)) setFilterEventFlags(flags & ~flag);
     539           0 : }
     540             : 
     541           0 : int PlotLogger::filterEventFlags() const { return m_filter.eventFlags(); }
     542           0 : void PlotLogger::setFilterEventFlags(int flags) {
     543           0 :     if(flags != m_filter.eventFlags()) {
     544           0 :         m_filter.setEventFlags(flags);
     545           0 :         if(!m_logger.null()) m_logger->filter(m_filter);
     546             :     }
     547           0 : }
     548             : 
     549           0 : void PlotLogger::postMessage(const PlotLogMessage& message) {
     550             :     try {
     551           0 :         if(!m_logger.null()) {
     552             :             // Do events type check here.
     553           0 :             int type = message.eventType();
     554           0 :             if(type <= 0 || m_filter.eventFlags() & type)
     555           0 :                 m_logger->postLocally(message);
     556             :         }
     557           0 :     } catch(...) { }
     558           0 : }
     559             : 
     560           0 : void PlotLogger::postMessage(const String& origin1, const String& origin2,
     561             :         const String& message, int eventType) {
     562           0 :     postMessage(PlotLogMessage(origin1, origin2, message, eventType)); }
     563             : 
     564           0 : PlotLogMessage PlotLogger::markMeasurement(const String& origin1,
     565             :         const String& origin2, int eventType, bool postStartMessage) {
     566             :     PlotLogMessage startMessage(origin1, origin2,
     567           0 :             "START: ", eventType);
     568           0 :     if(postStartMessage) postMessage(startMessage);
     569           0 :     m_measurements.push_back(PlotLogMeasurement(origin1, origin2,
     570             :             PlotLogMeasurement::DEFAULT_TIME_UNIT, eventType));
     571           0 :     return startMessage;
     572           0 : }
     573             : 
     574           0 : PlotLogMeasurement PlotLogger::releaseMeasurement(bool postReleaseMessage) {
     575           0 :     if(m_measurements.size() == 0) // invalid
     576           0 :         return PlotLogMeasurement("PlotLogger", "releaseMeasurement");
     577             :     
     578             :     // Go through and update previous times.    
     579           0 :     PlotLogMeasurement m = m_measurements[m_measurements.size() - 1];
     580           0 :     m_measurements.erase(m_measurements.begin() + m_measurements.size() - 1);
     581           0 :     m.stopMeasurement();
     582           0 :     if(postReleaseMessage) postMessage(m);
     583             :     
     584           0 :     return m;
     585           0 : }
     586             : 
     587           0 : PlotLogLocate PlotLogger::locate(PlotCanvas* canvas, const PlotRegion& region,
     588             :             int eventType, bool postLocateMessage) {
     589           0 :     if(canvas == NULL) return PlotLogLocate("", "", region, NULL);
     590             :     
     591           0 :     vector<vector<pair<unsigned int, unsigned int> > >* res = canvas->locate(
     592             :             region);
     593           0 :     PlotLogLocate msg("PlotCanvas", "locate", region, res, eventType, false);
     594           0 :     if(postLocateMessage) postMessage(msg);
     595           0 :     return msg;
     596           0 : }
     597             : 
     598             : }

Generated by: LCOV version 1.16