Syslog client for mbed-os 5
Fork of logger by
logger.h@2:ce978c9ea3e8, 2016-10-14 (annotated)
- Committer:
- infinnovation
- Date:
- Fri Oct 14 12:06:05 2016 +0000
- Revision:
- 2:ce978c9ea3e8
- Parent:
- 1:f7e32e99f366
- Child:
- 3:91ee7ead8536
Rework for mbed-os 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:7d428b9b277e | 1 | /* |
okini3939 | 0:7d428b9b277e | 2 | * syslog device library |
okini3939 | 0:7d428b9b277e | 3 | * Copyright (c) 2011 Hiroshi Suga |
okini3939 | 0:7d428b9b277e | 4 | * Released under the MIT License: http://mbed.org/license/mit |
okini3939 | 0:7d428b9b277e | 5 | */ |
okini3939 | 0:7d428b9b277e | 6 | |
okini3939 | 0:7d428b9b277e | 7 | /** @file logger.h |
okini3939 | 0:7d428b9b277e | 8 | * @brief syslog device (sender/client) |
okini3939 | 0:7d428b9b277e | 9 | */ |
okini3939 | 0:7d428b9b277e | 10 | |
okini3939 | 0:7d428b9b277e | 11 | #ifndef LOGGER_H |
okini3939 | 0:7d428b9b277e | 12 | #define LOGGER_H |
okini3939 | 0:7d428b9b277e | 13 | |
okini3939 | 0:7d428b9b277e | 14 | #include "mbed.h" |
infinnovation | 2:ce978c9ea3e8 | 15 | #include "NetworkInterface.h" |
okini3939 | 0:7d428b9b277e | 16 | #include "UDPSocket.h" |
okini3939 | 0:7d428b9b277e | 17 | |
okini3939 | 0:7d428b9b277e | 18 | #define LOG_LEN 256 |
okini3939 | 0:7d428b9b277e | 19 | #define LOG_UDPPORT 514 |
okini3939 | 0:7d428b9b277e | 20 | |
okini3939 | 0:7d428b9b277e | 21 | /** |
okini3939 | 0:7d428b9b277e | 22 | * @enum Severity of priority |
okini3939 | 0:7d428b9b277e | 23 | */ |
okini3939 | 0:7d428b9b277e | 24 | enum LOG_SEVERITY { |
okini3939 | 0:7d428b9b277e | 25 | LOG_EMERG = 0, /* system is unusable */ |
okini3939 | 0:7d428b9b277e | 26 | LOG_ALERT = 1, /* action must be taken immediately */ |
okini3939 | 0:7d428b9b277e | 27 | LOG_CRIT = 2, /* critical conditions */ |
okini3939 | 0:7d428b9b277e | 28 | LOG_ERR = 3, /* error conditions */ |
okini3939 | 0:7d428b9b277e | 29 | LOG_WARNING = 4, /* warning conditions */ |
okini3939 | 0:7d428b9b277e | 30 | LOG_NOTICE = 5, /* normal but significant condition */ |
okini3939 | 0:7d428b9b277e | 31 | LOG_INFO = 6, /* informational */ |
okini3939 | 0:7d428b9b277e | 32 | LOG_DEBUG = 7, /* debug-level messages */ |
okini3939 | 0:7d428b9b277e | 33 | }; |
okini3939 | 0:7d428b9b277e | 34 | |
okini3939 | 0:7d428b9b277e | 35 | /** |
okini3939 | 0:7d428b9b277e | 36 | * @enum Facility of priority |
okini3939 | 0:7d428b9b277e | 37 | */ |
okini3939 | 0:7d428b9b277e | 38 | enum LOG_FACILITY { |
okini3939 | 0:7d428b9b277e | 39 | LOG_KERN = 0, /* kernel messages */ |
okini3939 | 0:7d428b9b277e | 40 | LOG_USER = 1, /* user-level messages */ |
okini3939 | 0:7d428b9b277e | 41 | LOG_MAIL = 2, /* mail system */ |
okini3939 | 0:7d428b9b277e | 42 | LOG_DAEMON = 3, /* system daemons */ |
okini3939 | 0:7d428b9b277e | 43 | LOG_AUTH = 4, /* authorization messages */ |
okini3939 | 0:7d428b9b277e | 44 | LOG_SYSLOG = 5, /* messages generated internally by syslogd */ |
okini3939 | 0:7d428b9b277e | 45 | LOG_LPR = 6, /* line printer subsystem */ |
okini3939 | 0:7d428b9b277e | 46 | LOG_NEWS = 7, /* network news subsystem */ |
okini3939 | 0:7d428b9b277e | 47 | LOG_UUCP = 8, /* UUCP subsystem */ |
okini3939 | 0:7d428b9b277e | 48 | LOG_CRON = 9, /* clock daemon */ |
okini3939 | 0:7d428b9b277e | 49 | LOG_AUTHPRIV = 10, /* authorization messages = private */ |
okini3939 | 0:7d428b9b277e | 50 | LOG_FTP = 11, /* ftp daemon */ |
okini3939 | 0:7d428b9b277e | 51 | LOG_NTP = 12, /* NTP subsystem */ |
okini3939 | 0:7d428b9b277e | 52 | LOG_SECURITY = 13, /* security subsystems (audit) */ |
okini3939 | 0:7d428b9b277e | 53 | LOG_CONSOLE = 14, /* /dev/console output (alert) */ |
okini3939 | 0:7d428b9b277e | 54 | LOG_CLOCK = 15, /* clock daemon */ |
okini3939 | 0:7d428b9b277e | 55 | LOG_LOCAL0 = 16, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 56 | LOG_LOCAL1 = 17, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 57 | LOG_LOCAL2 = 18, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 58 | LOG_LOCAL3 = 19, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 59 | LOG_LOCAL4 = 20, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 60 | LOG_LOCAL5 = 21, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 61 | LOG_LOCAL6 = 22, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 62 | LOG_LOCAL7 = 23, /* reserved for local use */ |
okini3939 | 0:7d428b9b277e | 63 | }; |
okini3939 | 0:7d428b9b277e | 64 | |
okini3939 | 1:f7e32e99f366 | 65 | /** brief syslog device (sender/client) |
okini3939 | 0:7d428b9b277e | 66 | */ |
infinnovation | 2:ce978c9ea3e8 | 67 | class Logger { |
okini3939 | 0:7d428b9b277e | 68 | public: |
okini3939 | 1:f7e32e99f366 | 69 | /** init logger class |
okini3939 | 1:f7e32e99f366 | 70 | * @param p_eth EthernetNetIf class |
okini3939 | 1:f7e32e99f366 | 71 | * @param host syslog collctor (server) |
okini3939 | 1:f7e32e99f366 | 72 | */ |
infinnovation | 2:ce978c9ea3e8 | 73 | Logger(NetworkInterface *, const char *); |
okini3939 | 1:f7e32e99f366 | 74 | |
okini3939 | 1:f7e32e99f366 | 75 | /** init logger class |
okini3939 | 1:f7e32e99f366 | 76 | * @param p_eth EthernetNetIf class |
okini3939 | 1:f7e32e99f366 | 77 | * @param host syslog collctor (server) hostname or IP address |
okini3939 | 1:f7e32e99f366 | 78 | * @param myname My hostname or IP address |
okini3939 | 1:f7e32e99f366 | 79 | */ |
infinnovation | 2:ce978c9ea3e8 | 80 | Logger(NetworkInterface *, const char *, const char *); |
okini3939 | 0:7d428b9b277e | 81 | |
okini3939 | 1:f7e32e99f366 | 82 | /** Send the message |
okini3939 | 1:f7e32e99f366 | 83 | * @param tag Process name |
okini3939 | 1:f7e32e99f366 | 84 | * @param content Message |
okini3939 | 1:f7e32e99f366 | 85 | */ |
infinnovation | 2:ce978c9ea3e8 | 86 | void send(LOG_SEVERITY, LOG_FACILITY, const char *, const char *); |
okini3939 | 1:f7e32e99f366 | 87 | |
okini3939 | 1:f7e32e99f366 | 88 | /** Send the message |
okini3939 | 1:f7e32e99f366 | 89 | * @param sev Severity |
okini3939 | 1:f7e32e99f366 | 90 | * @param fac Facility |
okini3939 | 1:f7e32e99f366 | 91 | * @param tag Process name |
okini3939 | 1:f7e32e99f366 | 92 | * @param content Message |
okini3939 | 1:f7e32e99f366 | 93 | */ |
infinnovation | 2:ce978c9ea3e8 | 94 | void send(const char *, const char *); |
okini3939 | 0:7d428b9b277e | 95 | |
okini3939 | 0:7d428b9b277e | 96 | private: |
infinnovation | 2:ce978c9ea3e8 | 97 | NetworkInterface *_netif; |
infinnovation | 2:ce978c9ea3e8 | 98 | UDPSocket _udpsock; |
infinnovation | 2:ce978c9ea3e8 | 99 | SocketAddress _remote; |
infinnovation | 2:ce978c9ea3e8 | 100 | char _ident[32]; |
okini3939 | 0:7d428b9b277e | 101 | |
okini3939 | 0:7d428b9b277e | 102 | }; |
okini3939 | 0:7d428b9b277e | 103 | |
okini3939 | 0:7d428b9b277e | 104 | #endif |
okini3939 | 0:7d428b9b277e | 105 |