DEPRECATED: operator<< API

This commit is contained in:
gabime 2016-07-03 03:43:55 +03:00
parent 70d0e87328
commit 5650f10bab
10 changed files with 32 additions and 62 deletions

View File

@ -69,7 +69,6 @@ int main(int, char* [])
auto console = spd::stdout_logger_mt("console", true); auto console = spd::stdout_logger_mt("console", true);
console->info("Welcome to spdlog!") ; console->info("Welcome to spdlog!") ;
console->info("An info message example {}..", 1); console->info("An info message example {}..", 1);
console->info() << "Streams are supported too " << 1;
//Formatting examples //Formatting examples
console->info("Easy padding in numbers like {:08d}", 12); console->info("Easy padding in numbers like {:08d}", 12);
@ -129,7 +128,7 @@ int main(int, char* [])
size_t q_size = 8192; //queue size must be power of 2 size_t q_size = 8192; //queue size must be power of 2
spdlog::set_async_mode(q_size); spdlog::set_async_mode(q_size);
auto async_file= spd::daily_logger_st("async_file_logger", "logs/async_log.txt"); auto async_file= spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
async_file->info() << "This is async log.." << "Should be very fast!"; async_file->info("This is async log..Should be very fast!");
// //
// syslog example. linux only.. // syslog example. linux only..
@ -148,16 +147,6 @@ int main(int, char* [])
} }
// Example of user defined class with operator<<
class some_class {};
std::ostream& operator<<(std::ostream& os, const some_class& c) { return os << "some_class"; }
void custom_class_example()
{
some_class c;
spdlog::get("console")->info("custom class with operator<<: {}..", c);
spdlog::get("console")->info() << "custom class with operator<<: " << c << "..";
}
``` ```
## Documentation ## Documentation

View File

@ -41,7 +41,7 @@ int main(int argc, char* argv[])
{ {
int counter = ++msg_counter; int counter = ++msg_counter;
if (counter > howmany) break; if (counter > howmany) break;
logger->info() << "spdlog message #" << counter << ": This is some text for your pleasure"; logger->info("spdlog message #{}: This is some text for your pleasure", counter);
} }
})); }));
} }

View File

@ -38,7 +38,7 @@ int main(int argc, char* argv[])
{ {
int counter = ++msg_counter; int counter = ++msg_counter;
if (counter > howmany) break; if (counter > howmany) break;
logger->info() << "spdlog message #" << counter << ": This is some text for your pleasure"; logger->info("spdlog message #{}: This is some text for your pleasure", counter);
} }
})); }));
} }

View File

@ -15,6 +15,6 @@ int main(int, char* [])
logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
for(int i = 0 ; i < howmany; ++i) for(int i = 0 ; i < howmany; ++i)
logger->info() << "spdlog message #" << i << ": This is some text for your pleasure"; logger->info("spdlog message #{} : This is some text for your pleasure", i);
return 0; return 0;
} }

View File

@ -23,7 +23,6 @@ int main(int, char*[])
auto console = spd::stdout_logger_mt("console", true); auto console = spd::stdout_logger_mt("console", true);
console->info("Welcome to spdlog!"); console->info("Welcome to spdlog!");
console->info("An info message example {}..", 1); console->info("An info message example {}..", 1);
console->info() << "Streams are supported too " << 1;
// Formatting examples // Formatting examples
console->info("Easy padding in numbers like {:08d}", 12); console->info("Easy padding in numbers like {:08d}", 12);
@ -55,6 +54,7 @@ int main(int, char*[])
// Create a daily logger - a new file is created every day on 2:30am // Create a daily logger - a new file is created every day on 2:30am
auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily", 2, 30); auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily", 2, 30);
daily_logger->info(123.44);
// Customize msg format for all messages // Customize msg format for all messages
spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***"); spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***");
@ -107,17 +107,3 @@ void syslog_example()
} }
// Example of user defined class with operator<<
class some_class {};
std::ostream& operator<<(std::ostream& os, const some_class&)
{
return os << "some_class";
}
void custom_class_example()
{
some_class c;
spdlog::get("console")->info("custom class with operator<<: {}..", c);
spdlog::get("console")->info() << "custom class with operator<<: " << c << "..";
}

View File

@ -27,6 +27,14 @@
#define SPDLOG_CONSTEXPR constexpr #define SPDLOG_CONSTEXPR constexpr
#endif #endif
#if defined(__GNUC__) || defined(__clang__)
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#else
#pragma message("DEPRECATED")
#define DEPRECATED
#endif
namespace spdlog namespace spdlog
{ {

View File

@ -49,21 +49,21 @@ public:
// //
// Support for operator<< // Support for operator<<
// //
line_logger& operator<<(const char* what); DEPRECATED line_logger& operator<<(const char* what);
line_logger& operator<<(const std::string& what); DEPRECATED line_logger& operator<<(const std::string& what);
line_logger& operator<<(int what); DEPRECATED line_logger& operator<<(int what);
line_logger& operator<<(unsigned int what); DEPRECATED line_logger& operator<<(unsigned int what);
line_logger& operator<<(long what); DEPRECATED line_logger& operator<<(long what);
line_logger& operator<<(unsigned long what); DEPRECATED line_logger& operator<<(unsigned long what);
line_logger& operator<<(long long what); DEPRECATED line_logger& operator<<(long long what);
line_logger& operator<<(unsigned long long what); DEPRECATED line_logger& operator<<(unsigned long long what);
line_logger& operator<<(double what); DEPRECATED line_logger& operator<<(double what);
line_logger& operator<<(long double what); DEPRECATED line_logger& operator<<(long double what);
line_logger& operator<<(float what); DEPRECATED line_logger& operator<<(float what);
line_logger& operator<<(char what); DEPRECATED line_logger& operator<<(char what);
//Support user types which implements operator<< //Support user types which implements operator<<
template<typename T> template<typename T>
line_logger& operator<<(const T& what); DEPRECATED line_logger& operator<<(const T& what);
void disable(); void disable();
bool is_enabled() const; bool is_enabled() const;

View File

@ -74,7 +74,7 @@ inline spdlog::details::line_logger spdlog::logger::_log_if_enabled(level::level
{ {
bool msg_enabled = should_log(lvl); bool msg_enabled = should_log(lvl);
details::line_logger l(this, lvl, msg_enabled); details::line_logger l(this, lvl, msg_enabled);
l << msg; l.write("{}", msg);
return l; return l;
} }

View File

@ -11,7 +11,7 @@ std::string log_info(const T& what, spdlog::level::level_enum logger_level = spd
spdlog::logger oss_logger("oss", oss_sink); spdlog::logger oss_logger("oss", oss_sink);
oss_logger.set_level(logger_level); oss_logger.set_level(logger_level);
oss_logger.set_pattern("%v"); oss_logger.set_pattern("%v");
oss_logger.info() << what; oss_logger.info(what);
return oss.str().substr(0, oss.str().length() - spdlog::details::os::eol_size); return oss.str().substr(0, oss.str().length() - spdlog::details::os::eol_size);
} }
@ -21,19 +21,6 @@ std::string log_info(const T& what, spdlog::level::level_enum logger_level = spd
//User defined class with operator<<
struct some_logged_class
{
some_logged_class(const std::string val) :value(val) {};
std::string value;
};
std::ostream& operator<<(std::ostream& os, const some_logged_class& c)
{
return os << c.value;
}
TEST_CASE("basic_logging ", "[basic_logging]") TEST_CASE("basic_logging ", "[basic_logging]")
{ {
//const char //const char
@ -49,7 +36,7 @@ TEST_CASE("basic_logging ", "[basic_logging]")
REQUIRE(log_info(5.6) == "5.6"); REQUIRE(log_info(5.6) == "5.6");
//User defined class //User defined class
REQUIRE(log_info(some_logged_class("some_val")) == "some_val"); //REQUIRE(log_info(some_logged_class("some_val")) == "some_val");
} }

View File

@ -26,7 +26,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
@ -38,7 +38,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>