23 #include <logging/console.h> 24 #include <netcomm/fawkes/client.h> 25 #include <netcomm/fawkes/client_handler.h> 26 #include <netcomm/fawkes/component_ids.h> 27 #include <network_logger/network_logger.h> 28 #include <utils/system/argparser.h> 29 #include <utils/system/signal.h> 42 explicit NetLogConsolePrinter(
const char *hostport)
47 char * hp = strdup(hostport);
48 const char *hostname = strtok(hp,
":");
49 const char *portstr = strtok(NULL,
"");
53 if ((port < 0) || (port > 0xFFFF)) {
54 printf(
"Invalid port given, must be in range [1:65535]. Using default 1910 instead\n");
61 client->register_handler(
this, FAWKES_CID_NETWORKLOGGER);
67 ~NetLogConsolePrinter()
74 handle_signal(
int signal)
77 client->wake(FAWKES_CID_NETWORKLOGGER);
83 if ((m->cid() == FAWKES_CID_NETWORKLOGGER)
86 struct timeval t = content->
get_time();
93 deregistered(
unsigned int id)
throw()
99 connection_died(
unsigned int id)
throw()
101 printf(
"Connection to host died. Aborting.\n");
106 connection_established(
unsigned int id)
throw()
114 client->wait(FAWKES_CID_NETWORKLOGGER);
116 client->disconnect();
127 print_usage(
const char *program_name)
129 printf(
"Usage: %s [hostname[:port]]\n", program_name);
133 main(
int argc,
char **argv)
137 if (argp.has_arg(
"h")) {
138 print_usage(argv[0]);
142 const char * hostport = (argp.num_items() > 0) ? argp.items()[0] :
"localhost:1910";
143 NetLogConsolePrinter printer(hostport);
Message handler for FawkesNetworkClient.
const char * get_component() const
Get component.
const char * get_message() const
Get message.
Message sent over the network with a log message.
Simple Fawkes network client.
Interface for logging to stderr.
Fawkes library namespace.
Representation of a message that is sent over the network.
virtual void tlog(LogLevel level, struct timeval *t, const char *component, const char *format,...)
Log message of given log level and time.
Interface for signal handling.
Parse command line arguments.
Logger::LogLevel get_loglevel() const
Log level.
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
struct timeval get_time() const
Get time.
Subscribe for logging messages.