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()
77 client->wake(FAWKES_CID_NETWORKLOGGER);
83 if ((m->cid() == FAWKES_CID_NETWORKLOGGER)
84 && (m->msgid() == NetworkLogger::MSGTYPE_LOGMESSAGE)) {
86 struct timeval t = content->
get_time();
101 printf(
"Connection to host died. Aborting.\n");
114 client->wait(FAWKES_CID_NETWORKLOGGER);
116 client->disconnect();
127print_usage(
const char *program_name)
129 printf(
"Usage: %s [hostname[:port]]\n", program_name);
133main(
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);
145 SignalManager::register_handler(SIGINT, &printer);
Parse command line arguments.
Interface for logging to stderr.
Message handler for FawkesNetworkClient.
virtual void deregistered(unsigned int id) noexcept=0
This handler has been deregistered.
virtual void inbound_received(FawkesNetworkMessage *m, unsigned int id) noexcept=0
Called for incoming messages.
virtual void connection_established(unsigned int id) noexcept=0
Client has established a connection.
virtual void connection_died(unsigned int id) noexcept=0
Client connection died.
Simple Fawkes network client.
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.
Message sent over the network with a log message.
Logger::LogLevel get_loglevel() const
Log level.
struct timeval get_time() const
Get time.
const char * get_message() const
Get message.
const char * get_component() const
Get component.
Interface for signal handling.
virtual void handle_signal(int signal)=0
Signal hanlding method.
Fawkes library namespace.