Alien-libpanda

 view release on metacpan or  search on metacpan

src/panda/log.h  view on Meta::CPAN

    Emergency
};

struct Module {
    Module* parent;
    Level   level;
    string  name;

    Module(const string& name, Level level = Level::Debug);
    Module(const string& name, Module* parent, Level level = Level::Debug);

    Module(const Module&) = delete;
    Module(Module&&) = delete;
    Module & operator =(const Module&) = delete;

    void set_level(Level level);

    std::map<string, Module*> children;
};

struct CodePoint {
    string_view file;
    uint32_t    line;
    Module*     module;

    std::string to_string () const;
};
std::ostream& operator<< (std::ostream&, const CodePoint&);

struct ILogger {
    virtual bool should_log (Level, const CodePoint&) { return true; }
    virtual void log        (Level, const CodePoint&, const std::string&) = 0;
    virtual ~ILogger() {}
};

namespace details {
    extern Level                    min_level;
    extern std::unique_ptr<ILogger> ilogger;

    std::ostream& _get_os ();
    bool          _do_log (std::ostream&, const CodePoint&, Level);

    template <class Func>
    struct CallbackLogger : ILogger {
        Func f;
        CallbackLogger (const Func& f) : f(f) {}
        void log (Level level, const CodePoint& cp, const std::string& s) override { f(level, cp, s); }
    };
}

void set_level  (Level, const string& name = "");
void set_logger (ILogger*);

template <class Func, typename = std::enable_if_t<!std::is_base_of<ILogger, std::remove_cv_t<std::remove_pointer_t<Func>>>::value>>
void set_logger (const Func& f) { set_logger(new details::CallbackLogger<Func>(f)); }

inline bool should_log (Level level, const CodePoint& cp, const Module& module) {
    return level >= module.level && details::ilogger && details::ilogger->should_log(level, cp);
}

struct escaped {
    string_view src;
};
std::ostream& operator<< (std::ostream&, const escaped&);

}
}
extern panda::log::Module* panda_log_module;



( run in 0.315 second using v1.01-cache-2.11-cpan-acebb50784d )