Scyllarus: C++ Hyperspectral Processing Library
Hyperspectral Image Processing Pipeline
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
logger.h
Go to the documentation of this file.
1 /****************************************************************************************
2  * SCYLLARUS : C++ HYPERSPECTRAL PROCESSING LIBRARY
3  * logger.h - Singleton Logger Class for library
4  *
5  * This computer code is subject to copyright:
6  * (c) National ICT Australia Limited (NICTA) 2013-2014 All Rights Reserved.
7  *
8  * Jeremy Oorloff, National ICT Australia (NICTA)
9  *
10  ***************************************************************************************/
11 
12 #ifndef LOGGER_H_
13 #define LOGGER_H_
14 
15 #include <iostream>
16 #include <sstream>
17 #include <vector>
18 #include <boost/format.hpp>
19 #include <boost/date_time/posix_time/posix_time.hpp>
20 
21 #include "scyllarus_types.h"
22 
23 
24 namespace scyl
25 {
26 
46 class logger
47 {
48 
49 public:
50 
51  typedef std::pair<std::string, std::string> logitem;
52  typedef std::vector<logitem> log;
53 
54  static logger * access();
55 
56  static std::string endl(){return "EOL";}
57 
58  static std::string timestamp();
59 
60  void set_print_output(bool in);
61  void set_bar(bool in);
62 
63  int percentage();
64  void set_percentage(int in);
65 
66  void check_abort();
67  void set_abort(bool in);
68  bool abort() const;
69 
72 
75  void save_logs(std::string filename);
76 
82  template <typename T>
83  scyl::logger & operator <<(T const & in)
84  {
85  #pragma omp critical (logger)
86  {
87  std::stringstream s;
88  s << in;
89  if (s.str().compare(scyl::logger::endl()) != 0)
90  {
91  m_ss << in;
92  } else
93  {
94  if (m_print)
95  {
96  std::cout << m_ss.str() << std::endl;
97  }
99  m_ss.str("");
100  }
101  }
102 
103  return *scyl::logger::access();
104  }
105 
106 
107 private:
108 
109  logger();
110  virtual ~logger();
111  void add_log(const std::string & timestamp, const std::string & in);
112 
113 
114  static logger * m_instance;
115 
116  std::stringstream m_ss;
117 
119 
121 
123 
124  bool m_print;
125 
126  bool m_abort;
127 
128  bool m_bar;
129 
130 };
131 
132 }
133 #endif /* LOGGER_H_ */
bool m_abort
Definition: logger.h:126
static std::string timestamp()
timestamp returns a string giving the current time, eg: "2013-Jan-01 12:12:12"
Definition: logger.cpp:198
void save_logs(std::string filename)
save_logs outputs the Loggers current log list to a file
Definition: logger.cpp:168
void set_print_output(bool in)
Toggle the console output of the Logger on or off.
Definition: logger.cpp:70
bool m_print
Definition: logger.h:124
void check_abort()
check_abort checks the status of the abort boolean. If it is set to false it does nothing...
Definition: logger.cpp:93
int m_percentage
Definition: logger.h:122
std::vector< logitem > log
Definition: logger.h:52
std::stringstream m_ss
Definition: logger.h:116
static std::string endl()
Definition: logger.h:56
logger()
Definition: logger.cpp:21
virtual ~logger()
Definition: logger.cpp:36
std::pair< std::string, std::string > logitem
Definition: logger.h:51
void set_abort(bool in)
set_abort sets the abort boolean. If set to true, the next time a processing function calls check_abo...
Definition: logger.cpp:109
scyl::logger::log take_logs()
take_logs returns the log vector, and clears the Logger's logs..
Definition: logger.cpp:155
static logger * access()
Logger access function is used to access the logger object.
Definition: logger.cpp:55
static logger * m_instance
Definition: logger.h:114
scyl::logger & operator<<(T const &in)
Pipe operator for the logger. Used to add logs.
Definition: logger.h:83
void set_stage(scyl::PIPELINE_STAGE in)
Set the pipeline stage.
Definition: logger.cpp:274
void add_log(const std::string &timestamp, const std::string &in)
add_log adds a log to the list of logs
Definition: logger.cpp:132
scyl::PIPELINE_STAGE m_stage
Definition: logger.h:118
scyl::logger::log get_logs()
get_logs returns the log vector
Definition: logger.cpp:144
scyl::logger::log m_log
Definition: logger.h:120
bool abort() const
Definition: logger.cpp:118
PIPELINE_STAGE
Definition: scyllarus_types.h:46
Logger is used to record messages and other processing details for the scyl library functions and acc...
Definition: logger.h:46
void set_percentage(int in)
Set the percentage.
Definition: logger.cpp:227
void set_bar(bool in)
Toggle the progress bar in the console on and off (may want to disable if you need higher levels of d...
Definition: logger.cpp:81
scyl::PIPELINE_STAGE stage()
stage returns the currently set pipeline stage.
Definition: logger.cpp:263
int percentage()
percentage returns the currently set percentage
Definition: logger.cpp:216
bool m_bar
Definition: logger.h:128