mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 10:23:50 +01:00
LOG_F changed to LOGF
Added #error to define checks
This commit is contained in:
parent
fa9e5b4adf
commit
9dbc9023fc
@ -87,14 +87,14 @@ if (false == (boolean_expression))
|
||||
For flags, width, precision etc please see the above references.
|
||||
EXAMPLES:
|
||||
{
|
||||
LOG_F(INFO, "Characters: %c %c \n", 'a', 65);
|
||||
LOG_F(INFO, "Decimals: %d %ld\n", 1977, 650000L); // printing long
|
||||
LOG_F(INFO, "Preceding with blanks: %10d \n", 1977);
|
||||
LOG_F(INFO, "Preceding with zeros: %010d \n", 1977);
|
||||
LOG_F(INFO, "Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
|
||||
LOG_F(INFO, "floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
|
||||
LOG_F(INFO, "Width trick: %*d \n", 5, 10);
|
||||
LOG_F(INFO, "%s \n", "A string");
|
||||
LOGF(INFO, "Characters: %c %c \n", 'a', 65);
|
||||
LOGF(INFO, "Decimals: %d %ld\n", 1977, 650000L); // printing long
|
||||
LOGF(INFO, "Preceding with blanks: %10d \n", 1977);
|
||||
LOGF(INFO, "Preceding with zeros: %010d \n", 1977);
|
||||
LOGF(INFO, "Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
|
||||
LOGF(INFO, "floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
|
||||
LOGF(INFO, "Width trick: %*d \n", 5, 10);
|
||||
LOGF(INFO, "%s \n", "A string");
|
||||
return 0;
|
||||
}
|
||||
And here is possible output
|
||||
@ -106,17 +106,17 @@ And here is possible output
|
||||
: floats: 3.14 +3e+000 3.141600E+000
|
||||
: Width trick: 10
|
||||
: A string \endverbatim */
|
||||
#define G2_LOG_F_INFO g2::internal::LogMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,"INFO")
|
||||
#define G2_LOG_F_DEBUG g2::internal::LogMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,"DEBUG")
|
||||
#define G2_LOG_F_WARNING g2::internal::LogMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,"WARNING")
|
||||
#define G2_LOG_F_FATAL g2::internal::LogContractMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,k_fatal_log_expression)
|
||||
#define G2_LOGF_INFO g2::internal::LogMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,"INFO")
|
||||
#define G2_LOGF_DEBUG g2::internal::LogMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,"DEBUG")
|
||||
#define G2_LOGF_WARNING g2::internal::LogMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,"WARNING")
|
||||
#define G2_LOGF_FATAL g2::internal::LogContractMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__,k_fatal_log_expression)
|
||||
|
||||
// LOG_F(level,msg,...) is the API for the "printf" like log
|
||||
#define LOG_F(level, printf_like_message, ...) \
|
||||
G2_LOG_F_##level.messageSave(printf_like_message, __VA_ARGS__);
|
||||
// LOGF(level,msg,...) is the API for the "printf" like log
|
||||
#define LOGF(level, printf_like_message, ...) \
|
||||
G2_LOGF_##level.messageSave(printf_like_message, __VA_ARGS__);
|
||||
|
||||
// conditional log printf syntax
|
||||
#define LOG_F_IF(level,boolean_expression, printf_like_message, ...) \
|
||||
#define LOGF_IF(level,boolean_expression, printf_like_message, ...) \
|
||||
if(true == boolean_expression) \
|
||||
G2_LOG_##level.messageSave(printf_like_message, __VA_ARGS__);
|
||||
|
||||
|
@ -24,7 +24,7 @@ int main(int argc, char** argv)
|
||||
std::cout << "****** please see g2log/src/main.cpp and he finished log file to " << std::endl;
|
||||
std::cout << "****** follow what is done in this example\n\n" << std::endl;
|
||||
|
||||
LOG_F(INFO, "Hi log %d", 123);
|
||||
LOGF(INFO, "Hi log %d", 123);
|
||||
LOG(INFO) << "Test SLOG INFO";
|
||||
LOG(DEBUG) << "Test SLOG DEBUG";
|
||||
LOG(INFO) << "one: " << 1;
|
||||
@ -34,32 +34,32 @@ int main(int argc, char** argv)
|
||||
LOG(DEBUG) << "pi double: " << pi_d;
|
||||
LOG(DEBUG) << "pi float: " << pi_f;
|
||||
LOG(DEBUG) << "pi float (width 10): " << std::setprecision(10) << pi_f;
|
||||
LOG_F(INFO, "pi float printf:%f", pi_f);
|
||||
LOGF(INFO, "pi float printf:%f", pi_f);
|
||||
|
||||
//
|
||||
// START: LOG Entris that were in the article
|
||||
//
|
||||
//LOG(UNKNOWN_LEVEL) << "This log attempt will cause a compiler error";
|
||||
LOG(INFO) << "Simple to use with streaming syntax, easy as abc or " << 123;
|
||||
LOG_F(WARNING, "Printf-style syntax is also %s", "available");
|
||||
LOGF(WARNING, "Printf-style syntax is also %s", "available");
|
||||
// ....
|
||||
try
|
||||
{
|
||||
LOG_F(FATAL, "FATAL has a special meaning. This %s will throw an exception", "message");
|
||||
LOGF(FATAL, "FATAL has a special meaning. This %s will throw an exception", "message");
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cout << "\n **** All good expected the 'FATAL has a special meaning' runtime exception\n\n\n" << std::endl;
|
||||
}
|
||||
LOG_IF(INFO, (1 < 2)) << "If true this text will be logged";
|
||||
LOG_F_IF(INFO, (1<2), "if %d<%d : then this text will be logged", 1,2);
|
||||
LOGF_IF(INFO, (1<2), "if %d<%d : then this text will be logged", 1,2);
|
||||
LOG_IF(FATAL, (2>3)) << "This message should NOT throw";
|
||||
LOG_F(DEBUG, "This API is popular with some %s", "programmers");
|
||||
LOG_F_IF(DEBUG, (1<2), "If true, then this %s will be logged", "message");
|
||||
LOGF(DEBUG, "This API is popular with some %s", "programmers");
|
||||
LOGF_IF(DEBUG, (1<2), "If true, then this %s will be logged", "message");
|
||||
{
|
||||
const std::string logging = "logging";
|
||||
// OK --- this WILL get a compiler warning
|
||||
LOG_F(DEBUG, "Printf-type %s is the number 1 for many %s", logging.c_str());
|
||||
LOGF(DEBUG, "Printf-type %s is the number 1 for many %s", logging.c_str());
|
||||
}
|
||||
CHECK(1 != 2); // true: won't throw
|
||||
try
|
||||
|
@ -14,7 +14,7 @@ const std::string title = "G2LOG";
|
||||
#elif defined(GOOGLE_GLOG_PERFORMANCE)
|
||||
const std::string title = "GOOGLE__GLOG";
|
||||
#else
|
||||
const std::string title = not_defined_this_will_be_compiler_error;
|
||||
#error G2LOG_PERFORMANCE or GOOGLE_GLOG_PERFORMANCE was not defined
|
||||
#endif
|
||||
|
||||
const std::string g_prefix_log_name = title + "-performance-2threads-MEAN_LOG";
|
||||
@ -22,9 +22,6 @@ const std::string g_measurement_dump= "/tmp/" + g_prefix_log_name + "_RESULT.tx
|
||||
const std::string g_path = "/tmp/";
|
||||
using namespace g2_test;
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
@ -19,7 +19,7 @@ const std::string title = "G2LOG";
|
||||
#elif defined(GOOGLE_GLOG_PERFORMANCE)
|
||||
const std::string title = "GOOGLE__GLOG";
|
||||
#else
|
||||
const std::string title = not_defined_this_will_be_compiler_error;
|
||||
#error G2LOG_PERFORMANCE or GOOGLE_GLOG_PERFORMANCE was not defined
|
||||
#endif
|
||||
|
||||
const std::string g_prefix_log_name = title + "-performance-2threads-WORST_LOG";
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "logworker.h"
|
||||
#elif defined(GOOGLE_GLOG_PERFORMANCE)
|
||||
#include <glog/logging.h>
|
||||
#else
|
||||
#error G2LOG_PERFORMANCE or GOOGLE_GLOG_PERFORMANCE was not defined
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -106,9 +106,9 @@ TEST(LogTest, LOG_F)
|
||||
std::string file_content;
|
||||
{
|
||||
RestoreLogger logger;
|
||||
LOG_F(INFO, std::string(t_info + "%d").c_str(), 123);
|
||||
LOG_F(DEBUG, std::string(t_debug + "%f").c_str(), 1.123456);
|
||||
LOG_F(WARNING, std::string(t_warning + "%s").c_str(), "yello");
|
||||
LOGF(INFO, std::string(t_info + "%d").c_str(), 123);
|
||||
LOGF(DEBUG, std::string(t_debug + "%f").c_str(), 1.123456);
|
||||
LOGF(WARNING, std::string(t_warning + "%s").c_str(), "yello");
|
||||
logger.reset(); // force flush of logger
|
||||
file_content = readFileToText(logger.log_file_);
|
||||
SCOPED_TRACE("LOG_INFO"); // Scope exit be prepared for destructor failure
|
||||
@ -142,8 +142,8 @@ TEST(LogTest, LOG_F_IF)
|
||||
std::string file_content;
|
||||
{
|
||||
RestoreLogger logger;
|
||||
LOG_F_IF(INFO, (2 == 2), std::string(t_info + "%d").c_str(), 123);
|
||||
LOG_F_IF(DEBUG, (2 != 2), std::string(t_debug + "%f").c_str(), 1.123456);
|
||||
LOGF_IF(INFO, (2 == 2), std::string(t_info + "%d").c_str(), 123);
|
||||
LOGF_IF(DEBUG, (2 != 2), std::string(t_debug + "%f").c_str(), 1.123456);
|
||||
logger.reset(); // force flush of logger
|
||||
file_content = readFileToText(logger.log_file_);
|
||||
SCOPED_TRACE("LOG_IF"); // Scope exit be prepared for destructor failure
|
||||
@ -167,12 +167,12 @@ TEST(LogTest, LOG_IF)
|
||||
ASSERT_FALSE(verifyContent(file_content, t_debug2));
|
||||
}
|
||||
|
||||
TEST(LogTest, LOG_F__FATAL)
|
||||
TEST(LogTest, LOGF__FATAL)
|
||||
{
|
||||
RestoreLogger logger;
|
||||
try
|
||||
{
|
||||
LOG_F(FATAL, "This message should throw %d",0);
|
||||
LOGF(FATAL, "This message should throw %d",0);
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
@ -221,12 +221,12 @@ TEST(LogTest, LOG_FATAL)
|
||||
}
|
||||
|
||||
|
||||
TEST(LogTest, LOG_F_IF__FATAL)
|
||||
TEST(LogTest, LOGF_IF__FATAL)
|
||||
{
|
||||
RestoreLogger logger;
|
||||
try
|
||||
{
|
||||
LOG_F_IF(FATAL, (2<3), "This message%sshould throw"," ");
|
||||
LOGF_IF(FATAL, (2<3), "This message%sshould throw"," ");
|
||||
}
|
||||
catch (std::exception const &e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user