Skip to content

Instantly share code, notes, and snippets.

@MikeLing
Last active July 8, 2017 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeLing/d146ca104903d2257446a4ee236edd50 to your computer and use it in GitHub Desktop.
Save MikeLing/d146ca104903d2257446a4ee236edd50 to your computer and use it in GitHub Desktop.
#include "spdlog/spdlog.h"
class SGIO
{
public:
SGIO
{
...
}
#ifdef HAVESPDLOG
void set_target_to_file(string filename)
{
shogun_log = spdlog::rotating_logger_mt("shogunFileLog");
}
void set_target_to_stdout()
{
shogun_log = spdlog::stdout_color_mt("shogunlog");
}
void set_target_to_stderr()
{
shogun_log = spdlog::stderr_color_mt("shogunErrorLog");
}
#endif
#ifdef HAVESPDLOG
public:
...
std::shared_ptr<spdlog::logger> shogun_log;
...
#endif
}
void SGIO::message(EMessageType prio, const char* function, const char* file,
int32_t line, const char *fmt, ... ) const
{
...
switch (prio)
{
case MSG_GCDEBUG:
case MSG_DEBUG:
shogun_log->debug(str);
break;
case MSG_INFO:
shogun_log->info(str);
break;
case MSG_NOTICE:
case MSG_MESSAGEONLY:
shogun_log->info(str);
break;
case MSG_WARN:
if (sg_print_warning)
shogun_log->warn(str);
break;
case MSG_ERROR:
shogun_log->error(str);
break;
case MSG_CRITICAL:
shogun_log->critical(str);
break;
case MSG_ALERT:
case MSG_EMERGENCY:
if (sg_print_error)
shogun_log->error(str);
throw ShogunException(str);
break;
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment