AudioManager  7.6.6
Native Application Runtime Environment
CAmLog.cpp
Go to the documentation of this file.
1 
24 #include "CAmLog.h"
25 
26 
27 void CAmLog::CAmFileLogger::generateLogFilename(std::string &result)
28 {
29  static uint32_t logFileID = 1;
30  time_t rawtime;
31  time (&rawtime);
32 
33  std::ostringstream stream;
34  stream << DEFAULT_LOG_FOLDER << DEFAULT_LOGFILE_PREFIX << logFileID << "_" << rawtime << DEFAULT_LOGFILE_EXT;
35  logFileID++;
36  result = stream.str();
37 }
38 
39 CAmLog::CAmFileLogger::~CAmFileLogger()
40 {
41  if (mOutputStream)
42  {
43  std::ofstream* of = static_cast<std::ofstream*>(mOutputStream);
44  of->close();
45  DEL(mOutputStream)
46  }
47 }
48 
49 CAmLog::CAmLog(const eCAmLogType type ):mLogType(type)
50 {
51  instantiateLogger(type);
52 }
53 
55 {
57 }
58 
60 {
61  releaseLogger();
62 }
63 
65 {
66  if(mLogger)
67  DEL(mLogger)
68 }
69 
71 {
72  if( eCAmLogStdout == type )
73  mLogger = new CAmStdOutLogger();
74  else if( eCAmLogFile == type )
75  {
76  std::string filename("");
77  CAmLog::CAmFileLogger::generateLogFilename(filename);
78  mLogger = new CAmFileLogger(filename);
79  }
80 }
81 
83 {
84  static CAmLog theInstance;
85  return &theInstance;
86 }
87 
89 {
90  if(mLogType!=type)
91  {
92  mLogType = type;
93  releaseLogger();
94  instantiateLogger(type);
95  }
96 }
97 
99 {
100  return mLogType;
101 }
#define DEL(aPointer)
Definition: CAmLog.h:47
#define DEFAULT_LOGFILE_EXT
Definition: CAmLog.h:45
eCAmLogType
Definition: CAmLog.h:50
CAmLog()
Definition: CAmLog.cpp:54
static CAmLog * getDefaultLog()
Definition: CAmLog.cpp:82
SPDX license identifier: MPL-2.0.
void setLogType(const eCAmLogType type)
Definition: CAmLog.cpp:88
void instantiateLogger(const eCAmLogType type)
Definition: CAmLog.cpp:70
#define DEFAULT_LOGFILE_PREFIX
Definition: CAmLog.h:44
eCAmLogType getLogType() const
Definition: CAmLog.cpp:98
Definition: CAmLog.h:52
#define DEFAULT_LOG_FOLDER
Implements a basic logging mechanism that can be used to print debug information into a file or to th...
Definition: CAmLog.h:43
void releaseLogger()
Definition: CAmLog.cpp:64
~CAmLog()
Definition: CAmLog.cpp:59