AudioManager  7.6.6
Native Application Runtime Environment
CAmLog.h
Go to the documentation of this file.
1 
24 #ifndef CAMLOG_H_
25 #define CAMLOG_H_
26 
27 #include <iostream>
28 #include <iosfwd>
29 #include <stdio.h>
30 #include <stdexcept>
31 #include <fstream>
32 #include <stdlib.h>
33 #include <sstream>
34 #include <assert.h>
35 
43 #define DEFAULT_LOG_FOLDER "/tmp/"
44 #define DEFAULT_LOGFILE_PREFIX "am_dump_"
45 #define DEFAULT_LOGFILE_EXT ".log"
46 
47 #define DEL( aPointer ) delete aPointer, aPointer = NULL;
48 
49 /* */
50 typedef enum { eCAmLogNone = 0, eCAmLogStdout = 1, eCAmLogFile = 2 } eCAmLogType;
51 
52 class CAmLog
53 {
54 private:
58  class CAmLogger
59  {
60  protected:
61  std::ostream* mOutputStream;
62  public:
63  CAmLogger ():mOutputStream(NULL) {};
64  virtual ~CAmLogger () { };
65  virtual void log(const std::string& _s)
66  {
67  (*mOutputStream) << _s;
68  mOutputStream->flush();
69  }
70  template <class T>
71  CAmLogger & operator << (const T & t)
72  {
73  (*mOutputStream) << t;
74  return (*this);
75  }
76  };
77 
78  class CAmFileLogger : public CAmLogger
79  {
80  std::string mFilename;
81  public:
82  static void generateLogFilename(std::string &result);
83  explicit CAmFileLogger(const std::string& _s) : CAmLogger()
84  {
85  mFilename = _s;
86  mOutputStream = new std::ofstream(mFilename.c_str());
87  }
88  ~CAmFileLogger();
89  };
90 
91  class CAmStdOutLogger : public CAmLogger
92  {
93  public:
94  CAmStdOutLogger()
95  {
96  mOutputStream = &std::cout;
97  }
98  };
99 
100 private:
101  eCAmLogType mLogType;
102  CAmLogger* mLogger;
103 
104 protected:
105  void releaseLogger();
106  void instantiateLogger( const eCAmLogType type);
107 public:
108  CAmLog(const eCAmLogType type );
109  CAmLog();
110  ~CAmLog();
111 
112  static CAmLog *getDefaultLog();
113 
114  void setLogType( const eCAmLogType type);
115  eCAmLogType getLogType() const;
116 
117  template <class T>
118  CAmLog & operator << (const T & t)
119  {
120  assert(mLogger!=NULL);
121  (*mLogger) << t;
122  return (*this);
123  }
124  };
125 
126 #define CAmLogger (*CAmLog::getDefaultLog())
127 
128 
129 #endif /* CAMLOG_H_ */
eCAmLogType
Definition: CAmLog.h:50
#define CAmLogger
Definition: CAmLog.h:126
CAmLog()
Definition: CAmLog.cpp:54
CAmLog & operator<<(const T &t)
Definition: CAmLog.h:118
static CAmLog * getDefaultLog()
Definition: CAmLog.cpp:82
void log(DltContext *const context, DltLogLevelType loglevel, T value, TArgs...args)
logs given values with a given context (register first!) and given loglevel
void setLogType(const eCAmLogType type)
Definition: CAmLog.cpp:88
void instantiateLogger(const eCAmLogType type)
Definition: CAmLog.cpp:70
eCAmLogType getLogType() const
Definition: CAmLog.cpp:98
Definition: CAmLog.h:52
void releaseLogger()
Definition: CAmLog.cpp:64
~CAmLog()
Definition: CAmLog.cpp:59