Skip to content

Commit

Permalink
Renamed logger macros
Browse files Browse the repository at this point in the history
Well it wasn't a got idea to use the simple names for the logger macros.
They are all prefixed by eal_ now. Should avoid naming conflicts.

Added a write_log function that doesn't need to be called with file,
line or func information
  • Loading branch information
crapp committed May 20, 2016
1 parent 538b830 commit 27424d5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ Session.vim

doc/html


package
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(ealogger)
# Version Number
set(ealogger_VERSION_MAJOR 0)
set(ealogger_VERSION_MINOR 7)
set(ealogger_VERSION_PATCH 0)
set(ealogger_VERSION_PATCH 1)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

option(BUILD_EXAMPLES "Build example and benchmark applications for ealogger" OFF)
Expand Down
23 changes: 12 additions & 11 deletions examples/ealogger_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ int main(void)
version << "." << EALOGGER_VERSION_PATCH;
}

log->info("This is an ealogger " + version.str() + " example application");
log->debug("A debug message");
log->info("Info was here");
log->warn("Warning");
log->error("Error");
log->fatal("Alert, system in fatal state");
log->eal_info("This is an ealogger " + version.str() +
" example application");
log->eal_debug("A debug message");
log->eal_info("Info was here");
log->eal_warn("Warning");
log->eal_error("Error");
log->eal_fatal("Alert, system in fatal state");

// As we are in async mode you might want to check whether the internal log
// messages queue is empty.
Expand All @@ -52,7 +53,7 @@ int main(void)
log->set_min_lvl(con::LOGGER_SINK::CONSOLES, con::LOG_LEVEL::WARNING);

// this message will not appear in the console
log->info("Info is not visible because minimum severity is WARNING");
log->eal_info("Info is not visible because minimum severity is WARNING");

// wait again
while (!log->queue_empty()) {
Expand All @@ -62,17 +63,17 @@ int main(void)
// set severity to info
log->set_min_lvl(con::LOGGER_SINK::CONSOLES, con::LOG_LEVEL::INFO);
// the next message will be visible again
log->info("This message should be visible in the console");
log->eal_info("This message should be visible in the console");

// change the datetime conversion pattern
log->set_datetime_pattern(con::LOGGER_SINK::CONSOLES, "%A %r");
log->info("You should now see the new datetime conversion pattern");
log->eal_info("You should now see the new datetime conversion pattern");

// change the message template for the console sink
// datetime [file name:"line number" "function name"] severity: log message
log->set_msg_template(con::LOGGER_SINK::CONSOLES, "%d [%f:%l %u] %s: %m");
log->info("You should now see a new message template in use");
log->info("The change will affect all messages currently in the queue");
log->eal_info("You should now see a new message template in use");
log->eal_info("The change will affect all messages currently in the queue");

return 0;
}
2 changes: 1 addition & 1 deletion examples/ealogger_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(void)
std::chrono::system_clock::time_point t = std::chrono::system_clock::now();
// log 1000000 messages
for (int i = 0; i < 1000000; i++) {
log->info("Hello Afrika - Tell me how you're doin'! ");
log->eal_info("Hello Afrika - Tell me how you're doin'! ");
}
// end time. this is to calculate how long it took ealogger to creat LogMessage
// objects and push them on a queue
Expand Down
35 changes: 25 additions & 10 deletions include/ealogger/ealogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,45 +60,45 @@ namespace ealogger

// Define macros for all log levels and call public member write_log()
/**
* @def debug(msg)
* @def eal_debug(msg)
* @brief Write a debug message
*/
#define debug(msg) \
#define eal_debug(msg) \
write_log(msg, ealogger::constants::LOG_LEVEL::DEBUG, __FILE__, __LINE__, \
__func__)
/**
* @def info(msg)
* @def eal_info(msg)
* @brief Write a info message
*/
#define info(msg) \
#define eal_info(msg) \
write_log(msg, ealogger::constants::LOG_LEVEL::INFO, __FILE__, __LINE__, \
__func__)
/**
* @def warn(msg)
* @def eal_warn(msg)
* @brief Write a warning message
*/
#define warn(msg) \
#define eal_warn(msg) \
write_log(msg, ealogger::constants::LOG_LEVEL::WARNING, __FILE__, __LINE__, \
__func__)
/**
* @def error(msg)
* @brief Write an error message
*/
#define error(msg) \
#define eal_error(msg) \
write_log(msg, ealogger::constants::LOG_LEVEL::ERROR, __FILE__, __LINE__, \
__func__)
/**
* @def fatal(msg)
* @brief Write a fatal message
*/
#define fatal(msg) \
#define eal_fatal(msg) \
write_log(msg, ealogger::constants::LOG_LEVEL::FATAL, __FILE__, __LINE__, \
__func__)
/**
* @def stack()
* @def eal_stack()
* @brief Write a message with a stacktrace
*/
#define stack() \
#define eal_stack() \
write_log("", ealogger::constants::LOG_LEVEL::STACK, __FILE__, __LINE__, \
__func__)

Expand Down Expand Up @@ -186,6 +186,21 @@ class Logger
void write_log(std::string msg, ealogger::constants::LOG_LEVEL lvl,
std::string file, int lnumber, std::string func);

/**
* @brief Write a log message
*
* @param msg Message text
* @param lvl Severity of the message, Logger#log_level
*
* @details
* This is an overloaded method of write_log(sd::string, ealogger::constants::LOG_LEVEL, std::string, int, std::string)
* @note
* Using conversion patterns for source file, line number or function with
* this function will not give you the appropriate information as it is not
* available
*/
void write_log(std::string msg, ealogger::constants::LOG_LEVEL lvl);

/**
* @brief Init a syslog Sink
*
Expand Down
5 changes: 5 additions & 0 deletions src/ealogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ void eal::Logger::write_log(std::string msg, con::LOG_LEVEL lvl,
}
}

void eal::Logger::write_log(std::string msg, con::LOG_LEVEL lvl)
{
this->write_log(std::move(msg), lvl, "", 0, "");
}

void eal::Logger::init_syslog_sink(bool enabled, con::LOG_LEVEL min_lvl,
std::string msg_template,
std::string datetime_pattern)
Expand Down

0 comments on commit 27424d5

Please sign in to comment.