Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Public Member Functions | List of all members
auryn::Logger Class Reference

A generic logger class that logs to screen and a log-file. More...

#include <Logger.h>

Public Member Functions

 Logger (std::string filename, int rank, LogMessageType console=PROGRESS, LogMessageType file=NOTIFICATION)
 
virtual ~Logger ()
 
void msg (std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
 
void info (std::string text)
 
void progress (std::string text)
 
void warning (std::string text)
 
void error (std::string text)
 
void verbose (std::string text, bool global=false, int line=-1, std::string srcfile="")
 
void debug (std::string text, bool global=false, int line=-1, std::string srcfile="")
 
void notification (std::string text)
 
void set_rank (int rank)
 
void set_debugging_mode ()
 Turns on verbosity on all channels. More...
 
void set_console_loglevel (LogMessageType level=PROGRESS)
 Sets loglevel for console output. More...
 
void set_logfile_loglevel (LogMessageType level=NOTIFICATION)
 Sets loglevel for file output. More...
 
template<typename T >
void parameter (std::string name, T value)
 

Detailed Description

A generic logger class that logs to screen and a log-file.

Logs message to console and a log-file. What goes where can be adjusted by the LogMessageType.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( std::string  filename,
int  rank,
LogMessageType  console = PROGRESS,
LogMessageType  file = NOTIFICATION 
)
32 {
33  console_out = console;
34  file_out = file;
35  set_rank(rank);
36  fname = filename;
37 
38  outfile.open(fname.c_str(),std::ios::out);
39  if (!outfile) {
40  std::cerr << "Can't open output logger output file " << fname << std::endl;
41  throw AurynOpenFileException();
42  }
43 
44 
45  std::stringstream oss;
46  oss << "Logger started on Rank " << local_rank;
47  msg(oss.str(),NOTIFICATION);
48 }
Definition: Logger.h:41
Definition: auryn_definitions.h:208
void set_rank(int rank)
Definition: Logger.cpp:156
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ ~Logger()

Logger::~Logger ( )
virtual
51 {
52  std::stringstream oss;
53  oss << "Logger stopped";
54  msg(oss.str(),NOTIFICATION);
55  outfile.close();
56 }
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

Member Function Documentation

◆ debug()

void Logger::debug ( std::string  text,
bool  global = false,
int  line = -1,
std::string  srcfile = "" 
)
152 {
153  msg(text, VERBOSE, global, line, srcfile );
154 }
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ error()

void Logger::error ( std::string  text)
142 {
143  msg(text, ERROR);
144 }
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ info()

void Logger::info ( std::string  text)
127 {
128  msg(text, INFO);
129 }
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: Logger.h:41
Here is the call graph for this function:

◆ msg()

void Logger::msg ( std::string  text,
LogMessageType  type = NOTIFICATION,
bool  global = false,
int  line = -1,
std::string  srcfile = "" 
)
75 {
76  time_t rawtime;
77  struct tm * timeinfo;
78  time ( &rawtime );
79  timeinfo = localtime ( &rawtime );
80  char tbuffer [80];
81  strftime (tbuffer,80,"%x %X",timeinfo);
82 
83  std::stringstream oss;
84  oss << tbuffer << ":: ";
85  switch ( type ) {
86  case WARNING:
87  oss << "!! WARNING: ";
88  break;
89  case ERROR:
90  oss << "!! ERROR: ";
91  break;
92  default:
93  break;
94  }
95 
96  oss << text; // actual text output
97 
98  if ( line >= 0 ) {
99  oss << " @ line " << line << " in " << srcfile;
100  }
101 
102  if ( type >= console_out && ( !global || (global && local_rank == 0) ) ) {
103  if ( last_message != text ) {
104  if ( type >= AURYN_LOGGER_CERRLEVEL )
105  if ( global ) {
106  std::cerr << "(!!) " << text << std::endl;
107  } else {
108  std::cerr << "(!!) " << "on rank " << local_rank << ": " << text << std::endl;
109  }
110  else
111  std::cout << "(" << std::setw(2) << local_rank << ") " << text << std::endl;
112  }
113  }
114 
115  if ( type >= file_out)
116  outfile << oss.str() << std::endl;
117 
118  last_message = text;
119 }
#define AURYN_LOGGER_CERRLEVEL
Definition: Logger.h:36
Definition: Logger.h:41
Definition: Logger.h:41

◆ notification()

void Logger::notification ( std::string  text)
132 {
133  msg(text, NOTIFICATION);
134 }
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

◆ parameter()

template<typename T >
void auryn::Logger::parameter ( std::string  name,
value 
)
inline
91  {
92  std::stringstream oss;
93  oss << std::scientific << " Parameter " << name << "=" << value;
94  msg(oss.str(),SETTINGS,true);
95  }
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: Logger.h:41
Here is the call graph for this function:

◆ progress()

void Logger::progress ( std::string  text)
122 {
123  msg(text, PROGRESS, true);
124 }
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: Logger.h:41
Here is the call graph for this function:

◆ set_console_loglevel()

void Logger::set_console_loglevel ( LogMessageType  level = PROGRESS)

Sets loglevel for console output.

Parameters
levelThe log level
59 {
60  console_out = level;
61 }

◆ set_debugging_mode()

void Logger::set_debugging_mode ( )

Turns on verbosity on all channels.

69 {
72 }
void set_logfile_loglevel(LogMessageType level=NOTIFICATION)
Sets loglevel for file output.
Definition: Logger.cpp:63
void set_console_loglevel(LogMessageType level=PROGRESS)
Sets loglevel for console output.
Definition: Logger.cpp:58
Definition: Logger.h:41
Here is the call graph for this function:

◆ set_logfile_loglevel()

void Logger::set_logfile_loglevel ( LogMessageType  level = NOTIFICATION)

Sets loglevel for file output.

Parameters
levelThe log level
64 {
65  file_out = level;
66 }

◆ set_rank()

void Logger::set_rank ( int  rank)
157 {
158  local_rank = rank;
159 }

◆ verbose()

void Logger::verbose ( std::string  text,
bool  global = false,
int  line = -1,
std::string  srcfile = "" 
)
147 {
148  debug(text, global, line, srcfile );
149 }
void debug(std::string text, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:151
Here is the call graph for this function:

◆ warning()

void Logger::warning ( std::string  text)
137 {
138  msg(text, WARNING);
139 }
Definition: Logger.h:41
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Here is the call graph for this function:

The documentation for this class was generated from the following files: