| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //
- // 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 <cstdarg>
- #include <cstdlib>
- #include <cstring>
- #include <memory>
- #include <string>
- #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<logger_impl> 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 <typename... Args>
- void log(level ll, std::string const & interp, Args &&... args) {
- log(ll, message(interp, std::forward<Args>(args)...));
- }
- template <typename... Args>
- void log(level ll, location_info const & info, std::string const & interp,
- Args &&... args) {
- log(ll, info, message(interp, std::forward<Args>(args)...));
- }
- void flush();
- protected:
- logger(std::string const & name, std::shared_ptr<logger_impl> impl);
- private:
- void log(level ll, message const &);
- void log(level ll, location_info const & info, message const &);
- };
- }
|