// // logger.hpp // logger // // Created by Sam Jaffe on 9/3/16. // #pragma once // // Logger.hpp // DanmakuRPG // // Created by Sam Jaffe on 7/18/15. // Copyright (c) 2015 Sam Jaffe. All rights reserved. // #pragma once #include #include #include #include #include #include "message.h" #define log_message(logger, lvl, ...) \ logger.log(level::lvl, log_here, __VA_ARGS__) namespace logging { enum class level : int; struct location_info; class logger_impl; struct logpacket; /* * The main top-level class that should be used when performing logging. * Provides various overrides of the function log() that handle various use * cases. In comparison with the C-Style logger, this one uses a Python style * of string formatting. * Currently, it is only able to support "{}", and cannot use positional, * named, or reflection-based interpolations. Under the hood, the loggers are * configured in a similar fashion to those in Log4J, such as PatternLayout * and FileAppender. * One of the useful features of this logger is the log_here macro. Log here * uses the compiler to generate all of the necessary information for file * name, class/namespace path, method name, and line number. It is not * supported for the logger to learn that information on its own through * creating a backtrace. */ class logger { private: friend class manager; std::string const logger_name_; std::shared_ptr impl_; public: ~logger(); void log(level ll, char const * str) { log(ll, message(str)); } void log(level ll, std::string const & str) { log(ll, message(str)); } template void log(level ll, std::string const & interp, Args &&... args) { log(ll, message(interp, std::forward(args)...)); } template void log(level ll, location_info const & info, std::string const & interp, Args &&... args) { log(ll, info, message(interp, std::forward(args)...)); } void flush(); protected: logger(std::string const & name, std::shared_ptr impl); private: void log(level ll, message const &); void log(level ll, location_info const & info, message const &); }; }