49 bool use_worker_thread)
51 m_log_level(log_level),
52 m_time_format(
"%Y-%m-%d %H:%M:%S"),
53 m_use_worker_thread(use_worker_thread),
54 m_no_worker_thread_push_mutex(1),
60 icl_core::config::get<icl_core::String>(config_prefix +
"/Format", log_format);
66 icl_core::config::get<icl_core::ThreadPriority>(config_prefix +
"/ThreadPriority", priority);
68 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 70 icl_core::config::get<size_t>(config_prefix +
"/MesageQueueSize", message_queue_size);
85 bool use_worker_thread)
97 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 116 std::cerr <<
"WARNING: Destroyed LogOutputStream while thread is still alive. " 117 <<
"Please call Shutdown() before destruction." <<
std::endl;
144 const char* log_stream_description,
const char *filename,
145 int line,
const char *classname,
const char *objectname,
146 const char *
function,
const char *text)
151 filename, line, classname, objectname,
function, text);
158 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 186 std::stringstream msg;
199 if (std::strcmp(log_message.
class_name,
"") != 0)
209 msg << it->text << log_message.
object_name << it->suffix;
233 msg << log_message.
line;
248 char time_buffer[100];
249 memset(time_buffer, 0, 100);
283 for (
size_t i = it->width; i > msec_len; --i)
300 std::cerr <<
"LOG OUTPUT STREAM ERROR: pushImpl() is not implemented!!!" <<
std::endl;
310 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 315 void LogOutputStream::ChangeTimeFormat(
const char* format)
323 void LogOutputStream::ChangeLogFormat(
const char *format)
332 const char *log_stream_description,
const char *filename,
333 int line,
const char *classname,
const char *objectname,
334 const char *
function,
const char *text)
336 push(log_level, log_stream_description, filename, line, classname, objectname,
function, text);
342 void LogOutputStream::Start()
351 void LogOutputStream::Shutdown()
385 void LogOutputStream::PrintConfiguration()
const 398 if (format[0] ==
'~')
403 while (format[0] != 0 && std::isdigit(format[0]))
405 new_entry.
width = 10 * new_entry.
width + (format[0] -
'0');
410 char *prefix_ptr = new_entry.
text;
411 while (format[0] != 0 && format[0] !=
'C' && format[0] !=
'O' && format[0] !=
'D' 412 && format[0] !=
'E' && format[0] !=
'F' && format[0] !=
'G' && format[0] !=
'L' 413 && format[0] !=
'S' && format[0] !=
'T' && format[0] !=
'M')
415 *prefix_ptr = format[0];
421 if (format[0] ==
'C')
425 else if (format[0] ==
'O')
428 if (new_entry.
text[0] ==
'(')
430 std::strncpy(new_entry.
suffix,
")", 100);
432 else if (new_entry.
text[0] ==
'[')
434 std::strncpy(new_entry.
suffix,
"]", 100);
436 else if (new_entry.
text[0] ==
'{')
438 std::strncpy(new_entry.
suffix,
"}", 100);
441 else if (format[0] ==
'D')
445 else if (format[0] ==
'E')
449 else if (format[0] ==
'F')
453 else if (format[0] ==
'G')
457 else if (format[0] ==
'L')
461 else if (format[0] ==
'S')
465 else if (format[0] ==
'T')
469 else if (format[0] ==
'M')
483 char *text_ptr = new_entry.
text;
484 while (format[0] !=
'~' && format[0] != 0)
486 *text_ptr = format[0];
491 if (new_entry.
text[0] != 0)
529 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 533 m_output_stream(output_stream),
534 m_message_queue_size(message_queue_size),
535 m_message_queue_write_index(0),
536 m_message_queue_read_index(0)
538 m_message_queue =
new LogMessage[message_queue_size+1];
546 m_output_stream(output_stream)
557 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 571 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 572 if (!isMessageQueueEmpty())
581 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 582 if (!isMessageQueueEmpty())
585 incrementIndex(m_message_queue_read_index);
616 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 617 while (!isMessageQueueEmpty())
620 incrementIndex(m_message_queue_read_index);
639 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE 640 void LogOutputStream::WorkerThread::incrementIndex(
size_t& index)
643 if (index >= m_message_queue_size)
649 bool LogOutputStream::WorkerThread::isMessageQueueEmpty()
651 return m_message_queue_read_index == m_message_queue_write_index;
654 bool LogOutputStream::WorkerThread::isMessageQueueFull()
656 return ((m_message_queue_write_index == m_message_queue_read_index - 1)
657 || (m_message_queue_write_index == m_message_queue_size - 1
658 && m_message_queue_read_index == 0));
664 const char *log_stream,
const char *filename,
665 size_t line,
const char *class_name,
666 const char *object_name,
const char *function_name,
667 const char *message_text)
668 : timestamp(timestamp),
669 log_level(log_level),
void post()
Increments the semaphore.
Represents absolute times.
icl_core::TimeStamp timestamp
MessageQueue m_message_queue
const size_t cMAX_IDENTIFIER_LENGTH
const size_t cMAX_DESCRIPTION_LENGTH
Contains icl_logging::ThreadStream.
Contains icl_logging::LoggingManager.
Contains global functions for string manipulation, encapsulated into the icl_core::os namespace...
int64_t days() const
Use this function if you want to express the time in days.
char filename[cMAX_DESCRIPTION_LENGTH+1]
void changeTimeFormat(const char *format)
void setLogLevel(icl_core::logging::LogLevel log_level)
WorkerThread * m_worker_thread
void strfLocaltime(char *dest, size_t max_len, const char *format) const
static LoggingManager & instance()
void start()
Starts the worker thread of the log output stream.
LogOutputStream * m_output_stream
#define cDEFAULT_FIXED_OUTPUT_STREAM_QUEUE_SIZE
Base header file for the configuration framework.
icl_core::logging::LogLevel getLogLevel() const
void push(icl_core::logging::LogLevel log_level, const char *log_stream_description, const char *filename, int line, const char *classname, const char *objectname, const char *function, const char *text)
#define ICL_CORE_VC_DEPRECATE_STYLE_USE(arg)
icl_core::logging::LogLevel log_level
icl_core::List< LogFormatEntry > m_new_log_format
Contains a system independet PRINTF macro.
int usleep(unsigned long useconds)
icl_core::List< LogFormatEntry > m_log_format
icl_core::logging::LogLevel m_log_level
Semaphore m_no_worker_thread_push_mutex
LogMessage(const icl_core::TimeStamp ×tamp=icl_core::TimeStamp(), icl_core::logging::LogLevel log_level=eLL_MUTE, const char *log_stream="", const char *filename="", size_t line=0, const char *class_name="", const char *object_name="", const char *function_name="", const char *message_text="")
ThreadStream & endl(ThreadStream &stream)
char message_text[cDEFAULT_LOG_SIZE+1]
Contains global functions, encapsulated into the icl_core::os namespace.
char object_name[cMAX_DESCRIPTION_LENGTH+1]
void assertInitialized() const
LogOutputStream(const icl_core::String &name, const icl_core::String &config_prefix, icl_core::logging::LogLevel log_level, bool use_worker_thread=true)
Implements a platform independent mutex.
virtual void onShutdown()
Contains global LXRT functions.
This is an output stream class for log messages.
virtual void pushImpl(const LogMessage &log_message)
char class_name[cMAX_IDENTIFIER_LENGTH+1]
WorkerThread(LogOutputStream *output_stream, icl_core::ThreadPriority priority)
void changeLogFormat(const char *format)
void * memset(void *dest, int c, size_t count)
virtual ~LogOutputStream()
const char * m_time_format
static const icl_core::ThreadPriority m_default_worker_thread_priority
char function_name[cMAX_IDENTIFIER_LENGTH+1]
char log_stream[cMAX_IDENTIFIER_LENGTH+1]
const char * logLevelDescription(LogLevel log_level)
void printConfiguration() const
Defines an entry for the message queue.
#define cDEFAULT_LOG_SIZE
void parseLogFormat(const char *format)
static const icl_core::String m_default_log_format
Contains icl_logging::LogOutputStream.
int snprintf(char *buffer, size_t maxlen, const char *format,...)
friend struct WorkerThread
icl_core::String name() const