stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

logger.hpp (713B)


      1 #ifndef STELLAR_ARENA_LOGGER_H
      2 #define STELLAR_ARENA_LOGGER_H
      3 
      4 #include "utils.hpp"
      5 #include <cerrno>
      6 #include <cstring>
      7 #include <format>
      8 #include <iostream>
      9 
     10 namespace logger {
     11 
     12 enum Level {
     13     Critical,
     14     Arena,
     15     Debug,
     16     Info,
     17 };
     18 
     19 static Level active = Debug;
     20 inline void set_level(const Level lvl) { active = lvl; }
     21 
     22 inline void log(const std::string &message, const Level lvl = Arena) {
     23     static const std::string name[] = {"crit", "arena", "debug", "info"};
     24     if (lvl > active) return;
     25     std::cerr << std::format("[ {:>5} ] {}\n", name[lvl], message);
     26 }
     27 
     28 inline void error(const char *call) { log(std::format("{}, {}", call, std::strerror(errno)), Critical); }
     29 
     30 } // namespace logger
     31 
     32 #endif