Commit b1867cfb authored by gabime's avatar gabime

log levels now lowercase

parent 892de62f
......@@ -68,7 +68,7 @@ int main(int, char* [])
try
{
// Set log level to all loggers to DEBUG and above
spd::set_level(spd::level::DEBUG);
spd::set_level(spd::level::debug);
//Create console, multithreaded logger
auto console = spd::stdout_logger_mt("console");
......@@ -87,7 +87,7 @@ int main(int, char* [])
//Create a file rotating logger with 5mb size max and 3 rotated files
auto file_logger = spd::rotating_logger_mt("file_logger", "logs/mylogfile", 1048576 * 5, 3);
file_logger->set_level(spd::level::INFO);
file_logger->set_level(spd::level::info);
for(int i = 0; i < 10; ++i)
file_logger->info("{} * {} equals {:>10}", i, i, i*i);
......@@ -114,7 +114,7 @@ int main(int, char* [])
//
#ifdef __linux__
std::string ident = "my_app";
auto syslog_logger = spd::syslog_logger("syslog", ident, spd::sinks::syslog::option::PID | spd::sinks::syslog::option::PERROR, "mail" );
auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID | LOG_PERROR);
syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!");
#endif
}
......
......@@ -28,17 +28,13 @@
#include <iostream>
#include "spdlog/spdlog.h"
int main(int, char* [])
{
namespace spd = spdlog;
try
{
std::string filename = "logs/spdlog_example";
// Set log level to all loggers to DEBUG and above
spd::set_level(spd::level::DEBUG);
spd::set_level(spd::level::debug);
//Create console, multithreaded logger
auto console = spd::stdout_logger_mt("console");
......@@ -47,55 +43,49 @@ int main(int, char* [])
console->info() << "Streams are supported too " << 1;
console->info("Easy padding in numbers like {:08d}", 12);
console->info("Support for int: {0:d}; hex: {0:08x}; oct: {0:o}; bin: {0:b}", 42);
console->info("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
console->info("Support for floats {:03.2f}", 1.23456);
console->info("Positional args are {1} {0}..", "too", "supported");
console->info("{:<30}", "left aligned");
console->info("{:>30}", "right aligned");
console->info("{:^30}", "centered");
//Create a file rotating logger with 5mb size max and 3 rotated files
auto file_logger = spd::rotating_logger_mt("file_logger", filename, 1024 * 1024 * 5, 3);
file_logger->info("Log file message number", 1);
auto file_logger = spd::rotating_logger_mt("file_logger", "logs/mylogfile", 1048576 * 5, 3);
file_logger->set_level(spd::level::info);
for(int i = 0; i < 10; ++i)
file_logger->info("{} * {} equals {:>10}", i, i, i*i);
file_logger->info("{} * {} equals {:>10}", i, i, i*i);
//Customize msg format for all messages
spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***");
file_logger->info("This is another message with custom format");
spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");
// Debug and trace macros to be turned on/off at compile time.
// Evaluates to empty statements if not turned on
// Define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON - before including spdlog.h
SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);
#ifdef __linux__
// syslog example
std::string ident = "spdlog_example"; // empty ident can be used to use current program name
auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID);
syslog_logger->set_pattern("[%l] %v"); //syslog already put timestamps so set the pattern to minimum (log level and the message)
syslog_logger->warn("This message that will end up in syslog. This is Linux only..");
#endif
// Asynchronous logging is easy..
//
// Asynchronous logging is very fast..
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
// Note: queue size must be power of 2!
size_t q_size = 1048576;
//
size_t q_size = 1048576; //queue size must be power of 2
spdlog::set_async_mode(q_size);
auto async_file= spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
for(int i = 0; i < 100; i++)
async_file->info("This is async log message #{}.. Should be very fast.. ", i);
async_file->info() << "This is async log.." << "Should be very fast!";
//
// syslog example
//
#ifdef __linux__
std::string ident = "my_app";
auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID | LOG_PERROR);
syslog_logger->warn("This is warning that will end up in syslog. This is Linux only!");
#endif
}
catch (const spd::spdlog_ex& ex)
{
std::cout << "Log failed: " << ex.what() << std::endl;
}
return 0;
}
......@@ -54,16 +54,16 @@ namespace level
{
typedef enum
{
TRACE = 0,
DEBUG = 1,
INFO = 2,
NOTICE = 3,
WARN = 4,
ERR = 5,
CRITICAL = 6,
ALERT = 7,
EMERG = 8,
OFF = 9
trace = 0,
debug = 1,
info = 2,
notice = 3,
warn = 4,
err = 5,
critical = 6,
alert = 7,
emerg = 8,
off = 9
} level_enum;
static const char* level_names[] { "trace", "debug", "info", "notice", "warning", "error", "critical", "alert", "emerg", "off"};
......
......@@ -63,7 +63,7 @@ inline void spdlog::async_logger::_set_pattern(const std::string& pattern)
inline void spdlog::async_logger::_stop()
{
set_level(level::OFF);
set_level(level::off);
}
inline void spdlog::async_logger::_log_msg(details::log_msg& msg)
......
......@@ -80,7 +80,7 @@ struct log_msg
void clear()
{
level = level::OFF;
level = level::off;
raw.clear();
formatted.clear();
}
......
......@@ -40,7 +40,7 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
{
// no support under vs2013 for member initialization for std::atomic
_level = level::INFO;
_level = level::info;
}
// ctor with sinks as init list
......@@ -92,55 +92,55 @@ inline spdlog::details::line_logger spdlog::logger::_log_if_enabled(level::level
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::trace(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::TRACE, fmt, args...);
return _log_if_enabled(level::trace, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::debug(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::DEBUG, fmt, args...);
return _log_if_enabled(level::debug, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::info(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::INFO, fmt, args...);
return _log_if_enabled(level::info, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::notice(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::NOTICE, fmt, args...);
return _log_if_enabled(level::notice, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::warn(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::WARN, fmt, args...);
return _log_if_enabled(level::warn, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::error(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::ERR, fmt, args...);
return _log_if_enabled(level::err, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::critical(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::CRITICAL, fmt, args...);
return _log_if_enabled(level::critical, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::alert(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::ALERT, fmt, args...);
return _log_if_enabled(level::alert, fmt, args...);
}
template <typename... Args>
inline spdlog::details::line_logger spdlog::logger::emerg(const char* fmt, const Args&... args)
{
return _log_if_enabled(level::EMERG, fmt, args...);
return _log_if_enabled(level::emerg, fmt, args...);
}
......@@ -152,48 +152,48 @@ inline spdlog::details::line_logger spdlog::logger::emerg(const char* fmt, const
inline spdlog::details::line_logger spdlog::logger::trace()
{
return _log_if_enabled(level::TRACE);
return _log_if_enabled(level::trace);
}
inline spdlog::details::line_logger spdlog::logger::debug()
{
return _log_if_enabled(level::DEBUG);
return _log_if_enabled(level::debug);
}
inline spdlog::details::line_logger spdlog::logger::info()
{
return _log_if_enabled(level::INFO);
return _log_if_enabled(level::info);
}
inline spdlog::details::line_logger spdlog::logger::notice()
{
return _log_if_enabled(level::NOTICE);
return _log_if_enabled(level::notice);
}
inline spdlog::details::line_logger spdlog::logger::warn()
{
return _log_if_enabled(level::WARN);
return _log_if_enabled(level::warn);
}
inline spdlog::details::line_logger spdlog::logger::error()
{
return _log_if_enabled(level::ERR);
return _log_if_enabled(level::err);
}
inline spdlog::details::line_logger spdlog::logger::critical()
{
return _log_if_enabled(level::CRITICAL);
return _log_if_enabled(level::critical);
}
inline spdlog::details::line_logger spdlog::logger::alert()
{
return _log_if_enabled(level::ALERT);
return _log_if_enabled(level::alert);
}
inline spdlog::details::line_logger spdlog::logger::emerg()
{
return _log_if_enabled(level::EMERG);
return _log_if_enabled(level::emerg);
}
......@@ -255,7 +255,7 @@ inline void spdlog::logger::_set_formatter(formatter_ptr msg_formatter)
inline void spdlog::logger::_stop()
{
set_level(level::OFF);
set_level(level::off);
}
......
......@@ -130,7 +130,7 @@ public:
void stop_all()
{
std::lock_guard<std::mutex> lock(_mutex);
_level = level::OFF;
_level = level::off;
for (auto& l : _loggers)
l.second->stop();
}
......@@ -149,7 +149,7 @@ private:
std::mutex _mutex;
std::unordered_map <std::string, std::shared_ptr<logger>> _loggers;
formatter_ptr _formatter;
level::level_enum _level = level::INFO;
level::level_enum _level = level::info;
bool _async_mode = false;
size_t _async_q_size = 0;
};
......
......@@ -50,16 +50,16 @@ public:
syslog_sink(const std::string& ident = "", int syslog_option=0, int syslog_facility=LOG_USER):
_ident(ident)
{
_priorities[static_cast<int>(level::TRACE)] = LOG_DEBUG;
_priorities[static_cast<int>(level::DEBUG)] = LOG_DEBUG;
_priorities[static_cast<int>(level::INFO)] = LOG_INFO;
_priorities[static_cast<int>(level::NOTICE)] = LOG_NOTICE;
_priorities[static_cast<int>(level::WARN)] = LOG_WARNING;
_priorities[static_cast<int>(level::ERR)] = LOG_ERR;
_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::OFF)] = LOG_INFO;
_priorities[static_cast<int>(level::trace)] = LOG_DEBUG;
_priorities[static_cast<int>(level::debug)] = LOG_DEBUG;
_priorities[static_cast<int>(level::info)] = LOG_INFO;
_priorities[static_cast<int>(level::notice)] = LOG_NOTICE;
_priorities[static_cast<int>(level::warn)] = LOG_WARNING;
_priorities[static_cast<int>(level::err)] = LOG_ERR;
_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::off)] = LOG_INFO;
//set ident to be program name if empty
::openlog(_ident.empty()? nullptr:_ident.c_str(), syslog_option, syslog_facility);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment