libcamgm
LogControl.hpp
Go to the documentation of this file.
1 
4 #ifndef CA_MGM_LOGCONTROL_H
5 #define CA_MGM_LOGCONTROL_H
6 
7 #include <iosfwd>
8 
9 #include <ca-mgm/Logger.hpp>
10 #include <ca-mgm/PtrTypes.hpp>
11 #include <ca-mgm/PathName.hpp>
12 
14 namespace ca_mgm
15 {
16 
18  namespace log
19  {
20 
26  struct LineWriter
27  {
28  virtual void writeOut( const std::string & /*formated_r*/ )
29  {}
30  virtual ~LineWriter()
31  {}
32  };
33 
35  struct StreamLineWriter : public LineWriter
36  {
37  StreamLineWriter( std::ostream & str_r ) : _str( &str_r ) {}
38 
39  virtual void writeOut( const std::string & formated_r )
40  { (*_str) << formated_r << std::endl; }
41 
42  protected:
43  StreamLineWriter() : _str( 0 ) {}
44  std::ostream *_str;
45  };
46 
49  {
51  };
52 
55  {
57  };
58 
64  {
65  FileLineWriter( const path::PathName & file_r, mode_t mode_r = 0 );
66  protected:
67  shared_ptr<void> _outs;
68  };
69 
71  } // namespace log
73 
74 
75 
77  //
78  // CLASS NAME : LogControl
79  //
84  class LogControl
85  {
86  friend std::ostream & operator<<( std::ostream & str, const LogControl & obj );
87 
88  public:
91  { return LogControl(); }
92 
93 
96 
103  {
104  virtual std::string format( const std::string & /*group_r*/,
105  logger::LogLevel /*level_r*/,
106  const char * /*file_r*/,
107  const char * /*func_r*/,
108  int /*line_r*/,
109  const std::string & /*message_r*/ );
110  virtual ~LineFormater() {}
111  };
112 
114  {
115  virtual std::string format( const std::string & group_r,
116  ca_mgm::logger::LogLevel level_r,
117  const char * ,
118  const char * ,
119  int ,
120  const std::string & message_r )
121  {
122  return ca_mgm::str::form( "%-5s %s - %s",
123  ca_mgm::logger::logLevelToString( level_r).c_str(),
124  group_r.c_str(), message_r.c_str());
125  }
126  virtual ~ShortLineFormater() {}
127  };
128 
129  public:
134  void setLineFormater( const shared_ptr<LineFormater> & formater_r );
135  void setShortLineFormater();
136 
137  public:
144  void logfile( const path::PathName & logfile_r );
145  void logfile( const path::PathName & logfile_r, mode_t mode_r );
146 
148  void logNothing();
149 
151  void logToStdErr();
152 
154  bool isEnabledFor( logger::LogLevel level_r );
155 
157  void setLogLevel( logger::LogLevel level_r );
158 
159  public:
161  shared_ptr<LineWriter> getLineWriter() const;
162 
168  void setLineWriter( const shared_ptr<LineWriter> & writer_r );
169 
170  private:
173  {}
174  };
176 
178  std::ostream & operator<<( std::ostream & str, const LogControl & obj );
179 
181 } // namespace ca_mgm
183 #endif // CA_MGM_LOGCONTROL_H
StreamLineWriter()
Definition: LogControl.hpp:43
LogControl()
Definition: LogControl.hpp:172
PathName manipulation class.
Definition: PathName.hpp:65
StreamLineWriter(std::ostream &str_r)
Definition: LogControl.hpp:37
LogLevel
Definition: Logger.hpp:78
virtual ~LineFormater()
Definition: LogControl.hpp:110
Definition: LogControl.hpp:63
shared_ptr< LineWriter > getLineWriter() const
virtual ~LineWriter()
Definition: LogControl.hpp:30
std::string logLevelToString(LogLevel level_r)
void setShortLineFormater()
bool isEnabledFor(logger::LogLevel level_r)
Definition: LogControl.hpp:113
void setLineFormater(const shared_ptr< LineFormater > &formater_r)
LiMaL path name manipulation utilities.
std::ostream & operator<<(std::ostream &ostr, const PathName &path)
friend std::ostream & operator<<(std::ostream &str, const LogControl &obj)
Definition: LogControl.hpp:84
virtual void writeOut(const std::string &)
Definition: LogControl.hpp:28
void setLogLevel(logger::LogLevel level_r)
shared_ptr< void > _outs
Definition: LogControl.hpp:67
Definition: LogControl.hpp:26
void logfile(const path::PathName &logfile_r)
FileLineWriter(const path::PathName &file_r, mode_t mode_r=0)
Definition: LogControl.hpp:35
virtual std::string format(const std::string &, logger::LogLevel, const char *, const char *, int, const std::string &)
Definition: LogControl.hpp:102
Definition: LogControl.hpp:54
log::LineWriter LineWriter
Definition: LogControl.hpp:95
std::ostream * _str
Definition: LogControl.hpp:44
virtual std::string format(const std::string &group_r, ca_mgm::logger::LogLevel level_r, const char *, const char *, int, const std::string &message_r)
Definition: LogControl.hpp:115
void setLineWriter(const shared_ptr< LineWriter > &writer_r)
Definition: LogControl.hpp:48
virtual ~ShortLineFormater()
Definition: LogControl.hpp:126
virtual void writeOut(const std::string &formated_r)
Definition: LogControl.hpp:39
std::string form(const char *format,...)
static LogControl instance()
Definition: LogControl.hpp:90
Definition: ByteBuffer.hpp:37