Fawkes API Fawkes Development Version
network_logger.h
1
2/***************************************************************************
3 * network_logger.h - Fawkes network logger
4 *
5 * Created: Sat Dec 15 00:45:54 2007 (after I5 xmas party)
6 * Copyright 2006-2017 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _LOGGING_NETWORK_H_
25#define _LOGGING_NETWORK_H_
26
27#include <core/utils/lock_list.h>
28#include <core/utils/lock_queue.h>
29#include <logging/logger.h>
30#include <netcomm/fawkes/handler.h>
31#include <netcomm/fawkes/message_content.h>
32
33#include <stdint.h>
34
35namespace fawkes {
36
37class Mutex;
38class FawkesNetworkHub;
39
41{
42public:
44 virtual ~NetworkLogger();
45
46 virtual void log_debug(const char *component, const char *format, ...);
47 virtual void log_info(const char *component, const char *format, ...);
48 virtual void log_warn(const char *component, const char *format, ...);
49 virtual void log_error(const char *component, const char *format, ...);
50
51 virtual void log_debug(const char *component, Exception &e);
52 virtual void log_info(const char *component, Exception &e);
53 virtual void log_warn(const char *component, Exception &e);
54 virtual void log_error(const char *component, Exception &e);
55
56 virtual void vlog_debug(const char *component, const char *format, va_list va);
57 virtual void vlog_info(const char *component, const char *format, va_list va);
58 virtual void vlog_warn(const char *component, const char *format, va_list va);
59 virtual void vlog_error(const char *component, const char *format, va_list va);
60
61 virtual void tlog_debug(struct timeval *t, const char *component, const char *format, ...);
62 virtual void tlog_info(struct timeval *t, const char *component, const char *format, ...);
63 virtual void tlog_warn(struct timeval *t, const char *component, const char *format, ...);
64 virtual void tlog_error(struct timeval *t, const char *component, const char *format, ...);
65
66 virtual void tlog_debug(struct timeval *t, const char *component, Exception &e);
67 virtual void tlog_info(struct timeval *t, const char *component, Exception &e);
68 virtual void tlog_warn(struct timeval *t, const char *component, Exception &e);
69 virtual void tlog_error(struct timeval *t, const char *component, Exception &e);
70
71 virtual void
72 vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va);
73 virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va);
74 virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va);
75 virtual void
76 vtlog_error(struct timeval *t, const char *component, const char *format, va_list va);
77
79 virtual void client_connected(unsigned int clid);
80 virtual void client_disconnected(unsigned int clid);
81
82 /** NetworkLogger message types. */
83 typedef enum {
84 MSGTYPE_SUBSCRIBE = 1, /**< Subscribe for logging messages. */
85 MSGTYPE_UNSUBSCRIBE = 2, /**< Unsubscribe from receiving logging messages. */
86 MSGTYPE_LOGMESSAGE = 3 /**< Log message. */
88
89#pragma pack(push, 4)
90 /** Network logging message header. */
91 typedef struct
92 {
93 uint32_t log_level : 4; /**< LogLevel, @see Logger::LogLevel */
94 uint32_t exception : 1; /**< 1 if message was generated by exception, 0 otherwise */
95 uint32_t reserved : 27; /**< reserved for future use */
96 uint64_t time_sec; /**< time in seconds since the epoch, encoded in network byte order */
97 uint32_t time_usec; /**< addition to time in usec, encoded in network byte order */
99#pragma pack(pop)
100
101private:
102 void send_message(Logger::LogLevel level,
103 struct timeval * t,
104 const char * component,
105 bool is_exception,
106 const char * format,
107 va_list va);
108 void send_message(Logger::LogLevel level,
109 struct timeval * t,
110 const char * component,
111 bool is_exception,
112 const char * message);
113
114 FawkesNetworkHub *hub;
115
117
118 LockList<unsigned int> subscribers_;
120};
121
123{
124public:
126 struct timeval * t,
127 const char * component,
128 bool is_exception,
129 const char * message);
131 struct timeval * t,
132 const char * component,
133 bool is_exception,
134 const char * format,
135 va_list va);
137 NetworkLoggerMessageContent(unsigned int component_id,
138 unsigned int msg_id,
139 void * payload,
140 size_t payload_size);
142
143 struct timeval get_time() const;
145 const char * get_component() const;
146 const char * get_message() const;
147 bool is_exception() const;
148
149 virtual void serialize();
150
151private:
153 const char * component_;
154 const char * message_;
155 bool own_payload_;
156};
157
158} // end namespace fawkes
159
160#endif
Base class for exceptions in Fawkes.
Definition: exception.h:36
Network handler abstract base class.
Definition: handler.h:32
Fawkes Network Hub.
Definition: hub.h:34
Fawkes network message content.
virtual size_t payload_size()
Return payload size.
virtual void * payload()
Return pointer to payload.
Representation of a message that is sent over the network.
Definition: message.h:77
Interface for logging.
Definition: logger.h:42
LogLevel
Log level.
Definition: logger.h:51
@ LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:52
LogLevel log_level
Minimum log level.
Definition: logger.h:126
Message sent over the network with a log message.
NetworkLoggerMessageContent(Logger::LogLevel log_level, struct timeval *t, const char *component, bool is_exception, const char *message)
Constructor.
virtual ~NetworkLoggerMessageContent()
Destructor.
Logger::LogLevel get_loglevel() const
Log level.
struct timeval get_time() const
Get time.
virtual void serialize()
Serialize message content.
const char * get_message() const
Get message.
const char * get_component() const
Get component.
bool is_exception() const
Check if message was generated by exception.
Interface for logging to network clients.
virtual void client_disconnected(unsigned int clid)
Called when a client disconnected.
virtual void log_error(const char *component, const char *format,...)
Log error message.
virtual void vlog_error(const char *component, const char *format, va_list va)
Log error message.
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 vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)
Log debug message for specific time.
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)
Log debug 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.
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)
Log warning message for specific time.
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)
Log informational message for specific time.
virtual void vlog_info(const char *component, const char *format, va_list va)
Log informational message.
virtual void vlog_debug(const char *component, const char *format, va_list va)
Log debug message.
virtual void client_connected(unsigned int clid)
Called when a new client connected.
virtual void log_info(const char *component, const char *format,...)
Log informational message.
NetworkLogger(FawkesNetworkHub *hub, LogLevel log_level=LL_DEBUG)
Constructor.
network_logger_msgtype_t
NetworkLogger message types.
@ MSGTYPE_SUBSCRIBE
Subscribe for logging messages.
@ MSGTYPE_LOGMESSAGE
Log message.
@ MSGTYPE_UNSUBSCRIBE
Unsubscribe from receiving logging messages.
virtual void vlog_warn(const char *component, const char *format, va_list va)
Log warning message.
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)
Log informational message for specific time.
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
virtual void handle_network_message(FawkesNetworkMessage *msg)
Called for incoming messages that are addressed to the correct component ID.
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)
Log error message for specific time.
virtual ~NetworkLogger()
Destructor.
Fawkes library namespace.
uint32_t reserved
< 1 if message was generated by exception, 0 otherwise
uint32_t time_usec
addition to time in usec, encoded in network byte order
uint64_t time_sec
time in seconds since the epoch, encoded in network byte order