mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 10:32:56 +01:00
feat(Logger): Optimize multi-arg logger methods to only call format() if log level allows #2332
This commit is contained in:
@@ -156,7 +156,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void fatal(const std::string& fmt, T arg1, Args&&... args)
|
void fatal(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_FATAL);
|
if (fatal())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_FATAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void critical(const std::string& msg);
|
void critical(const std::string& msg);
|
||||||
@@ -178,7 +179,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void critical(const std::string& fmt, T arg1, Args&&... args)
|
void critical(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_CRITICAL);
|
if (critical())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_CRITICAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(const std::string& msg);
|
void error(const std::string& msg);
|
||||||
@@ -200,7 +202,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void error(const std::string& fmt, T arg1, Args&&... args)
|
void error(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_ERROR);
|
if (error())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void warning(const std::string& msg);
|
void warning(const std::string& msg);
|
||||||
@@ -222,7 +225,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void warning(const std::string& fmt, T arg1, Args&&... args)
|
void warning(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_WARNING);
|
if (warning())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void notice(const std::string& msg);
|
void notice(const std::string& msg);
|
||||||
@@ -244,7 +248,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void notice(const std::string& fmt, T arg1, Args&&... args)
|
void notice(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_NOTICE);
|
if (notice())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_NOTICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void information(const std::string& msg);
|
void information(const std::string& msg);
|
||||||
@@ -266,7 +271,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void information(const std::string& fmt, T arg1, Args&&... args)
|
void information(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_INFORMATION);
|
if (information())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_INFORMATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug(const std::string& msg);
|
void debug(const std::string& msg);
|
||||||
@@ -288,7 +294,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void debug(const std::string& fmt, T arg1, Args&&... args)
|
void debug(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_DEBUG);
|
if (debug())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trace(const std::string& msg);
|
void trace(const std::string& msg);
|
||||||
@@ -310,7 +317,8 @@ public:
|
|||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
void trace(const std::string& fmt, T arg1, Args&&... args)
|
void trace(const std::string& fmt, T arg1, Args&&... args)
|
||||||
{
|
{
|
||||||
log(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_TRACE);
|
if (trace())
|
||||||
|
logAlways(Poco::format(fmt, arg1, std::forward<Args>(args)...), Message::PRIO_TRACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump(const std::string& msg, const void* buffer, std::size_t length, Message::Priority prio = Message::PRIO_DEBUG);
|
void dump(const std::string& msg, const void* buffer, std::size_t length, Message::Priority prio = Message::PRIO_DEBUG);
|
||||||
@@ -468,6 +476,8 @@ private:
|
|||||||
Logger(const Logger&);
|
Logger(const Logger&);
|
||||||
Logger& operator = (const Logger&);
|
Logger& operator = (const Logger&);
|
||||||
|
|
||||||
|
void logAlways(const std::string& text, Message::Priority prio);
|
||||||
|
|
||||||
std::string _name;
|
std::string _name;
|
||||||
Channel::Ptr _pChannel;
|
Channel::Ptr _pChannel;
|
||||||
int _level;
|
int _level;
|
||||||
@@ -674,6 +684,15 @@ inline void Logger::log(const std::string& text, Message::Priority prio, const c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void Logger::logAlways(const std::string& text, Message::Priority prio)
|
||||||
|
{
|
||||||
|
if (_pChannel)
|
||||||
|
{
|
||||||
|
_pChannel->log(Message(_name, text, prio));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Logger::fatal(const std::string& msg)
|
inline void Logger::fatal(const std::string& msg)
|
||||||
{
|
{
|
||||||
log(msg, Message::PRIO_FATAL);
|
log(msg, Message::PRIO_FATAL);
|
||||||
|
|||||||
Reference in New Issue
Block a user