Cat
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
MsgSvc Class Reference

#include <inc/MsgSvc.h>

Public Types

enum  MsgLevel {
  VERBOSE =-6, DEBUG, INFO, WARNING,
  ERR, FATAL, NONE
}
 
enum  MsgColor {
  BLUE, GREEN, WHITE, MAGENTA,
  YELLOW, RED, CYAN
}
 

Public Member Functions

 MsgSvc ()
 Standard constructor. More...
 
virtual ~MsgSvc ()
 Destructor. More...
 
void msgSvc (MsgSvc::MsgLevel, std::string, std::string call=std::string(""))
 
void setLineLength (int linelength)
 
void setCallSize (int callSize)
 

Protected Member Functions

void log (MsgSvc::MsgLevel, std::string, std::string)
 

Private Member Functions

std::string logtime ()
 

Private Attributes

std::vector< std::string > colors
 
int m_callSize
 
int m_lineLength
 
std::string m_origin
 

Detailed Description

Author
Frederic Machefert
Date
2009-12-30

Definition at line 21 of file MsgSvc.h.

Member Enumeration Documentation

◆ MsgColor

Enumerator
BLUE 
GREEN 
WHITE 
MAGENTA 
YELLOW 
RED 
CYAN 

Definition at line 25 of file MsgSvc.h.

◆ MsgLevel

Enumerator
VERBOSE 
DEBUG 
INFO 
WARNING 
ERR 
FATAL 
NONE 

Definition at line 24 of file MsgSvc.h.

Constructor & Destructor Documentation

◆ MsgSvc()

MsgSvc::MsgSvc ( )

Standard constructor.

Definition at line 19 of file MsgSvc.cpp.

References colors.

19  :
20  m_callSize (18),
21  m_lineLength (200){
22  colors.push_back(std::string("\033[94m"));
23  colors.push_back(std::string("\033[92m"));
24  colors.push_back(std::string("\033[93m"));
25  colors.push_back(std::string("\033[95m"));
26 // colors.push_back(std::string("\033[47m \033[7m \033[45m"));
27  colors.push_back(std::string("\033[33m"));
28  colors.push_back(std::string("\033[91m"));
29 // colors.push_back(std::string("\033[41m"));
30  colors.push_back(std::string("\033[0m"));
31 }
int m_callSize
Definition: MsgSvc.h:41
int m_lineLength
Definition: MsgSvc.h:42
std::vector< std::string > colors
Definition: MsgSvc.h:40

◆ ~MsgSvc()

MsgSvc::~MsgSvc ( )
virtual

Destructor.

Definition at line 36 of file MsgSvc.cpp.

36  {
37 }

Member Function Documentation

◆ log()

void MsgSvc::log ( MsgSvc::MsgLevel  level,
std::string  msg,
std::string  call 
)
protected

Definition at line 69 of file MsgSvc.cpp.

References application(), BLUE, colors, CYAN, DEBUG, ERR, FATAL, GREEN, INFO, logtime(), m_callSize, MAGENTA, RED, VERBOSE, WARNING, WHITE, and YELLOW.

Referenced by msgSvc(), and setCallSize().

71  {
72 
73  bool isFatal=false;
74 
75  //#ifndef WIN32
76  std::string output(colors[BLUE]);
77  output+=std::string(call,0,m_callSize);
78  //#else
79  // std::string output=std::string(call,0,m_callSize);
80  //#endif
81 
82 
83 
84  int clen=call.length();
85 
86  if (clen>0)
87  {
88  if (clen>m_callSize) output.replace(m_callSize+5-3,3,"...");
89  if (clen<m_callSize) output.insert (clen+5,m_callSize-clen,' ');
90  }
91 
92  std::string color;
93 
94  switch(level) {
95  case VERBOSE:
96 #ifndef WIN32
97  color=colors[BLUE];
98  output+=color;
99 #endif
100  output+=" VERBOSE ";
101  break;
102  case DEBUG:
103 #ifndef WIN32
104  color=colors[BLUE];
105  output+=color;
106 #endif
107  output+=" DEBUG ";
108  break;
109  case INFO:
110 #ifndef WIN32
111  color=colors[GREEN];
112  output+=color;
113 #endif
114  output+=" INFO ";
115  break;
116  case WARNING:
117 #ifndef WIN32
118  color=colors[YELLOW];
119  output+=color;
120 #endif
121  output+=" WARNING ";
122  break;
123  case ERR:
124 #ifndef WIN32
125  color=colors[MAGENTA];
126  output+=color;
127 #endif
128  output+=" ERROR ";
129  break;
130  case FATAL:
131 #ifndef WIN32
132  color=colors[RED];
133  output+=color;
134 #endif
135  output+=" FATAL ";
136  isFatal=true;
137  break;
138  default:
139 #ifndef WIN32
140  color = colors[CYAN];
141  output+=color;
142 #endif
143  output = call;
144  break;
145  }
146 #ifndef WIN32
147  output+=colors[WHITE];
148 #endif
149  output+=logtime();
150 #ifndef WIN32
151  output+=color;
152 #endif
153  output+=msg;
154 #ifndef WIN32
155  output+=colors[WHITE];
156 #endif
157  /*
158  int linereturn=output.length();
159 
160  while (linereturn>m_lineLength){
161  output.insert(m_lineLength,"\n");
162  output.insert(m_lineLength+1,9+m_callSize,' ');
163  linereturn-=m_lineLength;
164  }
165  */
166 
167  std::cout << output << std::endl;
168  (*application() -> options() -> stream ()) << output << std::endl; ;
169 
170  if (isFatal) {exit(0);}
171 }
int m_callSize
Definition: MsgSvc.h:41
Application * application()
Definition: Tools.cpp:42
std::vector< std::string > colors
Definition: MsgSvc.h:40
std::string logtime()
Definition: MsgSvc.cpp:54

◆ logtime()

std::string MsgSvc::logtime ( )
private

Definition at line 54 of file MsgSvc.cpp.

Referenced by log().

54  {
55  time_t rawtime;
56  struct tm * timeinfo;
57 
58  time ( &rawtime );
59  timeinfo = localtime ( &rawtime );
60  char* timechar = asctime (timeinfo) ;
61  std::string timing = std::string(timechar,24) + " ";
62 
63  return timing;
64 }

◆ msgSvc()

void MsgSvc::msgSvc ( MsgSvc::MsgLevel  level,
std::string  msg,
std::string  call = std::string("") 
)

Definition at line 42 of file MsgSvc.cpp.

References application(), log(), and Application::options().

Referenced by Object::debug(), var::debug(), DLLMgr::debug(), DLL::debug(), Object::error(), export_base(), Object::fatal(), var::fatal(), DLLMgr::fatal(), DLL::fatal(), Object::info(), var::info(), DLLMgr::info(), DLL::info(), Object::msg(), DLL::msg(), Object::msgSvc(), Options::print(), Object::verbose(), var::verbose(), DLLMgr::verbose(), DLL::verbose(), Object::warning(), var::warning(), DLLMgr::warning(), and DLL::warning().

44  {
45  Options *opt = application() ->options() ;
46  const int OUTLEVEL = opt -> logOutputLevel();
47  if (level<OUTLEVEL) return;
48  log ( level, msg, call);
49 }
Application * application()
Definition: Tools.cpp:42
Options * options()
Definition: Application.h:86
void log(MsgSvc::MsgLevel, std::string, std::string)
Definition: MsgSvc.cpp:69

◆ setCallSize()

void MsgSvc::setCallSize ( int  callSize)
inline

Definition at line 33 of file MsgSvc.h.

References log(), and m_callSize.

Referenced by export_base().

33 { m_callSize = callSize ; } //< Set Msg call field size
int m_callSize
Definition: MsgSvc.h:41

◆ setLineLength()

void MsgSvc::setLineLength ( int  linelength)
inline

Definition at line 32 of file MsgSvc.h.

References m_lineLength.

Referenced by export_base().

32 { m_lineLength = linelength ; } //< Set Msg line length
int m_lineLength
Definition: MsgSvc.h:42

Member Data Documentation

◆ colors

std::vector<std::string> MsgSvc::colors
private

Definition at line 40 of file MsgSvc.h.

Referenced by log(), and MsgSvc().

◆ m_callSize

int MsgSvc::m_callSize
private

Definition at line 41 of file MsgSvc.h.

Referenced by log(), and setCallSize().

◆ m_lineLength

int MsgSvc::m_lineLength
private

Definition at line 42 of file MsgSvc.h.

Referenced by setLineLength().

◆ m_origin

std::string MsgSvc::m_origin
private

Definition at line 45 of file MsgSvc.h.


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