2 * Copyright (C) 2012, BMW AG
4 * This file is part of GENIVI Project AudioManager.
6 * Contributions are licensed to the GENIVI Alliance under one or more
7 * Contribution License Agreements.
10 * This Source Code Form is subject to the terms of the
11 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
12 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013
18 * For further information see http://www.genivi.org/.
35 * Implements a basic logging mechanism that can be used to print debug information into a file or to the console.
36 * It can be used either as singleton through the appropriate method getDefaultLog() or as independent instantiated object.
37 * The default initializer sets the console as output for newly created objects.
38 * Example: CAmLogger << "Text"; //to print out through the singleton object directly to the console
41 #define DEFAULT_LOG_FOLDER "/tmp/"
42 #define DEFAULT_LOGFILE_PREFIX "am_dump_"
43 #define DEFAULT_LOGFILE_EXT ".log"
45 #define DEL( aPointer ) delete aPointer, aPointer = NULL;
48 typedef enum { eCAmLogNone = 0, eCAmLogStdout = 1, eCAmLogFile = 2 } eCAmLogType;
54 * Private classes which usually own (wrap) a stream object. They are responsible for creating and deleting it.
59 std::ostream* mOutputStream;
61 CAmLogger ():mOutputStream(NULL) {};
62 virtual ~CAmLogger () { };
63 virtual void log(const std::string& _s)
65 (*mOutputStream) << _s;
66 mOutputStream->flush();
69 CAmLogger & operator << (const T & t)
71 (*mOutputStream) << t;
76 class CAmFileLogger : public CAmLogger
78 std::string mFilename;
80 static void generateLogFilename(std::string &result);
81 explicit CAmFileLogger(const std::string& _s) : CAmLogger()
84 mOutputStream = new std::ofstream(mFilename.c_str());
89 class CAmStdOutLogger : public CAmLogger
94 mOutputStream = &std::cout;
103 void releaseLogger();
104 void instantiateLogger( const eCAmLogType type);
106 CAmLog(const eCAmLogType type );
110 static CAmLog *getDefaultLog();
112 void setLogType( const eCAmLogType type);
113 eCAmLogType getLogType() const;
116 CAmLog & operator << (const T & t)
118 assert(mLogger!=NULL);
124 #define CAmLogger (*CAmLog::getDefaultLog())
127 #endif /* CAMLOG_H_ */