Skip to content

Commit

Permalink
implement and integrate the new logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fmang committed Mar 3, 2018
1 parent 6cd658e commit 794a48e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/core/log.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* \file core/log.h
* \file include/core/log.h
* \ingroup core_log
*/

Expand Down Expand Up @@ -131,12 +131,12 @@ extern level priority;
*/
std::ostream& logger(level priority);

std::ostream& critical();
std::ostream& error();
std::ostream& warning();
std::ostream& info();
std::ostream& debug();
std::ostream& verbose();
std::ostream& debug();
std::ostream& info();
std::ostream& warning();
std::ostream& error();
std::ostream& critical();

/** \} */

Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_library(
beatmap/geometry.cc
beatmap/helpers.cc
beatmap/parser.cc
core/log.cc
game/actions.cc
game/clock.cc
game/controls.cc
Expand Down
36 changes: 36 additions & 0 deletions lib/core/log.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* \file src/core/log.cc
* \ingroup core_log
*/

#include "core/log.h"

#include <iostream>

namespace oshu {
inline namespace core {
namespace log {

level priority = level::warning;

/**
* Dummy output stream.
*/
static std::ostream devnull {nullptr};

std::ostream& logger(level priority)
{
if (priority >= oshu::core::log::priority)
return std::clog;
else
return devnull;
}

std::ostream& verbose() { return logger(level::verbose) << "VERBOSE: "; }
std::ostream& debug() { return logger(level::debug) << "DEBUG: "; }
std::ostream& info() { return logger(level::info) << "INFO: "; }
std::ostream& warning() { return logger(level::warning) << "WARNING: "; }
std::ostream& error() { return logger(level::error) << "ERROR: "; }
std::ostream& critical() { return logger(level::critical) << "CRITICAL: "; }

}}}
1 change: 1 addition & 0 deletions src/oshu/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ int main(int argc, char **argv)
return 2;
}

oshu::log::priority = static_cast<oshu::log::level>(verbosity);
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, (SDL_LogPriority) verbosity);
av_log_set_level(verbosity <= SDL_LOG_PRIORITY_DEBUG ? AV_LOG_INFO : AV_LOG_ERROR);
Expand Down

0 comments on commit 794a48e

Please sign in to comment.