Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GE_LOGGER_H
- #define GE_LOGGER_H
- #include <algorithm>
- #include <string>
- #include <fstream>
- #include <iostream>
- namespace ge
- {
- class Logger
- {
- public:
- Logger() = delete;
- Logger( const Logger& logger ) = delete;
- Logger( const std::string& filename, bool theStandardOutput = true );
- ~Logger();
- void Log( const std::string& str );
- #define stream(val) \
- file << ( val ); \
- if ( standardOutput ) \
- { \
- std::cout << ( val ); \
- }
- // http://en.wikipedia.org/wiki/Variadic_templates
- template< typename T, typename... Args >
- void Log( const std::string& str, T value, Args... args )
- {
- for ( auto it = str.begin(); it != str.end(); ++it )
- {
- size_t dist = std::distance( str.begin(), it );
- char cc = ( * it );
- if ( dist >= str.size() - 1 )
- {
- stream( cc );
- break;
- }
- char nc = ( * ( it + 1 ) );
- if ( cc == '%' and nc != '%' )
- {
- stream( value );
- Log( str.substr( dist + 1 ), args... );
- return;
- }
- stream( cc );
- }
- }
- #undef stream
- private:
- std::fstream file;
- bool standardOutput;
- };
- }
- #endif // GE_LOGGER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement