2017-08-08 13:53:47 +02:00
|
|
|
#ifndef _LOGGER_H
|
2018-10-26 19:57:39 +11:00
|
|
|
#define _LOGGER_H
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-26 20:06:12 +11:00
|
|
|
#include <string>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2019-01-04 21:46:37 +11:00
|
|
|
#include <spdlog/fmt/fmt.h>
|
|
|
|
|
2018-11-29 16:55:48 +01:00
|
|
|
namespace Sapphire
|
2018-08-29 21:40:59 +02:00
|
|
|
{
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
class Logger
|
|
|
|
{
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
private:
|
|
|
|
std::string m_logFile;
|
|
|
|
Logger();
|
|
|
|
~Logger();
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
public:
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
static void init( const std::string& logPath );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2019-01-04 21:46:37 +11:00
|
|
|
// todo: this is a minor increase in build time because of fmtlib, but much less than including spdlog directly
|
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
static void error( const std::string& text );
|
2019-01-04 21:46:37 +11:00
|
|
|
template< typename... Args >
|
2019-01-05 12:32:10 +01:00
|
|
|
static void error( const std::string& text, const Args&... args )
|
2019-01-04 21:46:37 +11:00
|
|
|
{
|
2019-01-05 12:32:10 +01:00
|
|
|
error( fmt::format( text, args... ) );
|
2019-01-04 21:46:37 +11:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-12-30 21:26:32 +11:00
|
|
|
static void warn( const std::string& text );
|
2019-01-04 21:46:37 +11:00
|
|
|
template< typename... Args >
|
2019-01-05 12:32:10 +01:00
|
|
|
static void warn( const std::string& text, const Args&... args )
|
2019-01-04 21:46:37 +11:00
|
|
|
{
|
2019-01-05 12:32:10 +01:00
|
|
|
warn( fmt::format( text, args... ) );
|
2019-01-04 21:46:37 +11:00
|
|
|
}
|
|
|
|
|
2018-12-30 21:26:32 +11:00
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
static void info( const std::string& text );
|
2019-01-04 21:46:37 +11:00
|
|
|
template< typename... Args >
|
2019-01-05 12:32:10 +01:00
|
|
|
static void info( const std::string& text, const Args&... args )
|
2019-01-04 21:46:37 +11:00
|
|
|
{
|
2019-01-05 12:32:10 +01:00
|
|
|
info( fmt::format( text, args... ) );
|
2019-01-04 21:46:37 +11:00
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
static void debug( const std::string& text );
|
2019-01-04 21:46:37 +11:00
|
|
|
template< typename... Args >
|
2019-01-05 12:32:10 +01:00
|
|
|
static void debug( const std::string& text, const Args&... args )
|
2019-01-04 21:46:37 +11:00
|
|
|
{
|
2019-01-05 12:32:10 +01:00
|
|
|
debug( fmt::format( text, args... ) );
|
2019-01-04 21:46:37 +11:00
|
|
|
}
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-12-23 03:53:08 +01:00
|
|
|
static void fatal( const std::string& text );
|
2019-01-04 21:46:37 +11:00
|
|
|
template< typename... Args >
|
2019-01-05 12:32:10 +01:00
|
|
|
static void fatal( const std::string& text, const Args&... args )
|
2019-01-04 21:46:37 +11:00
|
|
|
{
|
2019-01-05 12:32:10 +01:00
|
|
|
fatal( fmt::format( text, args... ) );
|
2019-01-04 21:46:37 +11:00
|
|
|
}
|
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-12-30 21:26:32 +11:00
|
|
|
static void trace( const std::string& text );
|
2019-01-04 21:46:37 +11:00
|
|
|
template< typename... Args >
|
2019-01-05 12:32:10 +01:00
|
|
|
static void trace( const std::string& text, const Args&... args )
|
2019-01-04 21:46:37 +11:00
|
|
|
{
|
2019-01-05 12:32:10 +01:00
|
|
|
trace( fmt::format( text, args... ) );
|
2019-01-04 21:46:37 +11:00
|
|
|
}
|
|
|
|
|
2018-12-30 21:26:32 +11:00
|
|
|
|
2018-10-28 21:53:21 +01:00
|
|
|
};
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
|
2018-09-26 08:47:22 -04:00
|
|
|
#endif
|