Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions doc/logs_doc.doxy
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@
* - {TYPE} To display here the type of the log.
* - {DATE} To display here the date of the log.
* - {THREAD} To display here the emiter thread number (only if -pthread or -fopenmp).
*
* @fn void mlog::Options::bindThreadName(const std::thread::id& id, const std::string& name)
* Binds the thread id to the name so that when using the tag
* {THREAD} the name given is used instead of an hexadecimal output
*
* @param[in] id The identifier returned by std::thread::get_id()
* @param[in] name Name that should be displayed instead of an id
* @see mlog::Options::unbidThreadName

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same story here, unbid instead of unbind.

*
* @fn void mlog::Options::unbidThreadName(const std::thread::id& id)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A n is missing right here, (unbid instead of unbind), please add it in order to get consistent documentation.

* Unbinds the thread id if it exists. This way, using the {THREAD}
* tag will print the thread id
*
* @param[in] id The identifier returned by std::thread::get_id()
* @see mlog::Options::bidThreadName

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bid instead of bind

*/

// Developpers part, enable HIDE_THIS_DOXYGEN to see it
Expand Down Expand Up @@ -411,6 +426,11 @@
* @var mlog::__details::__Static_declarer::FORMAT
* The header format (<b>"[{TYPE} {DATE}] : "</b> by default).
*
* @var mlog::__details::__Static_declarer::THREAD_NAME
* The container for bounds between thread id and a string value
* @see mlog::Options::bindThreadName
* @see mlog::Options::unbidThreadName

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again.

*
* @var mlog::__details::__Static_declarer::MUTEX
* A mutex to guaranty mutual exclusion for logging.
* Only if multithreading explicitly enabled (-pthread or -fopenmp).
Expand Down
39 changes: 35 additions & 4 deletions logs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <utility>
#include <vector>
#include <map>

// if -pthread or -fopenmp provided only
#ifdef _REENTRANT
Expand Down Expand Up @@ -85,8 +86,11 @@ namespace MTL_LOG_NAMESPACE
return this->pattern;
}
void display(std::ostream& out, const std::string& type, const char *const color,
const char *const nocolor, bool colorEnabled)
const char *const nocolor, bool colorEnabled, const void* threads_names)
{
# ifdef _REENTRANT

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MTL_LOG_WITh_THREADS

const std::map<std::thread::id, std::string>* thread = reinterpret_cast<const std::map<std::thread::id, std::string>*>(threads_names);
# endif
for(const auto& p : this->chunks)
{
switch(p.first)
Expand All @@ -110,8 +114,15 @@ namespace MTL_LOG_NAMESPACE
break;
}
case -3:
# ifdef MTL_LOG_WITH_THREADS
out << "0x" << std::hex << std::this_thread::get_id() << std::dec;
# ifdef _REENTRANT

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use MTL_LOG_WITH_THREADS macro instead of _REENTRANT.

try
{
out << (*thread).at(std::this_thread::get_id());
}
catch (const std::out_of_range&)
{
out << "0x" << std::hex << std::this_thread::get_id() << std::dec;
}
# endif
break;
case -2:
Expand Down Expand Up @@ -191,6 +202,9 @@ namespace MTL_LOG_NAMESPACE
static bool ENABLE_ALPHA_BOOL;
static MTL_LOG_NAMESPACE::__details::__Header FORMAT;

# ifdef _REENTRANT

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MTL_LOG_WITH_THREADS instead of _REENTRANT

static std::map<std::thread::id, std::string> THREAD_NAME;
# endif
private:
# ifdef MTL_LOG_WITH_THREADS
static std::mutex MUTEX;
Expand Down Expand Up @@ -220,6 +234,7 @@ namespace MTL_LOG_NAMESPACE
STATIC_DECLARATION(bool, ENABLE_ALPHA_BOOL, true)
# ifdef MTL_LOG_WITH_THREADS
template<typename T> std::mutex __Static_declarer<T>::MUTEX;
template<typename T> std::map<std::thread::id, std::string> __Static_declarer<T>::THREAD_NAME = {};
# endif
STATIC_DECLARATION(MTL_LOG_NAMESPACE::__details::__Header, FORMAT, std::string("[{TYPE} {DATE} {TIME}] : "))
# undef STATIC_DECLARATION
Expand Down Expand Up @@ -277,6 +292,16 @@ namespace MTL_LOG_NAMESPACE
MTL_LOG_LOCK;
return MTL_LOG_NAMESPACE::Options::FORMAT;
}
# ifdef _REENTRANT

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MTL_LOG_WITH_THREADS

static void bindThreadName(const std::thread::id& id, const std::string& name)
{
MTL_LOG_NAMESPACE::Options::THREAD_NAME.insert(std::make_pair(id, name));
}
static void unbidThreadName(const std::thread::id& id)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unbid instead of unbind

{
MTL_LOG_NAMESPACE::Options::THREAD_NAME.erase(id);
}
# endif
};

# undef MTL_LOG_GET_SET
Expand Down Expand Up @@ -329,7 +354,13 @@ namespace MTL_LOG_NAMESPACE
MTL_LOG_NAMESPACE::Options::FORMAT.display(*MTL_LOG_NAMESPACE::Options::OUT,
tag, color,
MTL_LOG_NAMESPACE::Options::C_BLANK,
MTL_LOG_NAMESPACE::Options::isColorEnabled());
MTL_LOG_NAMESPACE::Options::isColorEnabled(),
# ifdef _REENTRANT

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MTL_LOG_WITH_THREADS

&MTL_LOG_NAMESPACE::Options::THREAD_NAME
# else
nullptr
# endif
);
}
MTL_LOG_NAMESPACE::__details::_Logger::_print_(args...);
}
Expand Down