24 #include <logging/network.h> 26 #include <core/threading/mutex.h> 27 #include <netcomm/fawkes/component_ids.h> 28 #include <netcomm/fawkes/hub.h> 29 #include <netcomm/utils/ntoh64.h> 33 #include <netinet/in.h> 76 const char *component,
bool is_exception,
77 const char *format, va_list va)
81 gettimeofday(&now, NULL);
90 for ( __ssit = __subscribers.begin(); __ssit != __subscribers.end(); ++__ssit) {
105 const char *component,
bool is_exception,
110 gettimeofday(&now, NULL);
119 for ( __ssit = __subscribers.begin(); __ssit != __subscribers.end(); ++__ssit) {
136 __subscribers.
lock();
137 send_message(
LL_DEBUG, NULL, component,
false, format, va);
147 __subscribers.
lock();
148 send_message(
LL_INFO, NULL, component,
false, format, va);
158 __subscribers.
lock();
159 send_message(
LL_WARN, NULL, component,
false, format, va);
169 __subscribers.
lock();
170 send_message(
LL_ERROR, NULL, component,
false, format, va);
180 va_start(arg, format);
190 va_start(arg, format);
200 va_start(arg, format);
210 va_start(arg, format);
220 __subscribers.
lock();
222 send_message(
LL_DEBUG, NULL, component,
true, *i);
232 __subscribers.
lock();
234 send_message(
LL_INFO, NULL, component,
true, *i);
245 __subscribers.
lock();
247 send_message(
LL_WARN, NULL, component,
true, *i);
258 __subscribers.
lock();
260 send_message(
LL_ERROR, NULL, component,
true, *i);
271 const char *format, va_list va)
274 __subscribers.
lock();
275 send_message(
LL_DEBUG, t, component,
false, format, va);
285 __subscribers.
lock();
286 send_message(
LL_INFO, t, component,
false, format, va);
296 __subscribers.
lock();
297 send_message(
LL_WARN, t, component,
false, format, va);
307 __subscribers.
lock();
308 send_message(
LL_ERROR, t, component,
false, format, va);
318 va_start(arg, format);
328 va_start(arg, format);
338 va_start(arg, format);
348 va_start(arg, format);
358 __subscribers.
lock();
360 send_message(
LL_DEBUG, t, component,
true, *i);
370 __subscribers.
lock();
372 send_message(
LL_INFO, t, component,
true, *i);
383 __subscribers.
lock();
385 send_message(
LL_WARN, t, component,
true, *i);
396 __subscribers.
lock();
398 send_message(
LL_ERROR, t, component,
true, *i);
408 if ( (msg->
cid() == FAWKES_CID_NETWORKLOGGER) &&
410 __subscribers.
lock();
411 __subscribers.push_back(msg->
clid());
412 __subscribers.sort();
413 __subscribers.unique();
449 const char *component,
451 const char *format, va_list va)
455 if ( (tmplen = vasprintf(&tmp, format, va)) != -1 ) {
457 _payload = calloc(1, _payload_size);
458 __own_payload =
true;
461 header->exception = is_exception ? 1 : 0;
462 header->time_sec = hton64(t->tv_sec);
463 header->time_usec = htonl(t->tv_usec);
482 const char *component,
487 _payload = calloc(1, _payload_size);
488 __own_payload =
true;
491 header->exception = is_exception ? 1 : 0;
492 header->time_sec = hton64(t->tv_sec);
493 header->time_usec = htonl(t->tv_usec);
507 _payload = malloc(_payload_size);
508 __own_payload =
true;
509 memcpy(_payload, content->
_payload, _payload_size);
525 void *payload,
size_t payload_size)
527 if ( component_id != FAWKES_CID_NETWORKLOGGER ) {
532 _payload_size = payload_size;
533 __own_payload =
false;
542 if (__own_payload) free(_payload);
552 rv.tv_sec = (time_t)ntoh64(header->time_sec);
553 rv.tv_usec = ntohl(header->time_usec);
594 return (header->exception == 1);
void * _payload
Pointer to payload.
const char * get_component() const
Get component.
size_t _payload_size
Payloda size.
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)
Log informational message for specific time.
const char * get_message() const
Get message.
LogLevel log_level
Minimum log level.
Message sent over the network with a log message.
informational output about normal procedures
virtual ~NetworkLogger()
Destructor.
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)
Log error message for specific time.
virtual void lock() const
Lock list.
unsigned short int cid() const
Get component ID.
virtual void log_error(const char *component, const char *format,...)
Log error message.
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)
Log debug message for specific time.
NetworkLogger(FawkesNetworkHub *hub, LogLevel log_level=LL_DEBUG)
Constructor.
Fawkes library namespace.
unsigned int clid() const
Get client ID.
virtual void serialize()
Serialize message content.
virtual void add_handler(FawkesNetworkHandler *handler)=0
Add a message handler.
Representation of a message that is sent over the network.
warning, should be investigated but software still functions, an example is that something was reques...
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)
Log warning message for specific time.
Logger::LogLevel get_loglevel() const
Log level.
Message iterator for exceptions.
void remove_locked(const Type &x)
Remove element from list with lock protection.
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)
Log informational message for specific time.
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)
Log warning message for specific time.
error, may be recoverable (software still running) or not (software has to terminate).
iterator end()
Get end iterator for messages.
virtual void handle_network_message(FawkesNetworkMessage *msg)
Called for incoming messages that are addressed to the correct component ID.
virtual void vlog_info(const char *component, const char *format, va_list va)
Log informational message.
Base class for exceptions in Fawkes.
virtual void send(FawkesNetworkMessage *msg)=0
Method to send a message to a specific client.
virtual void client_connected(unsigned int clid)
Called when a new client connected.
virtual void log_warn(const char *component, const char *format,...)
Log warning message.
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)
Log error message for specific time.
virtual void vlog_warn(const char *component, const char *format, va_list va)
Log warning message.
virtual void unlock() const
Unlock list.
bool is_exception() const
Check if message was generated by exception.
iterator begin()
Get iterator for messages.
virtual void log_info(const char *component, const char *format,...)
Log informational message.
Network handler abstract base class.
debug output, relevant only when tracking down problems
virtual void vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)
Log debug message for specific time.
unsigned short int msgid() const
Get message type ID.
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
virtual void remove_handler(FawkesNetworkHandler *handler)=0
Remove a message handler.
virtual void vlog_debug(const char *component, const char *format, va_list va)
Log debug message.
virtual void vlog_error(const char *component, const char *format, va_list va)
Log error message.
NetworkLoggerMessageContent(Logger::LogLevel log_level, struct timeval *t, const char *component, bool is_exception, const char *message)
Constructor.
virtual void client_disconnected(unsigned int clid)
Called when a client disconnected.
virtual ~NetworkLoggerMessageContent()
Destructor.
Subscribe for logging messages.