Boost C++ Libraries

PrevUpHomeNext

Class current_thread_id

boost::log::attributes::current_thread_id — A class of an attribute that always returns the current thread identifier.

Synopsis

// In header: <boost/log/attributes/current_thread_id.hpp>


class current_thread_id : public attribute, public attribute_value {
public:
  // types
  typedef thread::id held_type;  // A held attribute value type. 

  // public member functions
  bool dispatch(type_dispatcher &);
  shared_ptr< attribute_value > get_value();
  shared_ptr< attribute_value > detach_from_thread();
};

Description

[Note] Note

This attribute may be registered globally, it will still return the correct thread identifier no matter which thread emits the log record.

current_thread_id public member functions

  1. bool dispatch(type_dispatcher & dispatcher);

    The method dispatches the value to the given object.

    Parameters:
    dispatcher

    The object that attempts to dispatch the stored value.

    Returns:

    true if dispatcher was capable to consume the real attribute value type and false otherwise.

  2. shared_ptr< attribute_value > get_value();

    Returns:

    The actual attribute value. It shall not return NULL (exceptions shall be used to indicate errors).

  3. shared_ptr< attribute_value > detach_from_thread();

    The method is called when the attribute value is passed to another thread (e.g. in case of asynchronous logging). The value should ensure it properly owns all thread-specific data.

    Returns:

    An actual pointer to the attribute value. It may either point to this object or another. In the latter case the returned pointer replaces the pointer used by caller to invoke this method and is considered to be a functional equivalent to the previous pointer.


PrevUpHomeNext