mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
astyle
This commit is contained in:
parent
a9dbfb8b0e
commit
ece27ac952
@ -64,10 +64,10 @@ int main(int, char* [])
|
|||||||
SPDLOG_TRACE(file_logger, "This is a trace message (only #ifdef _DEBUG)", 123);
|
SPDLOG_TRACE(file_logger, "This is a trace message (only #ifdef _DEBUG)", 123);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
auto syslog_logger = spd::syslog_logger("syslog");
|
auto syslog_logger = spd::syslog_logger("syslog");
|
||||||
syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!");
|
syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch (const spd::spdlog_ex& ex)
|
catch (const spd::spdlog_ex& ex)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ typedef enum
|
|||||||
DEBUG = 1,
|
DEBUG = 1,
|
||||||
INFO = 2,
|
INFO = 2,
|
||||||
NOTICE = 3,
|
NOTICE = 3,
|
||||||
WARN = 4,
|
WARN = 4,
|
||||||
ERR = 5,
|
ERR = 5,
|
||||||
CRITICAL = 6,
|
CRITICAL = 6,
|
||||||
ALERT = 7,
|
ALERT = 7,
|
||||||
@ -60,7 +60,8 @@ typedef enum
|
|||||||
} level_enum;
|
} level_enum;
|
||||||
|
|
||||||
static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical",
|
static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical",
|
||||||
"alert", "emerg", "", ""};
|
"alert", "emerg", "", ""
|
||||||
|
};
|
||||||
inline const char* to_str(spdlog::level::level_enum l)
|
inline const char* to_str(spdlog::level::level_enum l)
|
||||||
{
|
{
|
||||||
return level_names[l];
|
return level_names[l];
|
||||||
|
@ -82,10 +82,10 @@ public:
|
|||||||
|
|
||||||
void reopen()
|
void reopen()
|
||||||
{
|
{
|
||||||
if(_filename.empty())
|
if(_filename.empty())
|
||||||
throw spdlog_ex("Failed re opening file - was not opened before");
|
throw spdlog_ex("Failed re opening file - was not opened before");
|
||||||
open(_filename);
|
open(_filename);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void close()
|
void close()
|
||||||
|
@ -125,12 +125,12 @@ private:
|
|||||||
std::string target = calc_filename(_base_filename, i, _extension);
|
std::string target = calc_filename(_base_filename, i, _extension);
|
||||||
|
|
||||||
if (details::file_helper::file_exists(target))
|
if (details::file_helper::file_exists(target))
|
||||||
{
|
{
|
||||||
if (std::remove(target.c_str()) != 0)
|
if (std::remove(target.c_str()) != 0)
|
||||||
{
|
{
|
||||||
throw spdlog_ex("rotating_file_sink: failed removing " + target);
|
throw spdlog_ex("rotating_file_sink: failed removing " + target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str()))
|
if (details::file_helper::file_exists(src) && std::rename(src.c_str(), target.c_str()))
|
||||||
{
|
{
|
||||||
throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target);
|
throw spdlog_ex("rotating_file_sink: failed renaming " + src + " to " + target);
|
||||||
|
@ -35,54 +35,54 @@
|
|||||||
|
|
||||||
namespace spdlog
|
namespace spdlog
|
||||||
{
|
{
|
||||||
namespace sinks
|
namespace sinks
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Sink that write to syslog using the `syscall()` library call.
|
* Sink that write to syslog using the `syscall()` library call.
|
||||||
*
|
*
|
||||||
* Locking is not needed, as `syslog()` itself is thread-safe.
|
* Locking is not needed, as `syslog()` itself is thread-safe.
|
||||||
*/
|
*/
|
||||||
class syslog_sink : public sink
|
class syslog_sink : public sink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
syslog_sink()
|
||||||
{
|
{
|
||||||
public:
|
_priorities[static_cast<int>(level::TRACE)] = LOG_DEBUG;
|
||||||
syslog_sink()
|
_priorities[static_cast<int>(level::DEBUG)] = LOG_DEBUG;
|
||||||
{
|
_priorities[static_cast<int>(level::INFO)] = LOG_INFO;
|
||||||
_priorities[static_cast<int>(level::TRACE)] = LOG_DEBUG;
|
_priorities[static_cast<int>(level::NOTICE)] = LOG_NOTICE;
|
||||||
_priorities[static_cast<int>(level::DEBUG)] = LOG_DEBUG;
|
_priorities[static_cast<int>(level::WARN)] = LOG_WARNING;
|
||||||
_priorities[static_cast<int>(level::INFO)] = LOG_INFO;
|
_priorities[static_cast<int>(level::ERR)] = LOG_ERR;
|
||||||
_priorities[static_cast<int>(level::NOTICE)] = LOG_NOTICE;
|
_priorities[static_cast<int>(level::CRITICAL)] = LOG_CRIT;
|
||||||
_priorities[static_cast<int>(level::WARN)] = LOG_WARNING;
|
_priorities[static_cast<int>(level::ALERT)] = LOG_ALERT;
|
||||||
_priorities[static_cast<int>(level::ERR)] = LOG_ERR;
|
_priorities[static_cast<int>(level::EMERG)] = LOG_EMERG;
|
||||||
_priorities[static_cast<int>(level::CRITICAL)] = LOG_CRIT;
|
|
||||||
_priorities[static_cast<int>(level::ALERT)] = LOG_ALERT;
|
|
||||||
_priorities[static_cast<int>(level::EMERG)] = LOG_EMERG;
|
|
||||||
|
|
||||||
_priorities[static_cast<int>(level::ALWAYS)] = LOG_INFO;
|
_priorities[static_cast<int>(level::ALWAYS)] = LOG_INFO;
|
||||||
_priorities[static_cast<int>(level::OFF)] = LOG_INFO;
|
_priorities[static_cast<int>(level::OFF)] = LOG_INFO;
|
||||||
}
|
}
|
||||||
virtual ~syslog_sink() = default;
|
virtual ~syslog_sink() = default;
|
||||||
|
|
||||||
syslog_sink(const syslog_sink&) = delete;
|
|
||||||
syslog_sink& operator=(const syslog_sink&) = delete;
|
|
||||||
|
|
||||||
void log(const details::log_msg &msg) override
|
|
||||||
{
|
|
||||||
syslog(syslog_prio_from_level(msg), "%s", msg.formatted.str().c_str());
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
syslog_sink(const syslog_sink&) = delete;
|
||||||
/**
|
syslog_sink& operator=(const syslog_sink&) = delete;
|
||||||
* Simply maps spdlog's log level to syslog priority level.
|
|
||||||
*/
|
|
||||||
int syslog_prio_from_level(const details::log_msg &msg) const
|
|
||||||
{
|
|
||||||
return _priorities[static_cast<int>(msg.level)];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
void log(const details::log_msg &msg) override
|
||||||
std::array<int, 11> _priorities;
|
{
|
||||||
|
syslog(syslog_prio_from_level(msg), "%s", msg.formatted.str().c_str());
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* Simply maps spdlog's log level to syslog priority level.
|
||||||
|
*/
|
||||||
|
int syslog_prio_from_level(const details::log_msg &msg) const
|
||||||
|
{
|
||||||
|
return _priorities[static_cast<int>(msg.level)];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<int, 11> _priorities;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -70,7 +70,7 @@ std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name);
|
|||||||
|
|
||||||
// Create a syslog logger
|
// Create a syslog logger
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
std::shared_ptr<logger> syslog_logger(const std::string& logger_name);
|
std::shared_ptr<logger> syslog_logger(const std::string& logger_name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user