I would like to create a custom logger which allows logging commands in stream-style, but at the same time the output goes to some file or to the screen (cout) or to both. The code below illustrates the functionality:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include "logger.hpp"
- using std::endl;
- int main()
- {
- Log log;
- log.init("out.log");
- log.setLogOutputToFile(true);
- log.setLogOutputToScreen(true);
- int i = 10;
- log << "iteration #" << i << endl;
- return 0;
- }
Expand|Select|Wrap|Line Numbers
- template <typename T>
- Log& Log::operator<<( T& os )
- {
- if (printToFile_)
- {
- logFile_ << os;
- }
- if (printToScreen_)
- {
- cout << os;
- }
- return *this;
- }
src/main.cpp:17: error: no match for ‘operator<<’ in ‘((Log*)log.Log::operator<< [with T = const char [12]](((const char (&)[12])"iteration #")))->Log::operator<< [with T = int](((int&)(& i))) << std::endl’or compiling with intel's-icpc
src/main.cpp(17): error: no operator "<<" matches these operandsNot to mention that we do not only desire to allow "endl" but all manipulators like "std::right, std::left, setw" etc.
operand types are: Log << <unknown-type>
log << "iteration #" << i << endl;
Is there something I am doing wrong? Of course there is, but what can I do to get rid of these error messages?
Thank you all for your time,
Archwn.