summaryrefslogtreecommitdiff
path: root/louloulibs/logger
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-12-09 01:34:46 +0100
committerlouiz’ <louiz@louiz.org>2016-12-09 01:34:46 +0100
commite63f79169b2c031bdc1a4bb6ba8df34363e9e3c0 (patch)
treea1a4cdb2aa296208922c922a6de752710ab0b218 /louloulibs/logger
parent0a45b096653f7c9fd0275f2755989a869ab35c9d (diff)
downloadbiboumi-e63f79169b2c031bdc1a4bb6ba8df34363e9e3c0.tar.gz
biboumi-e63f79169b2c031bdc1a4bb6ba8df34363e9e3c0.tar.bz2
biboumi-e63f79169b2c031bdc1a4bb6ba8df34363e9e3c0.tar.xz
biboumi-e63f79169b2c031bdc1a4bb6ba8df34363e9e3c0.zip
Use an other implementation of a null_stream for the logger
Diffstat (limited to 'louloulibs/logger')
-rw-r--r--louloulibs/logger/logger.cpp8
-rw-r--r--louloulibs/logger/logger.hpp18
2 files changed, 16 insertions, 10 deletions
diff --git a/louloulibs/logger/logger.cpp b/louloulibs/logger/logger.cpp
index 7336579..92a3d9b 100644
--- a/louloulibs/logger/logger.cpp
+++ b/louloulibs/logger/logger.cpp
@@ -3,14 +3,18 @@
Logger::Logger(const int 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):
log_level(log_level),
ofstream(log_file.data(), std::ios_base::app),
- stream(ofstream.rdbuf())
+ stream(ofstream.rdbuf()),
+ null_buffer{},
+ null_stream{&null_buffer}
{
}
diff --git a/louloulibs/logger/logger.hpp b/louloulibs/logger/logger.hpp
index 0893c77..b3284a6 100644
--- a/louloulibs/logger/logger.hpp
+++ b/louloulibs/logger/logger.hpp
@@ -33,15 +33,15 @@
# define __FILENAME__ __FILE__
#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:
- nullstream():
- std::ostream(0)
- { }
+ public:
+ int overflow(int c) { return c; }
};
class Logger
@@ -59,9 +59,11 @@ public:
private:
const int log_level;
- std::ofstream ofstream;
- nullstream null_stream;
+ std::ofstream ofstream{};
std::ostream stream;
+
+ NullBuffer null_buffer;
+ std::ostream null_stream;
};
#define WHERE __FILENAME__, ":", __LINE__, ":\t"