Use an other implementation of a null_stream for the logger
This commit is contained in:
@@ -3,14 +3,18 @@
|
|||||||
|
|
||||||
Logger::Logger(const int log_level):
|
Logger::Logger(const int log_level):
|
||||||
log_level(log_level),
|
log_level(log_level),
|
||||||
stream(std::cout.rdbuf())
|
stream(std::cout.rdbuf()),
|
||||||
|
null_buffer{},
|
||||||
|
null_stream{&null_buffer}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Logger(const int log_level, const std::string& log_file):
|
Logger::Logger(const int log_level, const std::string& log_file):
|
||||||
log_level(log_level),
|
log_level(log_level),
|
||||||
ofstream(log_file.data(), std::ios_base::app),
|
ofstream(log_file.data(), std::ios_base::app),
|
||||||
stream(ofstream.rdbuf())
|
stream(ofstream.rdbuf()),
|
||||||
|
null_buffer{},
|
||||||
|
null_stream{&null_buffer}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,15 +33,15 @@
|
|||||||
# define __FILENAME__ __FILE__
|
# define __FILENAME__ __FILE__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Juste a structure representing a stream doing nothing with its input.
|
* A buffer, used to construct an ostream that does nothing
|
||||||
|
* when we output data in it
|
||||||
*/
|
*/
|
||||||
class nullstream: public std::ostream
|
class NullBuffer: public std::streambuf
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nullstream():
|
int overflow(int c) { return c; }
|
||||||
std::ostream(0)
|
|
||||||
{ }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Logger
|
class Logger
|
||||||
@@ -59,9 +59,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const int log_level;
|
const int log_level;
|
||||||
std::ofstream ofstream;
|
std::ofstream ofstream{};
|
||||||
nullstream null_stream;
|
|
||||||
std::ostream stream;
|
std::ostream stream;
|
||||||
|
|
||||||
|
NullBuffer null_buffer;
|
||||||
|
std::ostream null_stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define WHERE __FILENAME__, ":", __LINE__, ":\t"
|
#define WHERE __FILENAME__, ":", __LINE__, ":\t"
|
||||||
|
|||||||
Reference in New Issue
Block a user