Fawkes API  Fawkes Development Version
network.h
1 
2 /***************************************************************************
3  * network - Fawkes network logger
4  *
5  * Created: Sat Dec 15 00:45:54 2007 (after I5 xmas party)
6  * Copyright 2006-2007 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 
35 namespace fawkes {
36 
37 class Mutex;
38 class FawkesNetworkHub;
39 
41 : public Logger,
43 {
44  public:
46  virtual ~NetworkLogger();
47 
48  virtual void log_debug(const char *component, const char *format, ...);
49  virtual void log_info(const char *component, const char *format, ...);
50  virtual void log_warn(const char *component, const char *format, ...);
51  virtual void log_error(const char *component, const char *format, ...);
52 
53  virtual void log_debug(const char *component, Exception &e);
54  virtual void log_info(const char *component, Exception &e);
55  virtual void log_warn(const char *component, Exception &e);
56  virtual void log_error(const char *component, Exception &e);
57 
58  virtual void vlog_debug(const char *component, const char *format, va_list va);
59  virtual void vlog_info(const char *component, const char *format, va_list va);
60  virtual void vlog_warn(const char *component, const char *format, va_list va);
61  virtual void vlog_error(const char *component, const char *format, va_list va);
62 
63  virtual void tlog_debug(struct timeval *t, const char *component, const char *format, ...);
64  virtual void tlog_info(struct timeval *t, const char *component, const char *format, ...);
65  virtual void tlog_warn(struct timeval *t, const char *component, const char *format, ...);
66  virtual void tlog_error(struct timeval *t, const char *component, const char *format, ...);
67 
68  virtual void tlog_debug(struct timeval *t, const char *component, Exception &e);
69  virtual void tlog_info(struct timeval *t, const char *component, Exception &e);
70  virtual void tlog_warn(struct timeval *t, const char *component, Exception &e);
71  virtual void tlog_error(struct timeval *t, const char *component, Exception &e);
72 
73  virtual void vtlog_debug(struct timeval *t, const char *component,
74  const char *format, va_list va);
75  virtual void vtlog_info(struct timeval *t, const char *component,
76  const char *format, va_list va);
77  virtual void vtlog_warn(struct timeval *t, const char *component,
78  const char *format, va_list va);
79  virtual void vtlog_error(struct timeval *t, const char *component,
80  const char *format, va_list va);
81 
83  virtual void client_connected(unsigned int clid);
84  virtual void client_disconnected(unsigned int clid);
85 
86  /** NetworkLogger message types. */
87  typedef enum {
88  MSGTYPE_SUBSCRIBE = 1, /**< Subscribe for logging messages. */
89  MSGTYPE_UNSUBSCRIBE = 2, /**< Unsubscribe from receiving logging messages. */
90  MSGTYPE_LOGMESSAGE = 3 /**< Log message. */
92 
93 #pragma pack(push,4)
94  /** Network logging message header. */
95  typedef struct {
96  uint32_t log_level : 4; /**< LogLevel, @see Logger::LogLevel */
97  uint32_t exception : 1; /**< 1 if message was generated by exception, 0 otherwise */
98  uint32_t reserved : 27; /**< reserved for future use */
99  uint64_t time_sec; /**< time in seconds since the epoch, encoded in network byte order */
100  uint32_t time_usec; /**< addition to time in usec, encoded in network byte order */
102 #pragma pack(pop)
103 
104  private:
105  void send_message(Logger::LogLevel level, struct timeval *t,
106  const char *component, bool is_exception,
107  const char *format, va_list va);
108  void send_message(Logger::LogLevel level, struct timeval *t,
109  const char *component, bool is_exception, const char *message);
110 
111  FawkesNetworkHub *hub;
112 
114 
115  LockList<unsigned int> __subscribers;
117 };
118 
119 
121 {
122  public:
124  const char *component, bool is_exception,
125  const char *message);
126  NetworkLoggerMessageContent(Logger::LogLevel log_level, struct timeval *t,
127  const char *component, bool is_exception,
128  const char *format, va_list va);
130  NetworkLoggerMessageContent(unsigned int component_id, unsigned int msg_id,
131  void *payload, size_t payload_size);
132  virtual ~NetworkLoggerMessageContent();
133 
134  struct timeval get_time() const;
135  Logger::LogLevel get_loglevel() const;
136  const char * get_component() const;
137  const char * get_message() const;
138  bool is_exception() const;
139 
140  virtual void serialize();
141 
142  private:
144  const char *__component;
145  const char *__message;
146  bool __own_payload;
147 };
148 
149 } // end namespace fawkes
150 
151 #endif
LogLevel
Log level.
Definition: logger.h:45
virtual void vtlog_info(struct timeval *t, const char *component, const char *format, va_list va)
Log informational message for specific time.
Definition: network.cpp:282
LogLevel log_level
Minimum log level.
Definition: logger.h:128
uint64_t time_sec
time in seconds since the epoch, encoded in network byte order
Definition: network.h:99
Message sent over the network with a log message.
Definition: network.h:120
virtual ~NetworkLogger()
Destructor.
Definition: network.cpp:68
virtual void tlog_error(struct timeval *t, const char *component, const char *format,...)
Log error message for specific time.
Definition: network.cpp:345
virtual void log_error(const char *component, const char *format,...)
Log error message.
Definition: network.cpp:207
virtual void tlog_debug(struct timeval *t, const char *component, const char *format,...)
Log debug message for specific time.
Definition: network.cpp:315
network_logger_msgtype_t
NetworkLogger message types.
Definition: network.h:87
Interface for logging to network clients.
Definition: network.h:40
NetworkLogger(FawkesNetworkHub *hub, LogLevel log_level=LL_DEBUG)
Constructor.
Definition: network.cpp:57
Fawkes library namespace.
Representation of a message that is sent over the network.
Definition: message.h:75
virtual void tlog_warn(struct timeval *t, const char *component, const char *format,...)
Log warning message for specific time.
Definition: network.cpp:335
Fawkes network message content.
virtual void tlog_info(struct timeval *t, const char *component, const char *format,...)
Log informational message for specific time.
Definition: network.cpp:325
Network logging message header.
Definition: network.h:95
virtual void vtlog_warn(struct timeval *t, const char *component, const char *format, va_list va)
Log warning message for specific time.
Definition: network.cpp:293
Fawkes Network Hub.
Definition: hub.h:33
virtual void handle_network_message(FawkesNetworkMessage *msg)
Called for incoming messages that are addressed to the correct component ID.
Definition: network.cpp:406
virtual void vlog_info(const char *component, const char *format, va_list va)
Log informational message.
Definition: network.cpp:144
Base class for exceptions in Fawkes.
Definition: exception.h:36
virtual void client_connected(unsigned int clid)
Called when a new client connected.
Definition: network.cpp:419
virtual void log_warn(const char *component, const char *format,...)
Log warning message.
Definition: network.cpp:197
virtual void vtlog_error(struct timeval *t, const char *component, const char *format, va_list va)
Log error message for specific time.
Definition: network.cpp:304
virtual void vlog_warn(const char *component, const char *format, va_list va)
Log warning message.
Definition: network.cpp:155
uint32_t time_usec
addition to time in usec, encoded in network byte order
Definition: network.h:100
virtual void log_info(const char *component, const char *format,...)
Log informational message.
Definition: network.cpp:187
Network handler abstract base class.
Definition: handler.h:31
uint32_t reserved
< 1 if message was generated by exception, 0 otherwise
Definition: network.h:97
debug output, relevant only when tracking down problems
Definition: logger.h:46
virtual void vtlog_debug(struct timeval *t, const char *component, const char *format, va_list va)
Log debug message for specific time.
Definition: network.cpp:270
virtual void log_debug(const char *component, const char *format,...)
Log debug message.
Definition: network.cpp:177
Unsubscribe from receiving logging messages.
Definition: network.h:89
virtual void vlog_debug(const char *component, const char *format, va_list va)
Log debug message.
Definition: network.cpp:133
virtual void vlog_error(const char *component, const char *format, va_list va)
Log error message.
Definition: network.cpp:166
virtual void client_disconnected(unsigned int clid)
Called when a client disconnected.
Definition: network.cpp:425
Subscribe for logging messages.
Definition: network.h:88
Interface for logging.
Definition: logger.h:34