20#include "flow/error/error.hpp"
37 bool also_set_os_name)
40 using boost::system::system_category;
41 using ::pthread_setname_np;
50 :
new string(thread_nickname));
56 FLOW_LOG_INFO(
"Set new thread nickname for current thread ID "
57 "[" << util::this_thread::get_id() <<
"].");
63# error "this_thread_set_logged_nickname() also_set_os_name implementation is for Linux only."
70 : string(thread_nickname);
73 constexpr size_t MAX_PTHREAD_NAME_SZ = 15;
74 if (os_name.size() > MAX_PTHREAD_NAME_SZ)
77 os_name.erase(0, os_name.size() - MAX_PTHREAD_NAME_SZ);
80 const auto result_code = pthread_setname_np(pthread_self(), os_name.c_str());
86 if (result_code == -1)
88 const Error_code sys_err_code(errno, system_category());
89 FLOW_LOG_WARNING(
"Unable to set OS thread name to [" << os_name <<
"], possibly truncated from the front "
90 "to [" << MAX_PTHREAD_NAME_SZ <<
"] characters, via pthread_setname_np(). "
91 "This should only occur due to an overlong name, which we guard against, so this is "
92 "highly unexpected. Details follow.");
97 FLOW_LOG_INFO(
"OS thread name has been set to [" << os_name <<
"], possibly truncated from the front "
98 "to [" << MAX_PTHREAD_NAME_SZ <<
"] characters.");
103 assert(result_code != -1);
116 if (this_thread_nickname_ptr)
118 return os << (*this_thread_nickname_ptr);
121 return os << util::this_thread::get_id();
126 assert(call_thread_nickname);
127 assert(call_thread_id);
133 if (this_thread_nickname_ptr)
135 *call_thread_nickname = (*this_thread_nickname_ptr);
139 *call_thread_id = util::this_thread::get_id();
145 assert(msg_metadata);
158 m_payload_type_or_null(0)
181 using std::type_index;
265 assert(
false &&
"Looks like a corrupt/sentinel log::Sev value. gcc would've caught an incomplete switch().");
A light-weight class, each object storing a component payload encoding an enum value from enum type o...
Component & operator=(const Component &src)
Overwrites *this with a copy of src.
unsigned int enum_raw_t
The type Payload must be enum class Payload : enum_raw_t: an enum type encoded via this integer type.
std::type_info const * m_payload_type_or_null
The typeid() of the Payload passed to the 1-arg constructor; if 0-arg ctor was used (empty() is true)...
const std::type_info & payload_type() const
Returns typeid(Payload), where Payload was the template param used when calling the originating one-a...
bool empty() const
Returns true if *this is as if default-constructed (a null Component); false if as if constructed via...
enum_raw_t m_payload_enum_raw_value
The internally stored integer representation of the enum value passed to the 1-arg constructor; meani...
enum_raw_t payload_enum_raw_value() const
Returns the numeric value of the enum payload stored by this Component, originating in the one-arg co...
Component()
Constructs a Component that stores no payload; meaning an unspecified-component Component that return...
std::type_index payload_type_index() const
Convenience accessor that returns std::type_index(payload_type()), which can be used most excellently...
Convenience class that simply stores a Logger and/or Component passed into a constructor; and returns...
Log_context & operator=(const Log_context &src)
Assignment operator that behaves similarly to the copy constructor.
const Component & get_log_component() const
Returns reference to the stored Component object, particularly as many FLOW_LOG_*() macros expect.
void swap(Log_context &other)
Swaps Logger pointers and Component objects held by *this and other.
Component m_component
The held Component object. Making the object non-const to allow operator=() to work.
Log_context(Logger *logger=0)
Constructs Log_context by storing the given pointer to a Logger and a null Component.
Logger * m_logger
The held Logger pointer. Making the pointer itself non-const to allow operator=() to work.
Logger * get_logger() const
Returns the stored Logger pointer, particularly as many FLOW_LOG_*() macros expect.
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
static void set_thread_info(std::string *call_thread_nickname, flow::util::Thread_id *call_thread_id)
Same as set_thread_info_in_msg_metadata() but targets the given two variables as opposed to a Msg_met...
static void set_thread_info_in_msg_metadata(Msg_metadata *msg_metadata)
Loads msg_metadata->m_call_thread_nickname (if set) or else msg_metadata->m_call_thread_id,...
static boost::thread_specific_ptr< std::string > s_this_thread_nickname_ptr
Thread-local storage for each thread's logged name (null pointer, which is default,...
static void this_thread_set_logged_nickname(util::String_view thread_nickname=util::String_view(), Logger *logger_ptr=0, bool also_set_os_name=true)
Sets or unsets the current thread's logging-worthy string name; optionally sets the OS thread name (s...
static std::ostream & this_thread_logged_name_os_manip(std::ostream &os)
ostream manipulator function that, if output via operator<< to an ostream, will cause the current thr...
std::ostream * this_thread_ostream() const
Returns the stream dedicated to the executing thread and this Logger, so that the caller can apply st...
static Thread_local_string_appender * get_this_thread_string_appender(const util::Unique_id_holder &source_obj_id)
Returns a pointer to the exactly one Thread_local_string_appender object that is accessible from the ...
std::ostream * appender_ostream()
Same as fresh_appender_ostream() but does not clear the result string, enabling piecemeal writing to ...
#define FLOW_ERROR_SYS_ERROR_LOG_WARNING()
Logs a warning about the (often errno-based or from a library) error code in sys_err_code.
#define FLOW_LOG_INFO(ARG_stream_fragment)
Logs an INFO message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
#define FLOW_LOG_WARNING(ARG_stream_fragment)
Logs a WARNING message into flow::log::Logger *get_logger() with flow::log::Component get_log_compone...
#define FLOW_LOG_SET_CONTEXT(ARG_logger_ptr, ARG_component_payload)
For the rest of the block within which this macro is instantiated, causes all FLOW_LOG_....
Flow module providing logging functionality.
std::ostream & operator<<(std::ostream &os, Sev val)
Serializes a log::Sev to a standard output stream.
void swap(Log_context &val1, Log_context &val2)
Log_context ADL-friendly swap: Equivalent to val1.swap(val2).
size_t deep_size(const Msg_metadata &val)
Estimate of memory footprint of the given value, including memory allocated on its behalf – but exclu...
std::istream & operator>>(std::istream &is, Sev &val)
Deserializes a log::Sev from a standard input stream.
Sev
Enumeration containing one of several message severity levels, ordered from highest to lowest.
@ S_DATA
Message satisfies Sev::S_TRACE description AND contains variable-length structure (like packet,...
@ S_TRACE
Message indicates any condition that may occur with great frequency (thus verbose if logged).
@ S_WARNING
Message indicates a "bad" condition that is not frequent enough to be of severity Sev::S_TRACE.
@ S_END_SENTINEL
Not an actual value but rather stores the highest numerical payload, useful for validity checks.
@ S_NONE
Sentinel log level that must not be specified for any actual message (at risk of undefined behavior s...
@ S_DEBUG
Message indicates a condition with, perhaps, no significant perf impact if enabled (like Sev::S_INFO)...
@ S_ERROR
Message indicates a "bad" condition with "worse" impact than that of Sev::S_WARNING.
@ S_INFO
Message indicates a not-"bad" condition that is not frequent enough to be of severity Sev::S_TRACE.
@ S_FATAL
Message indicates a "fatally bad" condition, such that the program shall imminently abort,...
void beautify_chrono_logger_this_thread(Logger *logger_ptr)
Sets certain chrono-related formatting on the given Logger in the current thread that results in a co...
boost::thread_specific_ptr< Msg_metadata > this_thread_sync_msg_metadata_ptr
Thread-local Msg_metadata object used by FLOW_LOG_WITHOUT_CHECKING() for an alleged perf bonus in the...
void beautify_chrono_ostream(std::ostream *os_ptr)
Sets certain chrono-related formatting on the given ostream that results in a consistent,...
Thread::id Thread_id
Short-hand for an OS-provided ID of a util::Thread.
Enum istream_to_enum(std::istream *is_ptr, Enum enum_default, Enum enum_sentinel, bool accept_num_encoding, bool case_sensitive, Enum enum_lowest)
Deserializes an enum class value from a standard input stream.
size_t deep_size(const std::string &val)
Estimate of memory footprint of the given value, including memory allocated on its behalf – but exclu...
std::string ostream_op_string(T const &... ostream_args)
Equivalent to ostream_op_to_string() but returns a new string by value instead of writing to the call...
Basic_string_view< char > String_view
Commonly used char-based Basic_string_view. See its doc header.
boost::system::error_code Error_code
Short-hand for a boost.system error code (which basically encapsulates an integer/enum error code and...