Syslog client for mbed-os 5

Fork of logger by Suga koubou

Revision:
5:641de66579d2
Parent:
4:b51e0614c767
Child:
6:cf9acc20f954
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Logger.h	Fri Oct 14 15:58:13 2016 +0100
@@ -0,0 +1,104 @@
+/*
+ * syslog device library
+ * Copyright (c) 2011 Hiroshi Suga
+ * Copyright (c) 2016 Colin Hogben
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+
+/** @file logger.h
+ * @brief syslog device (sender/client)
+ */
+ 
+#ifndef LOGGER_H
+#define LOGGER_H
+
+#include "mbed.h"
+#include "NetworkInterface.h"
+#include "UDPSocket.h"
+
+/**
+ * @enum Severity of priority
+ */
+enum LOG_SEVERITY {
+    LOG_EMERG    = 0,    /* system is unusable */
+    LOG_ALERT    = 1,    /* action must be taken immediately */
+    LOG_CRIT    = 2,    /* critical conditions */
+    LOG_ERR        = 3,    /* error conditions */
+    LOG_WARNING    = 4,    /* warning conditions */
+    LOG_NOTICE    = 5,    /* normal but significant condition */
+    LOG_INFO    = 6,    /* informational */
+    LOG_DEBUG    = 7,    /* debug-level messages */
+};
+
+/**
+ * @enum Facility of priority
+ */
+enum LOG_FACILITY {
+    LOG_KERN    = 0,    /* kernel messages */
+    LOG_USER    = 1,    /* user-level messages */
+    LOG_MAIL    = 2,    /* mail system */
+    LOG_DAEMON    = 3,    /* system daemons */
+    LOG_AUTH    = 4,    /* authorization messages */
+    LOG_SYSLOG    = 5,    /* messages generated internally by syslogd */
+    LOG_LPR        = 6,    /* line printer subsystem */
+    LOG_NEWS    = 7,    /* network news subsystem */
+    LOG_UUCP    = 8,    /* UUCP subsystem */
+    LOG_CRON    = 9,    /* clock daemon */
+    LOG_AUTHPRIV    = 10,    /* authorization messages = private */
+    LOG_FTP        = 11,    /* ftp daemon */
+    LOG_NTP        = 12,    /* NTP subsystem */
+    LOG_SECURITY    = 13,    /* security subsystems (audit) */
+    LOG_CONSOLE    = 14,    /* /dev/console output (alert) */
+    LOG_CLOCK    = 15,    /* clock daemon */
+    LOG_LOCAL0    = 16,    /* reserved for local use */
+    LOG_LOCAL1    = 17,    /* reserved for local use */
+    LOG_LOCAL2    = 18,    /* reserved for local use */
+    LOG_LOCAL3    = 19,    /* reserved for local use */
+    LOG_LOCAL4    = 20,    /* reserved for local use */
+    LOG_LOCAL5    = 21,    /* reserved for local use */
+    LOG_LOCAL6    = 22,    /* reserved for local use */
+    LOG_LOCAL7    = 23,    /* reserved for local use */
+};
+
+/** brief syslog device (sender/client)
+ */
+class Logger {
+public:
+    /** init logger class
+     * @param p_eth EthernetNetIf class
+     * @param host syslog collctor (server)
+     */
+    Logger(NetworkInterface *, const char *); 
+
+    /** init logger class
+     * @param p_eth EthernetNetIf class
+     * @param host syslog collctor (server) hostname or IP address
+     * @param myname My hostname or IP address
+     */
+    Logger(NetworkInterface *, const char *, const char *);
+
+    /** Send the message
+     * @param tag Process name
+     * @param content Message
+     */
+    void send(LOG_SEVERITY, LOG_FACILITY, const char *, const char *);
+
+    /** Send the message
+     * @param sev Severity
+     * @param fac Facility
+     * @param tag Process name
+     * @param content Message
+     */
+    void send(const char *, const char *);
+
+ private:
+    void _Logger(NetworkInterface *netif, const char *host, const char *myname);
+
+ private:
+    UDPSocket _udpsock;
+    SocketAddress _remote;
+    char _ident[32];
+};
+
+#endif
+