source: CMT/v1r26/source/cmt_log.h

Last change on this file was 535, checked in by rybkin, 14 years ago

See C.L. 422

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#ifndef __cmt_log_h__
8#define __cmt_log_h__
9
10#include "cmt_string.h"
11
12class CmtLogEnd
13{
14public:
15};
16
17class CmtLogDummy
18{
19public:
20};
21
22class CmtLog
23{
24public:
25  CmtLog ();
26
27  static CmtLogEnd& end ();
28  CmtLog& operator << (const cmt_string& s);
29  CmtLog& operator << (const char* c);
30  CmtLog& operator << (int i);
31  CmtLog& operator << (double d);
32  CmtLog& operator << (void* p);
33  CmtLog& operator << (CmtLogEnd& end);
34  CmtLog& operator << (CmtLogDummy& dummy);
35
36private:
37  bool check ();
38};
39
40#define Log static CmtLog log_instance
41#define log_endl CmtLog::end ()
42#define log      if (Cmt::get_debug ()) log_instance << CmtMessage::prefix () + " (" << __FILE__ << ":" << __LINE__ << ") "
43//#define log      if (Cmt::get_debug ()) log_instance << "#CMT> (" << __FILE__ << "-" << __LINE__ << ") "
44#define log_cont if (Cmt::get_debug ()) log_instance
45
46
47enum CmtMsgLevel
48  {
49    Nil = 0,
50    Debug,
51    Verbose,
52    Info,
53    Warning,
54    Error,
55    Fatal
56  };
57
58class CmtMessage
59{
60public:
61  static cmt_string& prefix ();
62  static void set_prefix (const cmt_string& prefix);
63  static CmtMsgLevel& level ();
64  static void set_level (const CmtMsgLevel& level);
65  static bool active (const CmtMsgLevel& level);
66  static void verbose (const cmt_string& message);
67  static void info (const cmt_string& message);
68  static void warning (const cmt_string& message);
69  static void error (const cmt_string& message);
70  static void fatal (const cmt_string& message);
71
72private:
73  CmtMessage ();
74  static CmtMessage& instance ();
75  cmt_string m_prefix;
76  CmtMsgLevel m_level;
77};
78
79/**----------------------------------------------------------
80   The CmtMessage default constructor
81   Here are primarily constructed all default definitions
82*/
83inline CmtMessage::CmtMessage ()
84  : m_prefix ("#CMT--->"), m_level (Info)
85{ }
86
87/**----------------------------------------------------------
88   The CmtMessage singleton
89*/
90inline CmtMessage& CmtMessage::instance ()
91{
92  static CmtMessage me;
93  return me;
94}
95
96inline cmt_string& CmtMessage::prefix ()
97{
98  return instance ().m_prefix;
99}
100
101inline void CmtMessage::set_prefix (const cmt_string& prefix)
102{
103  instance ().m_prefix = prefix;
104}
105
106inline CmtMsgLevel& CmtMessage::level ()
107{
108  return instance ().m_level;
109}
110
111inline void CmtMessage::set_level (const CmtMsgLevel& level)
112{
113  instance ().m_level = level;
114}
115
116inline bool CmtMessage::active (const CmtMsgLevel& lvl)
117{
118  return level () <= lvl;
119}
120
121inline void CmtMessage::verbose (const cmt_string& message)
122{
123  if (active (Verbose))
124    cerr << prefix () << " Verbose: " << message << endl;
125}
126
127inline void CmtMessage::info (const cmt_string& message)
128{
129  if (active (Info))
130    cerr << prefix () << " Info: " << message << endl;
131}
132
133inline void CmtMessage::warning (const cmt_string& message)
134{
135  if (active (Warning))
136    cerr << prefix () << " Warning: " << message << endl;
137}
138
139inline void CmtMessage::error (const cmt_string& message)
140{
141  if (active (Error))
142    cerr << prefix () << " Error: " << message << endl;
143}
144
145inline void CmtMessage::fatal (const cmt_string& message)
146{
147  if (active (Fatal))
148    cerr << prefix () << " Fatal: " << message << endl;
149}
150#endif
Note: See TracBrowser for help on using the repository browser.