├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── examples ├── AdvancedLogging │ └── AdvancedLogging.ino ├── AdvancedLoggingESP8266 │ └── AdvancedLoggingESP8266.ino ├── SimpleLogging │ └── SimpleLogging.ino ├── SimpleLoggingESP8266 │ └── SimpleLoggingESP8266.ino ├── SimpleLoggingWiFi │ └── SimpleLoggingWiFi.ino ├── SimpleLoggingWiFi101_MKR1000 │ └── SimpleLoggingWiFi101_MKR1000.ino └── SimpleLoggingYun │ └── SimpleLoggingYun.ino ├── keywords.txt ├── library.json ├── library.properties └── src ├── Syslog.cpp └── Syslog.h /.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | .idea 4 | CMakeListsPrivate.txt 5 | /CMakeLists.txt 6 | /cmake-build-debug 7 | /lib 8 | /platformio.ini 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | 5 | sudo: false 6 | cache: 7 | directories: 8 | - "~/.platformio" 9 | 10 | env: 11 | - BOARD=esp01 PLATFORMIO_CI_SRC=examples/SimpleLoggingESP8266 EXTRAS="--project-option=lib_ignore=WiFi101" 12 | - BOARD=nodemcuv2 PLATFORMIO_CI_SRC=examples/SimpleLoggingESP8266 EXTRAS="--project-option=lib_ignore=WiFi101" 13 | - BOARD=uno PLATFORMIO_CI_SRC=examples/SimpleLogging 14 | - BOARD=megaatmega1280 PLATFORMIO_CI_SRC=examples/SimpleLogging 15 | - BOARD=yun PLATFORMIO_CI_SRC=examples/SimpleLoggingYun 16 | - BOARD=zero PLATFORMIO_CI_SRC=examples/SimpleLoggingWiFi EXTRAS="--project-option=lib_ignore=WiFi101 --project-option=lib_deps=WiFi" 17 | - BOARD=mkr1000USB PLATFORMIO_CI_SRC=examples/SimpleLoggingWiFi101_MKR1000 18 | 19 | install: 20 | - pip install -U platformio 21 | - rm -rf ./linux 22 | 23 | # 24 | # Libraries from PlatformIO Library Registry: 25 | # 26 | # http://platformio.org/lib/show/299/WiFi101 27 | 28 | - platformio lib -g install 299 29 | 30 | script: 31 | - platformio ci -v --lib="." --board=$BOARD $EXTRAS -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Martin Sloup 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Syslog 2 | 3 | An Arduino library for logging to Syslog server via `UDP` protocol in 4 | [IETF (RFC 5424)] and [BSD (RFC 3164)] message format 5 | 6 | [![Build Status](https://travis-ci.org/arcao/Syslog.svg?branch=master)](https://travis-ci.org/arcao/Syslog) [![Join the chat at https://gitter.im/arcao/Syslog](https://badges.gitter.im/arcao/Syslog.svg)](https://gitter.im/arcao/Syslog?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 7 | 8 | How to use, see [examples]. 9 | 10 | ## Features 11 | - Supports original Syslog severity level and facility constants 12 | - Supports both Syslog messge formats: [IETF (RFC 5424)] and [BSD (RFC 3164)] 13 | - Supports `printf`-like formatting via `logf` methods (use `vsnprintf` method 14 | inside) 15 | - Supports fluent interface, see [AdvancedLogging] example 16 | - Allows to ignore sending specified severity levels with `logMask` function, 17 | see [AdvancedLogging] example 18 | - Independent on underlying network hardware. The network hardware library has 19 | to implement methods of `UDP` astract class only. 20 | 21 | ## Compatible Hardware 22 | The library uses the Arduino UDP Network API (`UDP` class) for interacting with 23 | the underlying network hardware. This means it Just Works with a growing number 24 | of boards and shields, including: 25 | 26 | - ESP8266 / ESP32 27 | - Arduino Ethernet 28 | - Arduino Ethernet Shield 29 | - Arduino YUN – use the included `BridgeUDP` in place of `EthernetUDP`, and 30 | be sure to call a `Bridge.begin()` first 31 | - Arduino WiFi Shield 32 | - Intel Galileo/Edison 33 | - Arduino/Genuino MKR1000 34 | - [Arduino module RTL00(RTL8710AF), F11AMIM13 (RTL8711AM)][RTLDUINO] 35 | - ... you tell me! 36 | 37 | ## Syslog message formats 38 | This library supports both Syslog message formats [IETF (RFC 5424)] and 39 | [BSD (RFC 3164)]. The newer **IETF** format is used by default. If you want to use 40 | older "obsolete" **BSD** format, just specify it with `SYSLOG_PROTO_BSD` constant 41 | in a last constructor parameter. 42 | 43 | ```c 44 | Syslog syslog(udpClient, host, port, device_hostname, app_name, default_priority, SYSLOG_PROTO_BSD); 45 | // or 46 | Syslog syslog(udpClient, ip, port, device_hostname, app_name, default_priority, SYSLOG_PROTO_BSD); 47 | // or 48 | Syslog syslog(udpClient, SYSLOG_PROTO_BSD); 49 | ``` 50 | 51 | ## Limitations 52 | - This library is sending empty timestamp in the syslog messages. For IETF 53 | format it is `NILVALUE` (char `-`) in `TIMESTAMP` field, for BSD format the 54 | `TIMESTAMP` field is completely ommited. Syslog server should use a time 55 | of receiving message in this case. It is OK in most cases. This issue will be 56 | fixed in some of the next releases. 57 | 58 | 59 | [IETF (RFC 5424)]: https://tools.ietf.org/html/rfc5424 60 | [BSD (RFC 3164)]: https://tools.ietf.org/html/rfc3164 61 | [examples]: https://github.com/arcao/Syslog/tree/master/examples 62 | [AdvancedLogging]: https://github.com/arcao/Syslog/blob/master/examples/AdvancedLogging/AdvancedLogging.ino 63 | [RTLDUINO]: https://github.com/pvvx/RtlDuino 64 | -------------------------------------------------------------------------------- /examples/AdvancedLogging/AdvancedLogging.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Syslog client: AdvancedLogging example 4 | 5 | Demonstrates logging messages to Syslog server in IETF format (rfc5424) in 6 | combination with the Ethernet library and Arduino Ethernet Shield. 7 | 8 | For more about Syslog see https://en.wikipedia.org/wiki/Syslog 9 | 10 | created 21 Jan 2017 11 | by Martin Sloup 12 | 13 | This code is in the public domain. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // Syslog server connection info 23 | #define SYSLOG_SERVER "syslog-server" 24 | #define SYSLOG_PORT 514 25 | 26 | // This device info 27 | #define DEVICE_HOSTNAME "my-device" 28 | #define APP_NAME "my-app" 29 | #define ANOTHER_APP_NAME "my-another-app" 30 | 31 | // Enter a MAC address for your controller below. 32 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 33 | byte mac[] = { 34 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 35 | }; 36 | 37 | // A UDP instance to let us send and receive packets over UDP 38 | EthernetUDP udpClient; 39 | 40 | // Create a new empty syslog instance 41 | Syslog syslog(udpClient, SYSLOG_PROTO_IETF); 42 | 43 | int iteration = 1; 44 | 45 | void setup() { 46 | // Open serial communications and wait for port to open: 47 | Serial.begin(9600); 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for native USB port only 50 | } 51 | 52 | // start Ethernet 53 | if (Ethernet.begin(mac) == 0) { 54 | Serial.println("Failed to configure Ethernet using DHCP"); 55 | // no point in carrying on, so do nothing forevermore: 56 | for (;;) 57 | ; 58 | } 59 | 60 | // prepare syslog configuration here (can be anywhere before first call of 61 | // log/logf method) 62 | syslog.server(SYSLOG_SERVER, SYSLOG_PORT); 63 | syslog.deviceHostname(DEVICE_HOSTNAME); 64 | syslog.appName(APP_NAME); 65 | syslog.defaultPriority(LOG_KERN); 66 | } 67 | 68 | void loop() { 69 | // Severity levels can be found in Syslog.h. They are same like in Linux 70 | // syslog. 71 | syslog.log(LOG_INFO, "Begin loop"); 72 | 73 | // Log message can be formated like with printf function. 74 | syslog.logf(LOG_ERR, "This is error message no. %d", iteration); 75 | syslog.logf(LOG_INFO, "This is info message no. %d", iteration); 76 | 77 | // You can force set facility in pri parameter for this log message. More 78 | // facilities in syslog.h or in Linux syslog documentation. 79 | syslog.logf(LOG_DAEMON | LOG_INFO, "This is daemon info message no. %d", 80 | iteration); 81 | 82 | // You can set default facility and severity level and use it for all log 83 | // messages (beware defaultPriority is stored permanently!) 84 | syslog.defaultPriority(LOG_FTP | LOG_INFO); 85 | syslog.logf("This is ftp info message no. %d", iteration); 86 | 87 | // Return to default facility 88 | syslog.defaultPriority(LOG_KERN); 89 | 90 | // Also fluent interface is supported (beware appName is stored permanently!) 91 | syslog.appName(ANOTHER_APP_NAME).logf(LOG_ERR, 92 | "This is error message no. %d from %s", iteration, ANOTHER_APP_NAME); 93 | 94 | // Return to default app name 95 | syslog.appName(APP_NAME); 96 | 97 | // Send log messages only for selected severity levels: LOG_INFO and LOG_WARNING 98 | syslog.logMask(LOG_MASK(LOG_INFO) | LOG_MASK(LOG_WARNING)); 99 | syslog.log(LOG_INFO, "This is logged."); 100 | syslog.log(LOG_WARNING, "This is logged."); 101 | syslog.log(LOG_ERR, "This is not logged."); 102 | 103 | // Send log messages up to LOG_WARNING priority 104 | syslog.logMask(LOG_UPTO(LOG_WARNING)); 105 | syslog.log(LOG_ERR, "This is logged."); 106 | syslog.log(LOG_WARNING, "This is logged."); 107 | syslog.log(LOG_NOTICE, "This is not logged."); 108 | syslog.log(LOG_INFO, "This is not logged."); 109 | 110 | // Return logMask to default 111 | syslog.logMask(LOG_UPTO(LOG_DEBUG)); 112 | 113 | // F() macro is supported too 114 | syslog.log(LOG_INFO, F("End loop")); 115 | 116 | iteration++; 117 | 118 | // wait ten seconds before sending log message again 119 | delay(10000); 120 | } 121 | -------------------------------------------------------------------------------- /examples/AdvancedLoggingESP8266/AdvancedLoggingESP8266.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Syslog client: AdvancedLogging example 4 | 5 | Demonstrates logging messages to Syslog server in IETF format (rfc5424) in 6 | combination with the ESP8266 board/library. 7 | 8 | For more about Syslog see https://en.wikipedia.org/wiki/Syslog 9 | 10 | created 3 Nov 2016 11 | by Martin Sloup 12 | 13 | This code is in the public domain. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | // WIFI credentials 22 | #define WIFI_SSID "**************" 23 | #define WIFI_PASS "**************" 24 | 25 | // Syslog server connection info 26 | #define SYSLOG_SERVER "syslog-server" 27 | #define SYSLOG_PORT 514 28 | 29 | // This device info 30 | #define DEVICE_HOSTNAME "my-device" 31 | #define APP_NAME "my-app" 32 | #define ANOTHER_APP_NAME "my-another-app" 33 | 34 | // A UDP instance to let us send and receive packets over UDP 35 | WiFiUDP udpClient; 36 | 37 | // Create a new empty syslog instance 38 | Syslog syslog(udpClient, SYSLOG_PROTO_IETF); 39 | 40 | int iteration = 1; 41 | 42 | void setup() { 43 | Serial.begin(115200); 44 | Serial.println(); 45 | Serial.println(); 46 | 47 | // We start by connecting to a WiFi network 48 | Serial.print("Connecting to "); 49 | Serial.println(WIFI_SSID); 50 | WiFi.begin(WIFI_SSID, WIFI_PASS); 51 | 52 | while (WiFi.status() != WL_CONNECTED) { 53 | delay(500); 54 | Serial.print("."); 55 | } 56 | Serial.println(); 57 | 58 | Serial.println("WiFi connected"); 59 | Serial.println("IP address: "); 60 | Serial.println(WiFi.localIP()); 61 | 62 | // prepare syslog configuration here (can be anywhere before first call of 63 | // log/logf method) 64 | syslog.server(SYSLOG_SERVER, SYSLOG_PORT); 65 | syslog.deviceHostname(DEVICE_HOSTNAME); 66 | syslog.appName(APP_NAME); 67 | syslog.defaultPriority(LOG_KERN); 68 | } 69 | 70 | void loop() { 71 | // Severity levels can be found in Syslog.h. They are same like in Linux 72 | // syslog. 73 | syslog.log(LOG_INFO, "Begin loop"); 74 | 75 | // Log message can be formated like with printf function. 76 | syslog.logf(LOG_ERR, "This is error message no. %d", iteration); 77 | syslog.logf(LOG_INFO, "This is info message no. %d", iteration); 78 | 79 | // You can force set facility in pri parameter for this log message. More 80 | // facilities in syslog.h or in Linux syslog documentation. 81 | syslog.logf(LOG_DAEMON | LOG_INFO, "This is daemon info message no. %d", 82 | iteration); 83 | 84 | // You can set default facility and severity level and use it for all log 85 | // messages (beware defaultPriority is stored permanently!) 86 | syslog.defaultPriority(LOG_FTP | LOG_INFO); 87 | syslog.logf("This is ftp info message no. %d", iteration); 88 | 89 | // Return to default facility 90 | syslog.defaultPriority(LOG_KERN); 91 | 92 | // Also fluent interface is supported (beware appName is stored permanently!) 93 | syslog.appName(ANOTHER_APP_NAME).logf(LOG_ERR, 94 | "This is error message no. %d from %s", iteration, ANOTHER_APP_NAME); 95 | 96 | // Return to default app name 97 | syslog.appName(APP_NAME); 98 | 99 | // Send log messages only for selected severity levels: LOG_INFO and LOG_WARNING 100 | syslog.logMask(LOG_MASK(LOG_INFO) | LOG_MASK(LOG_WARNING)); 101 | syslog.log(LOG_INFO, "This is logged."); 102 | syslog.log(LOG_WARNING, "This is logged."); 103 | syslog.log(LOG_ERR, "This is not logged."); 104 | 105 | // Send log messages up to LOG_WARNING severity 106 | syslog.logMask(LOG_UPTO(LOG_WARNING)); 107 | syslog.log(LOG_ERR, "This is logged."); 108 | syslog.log(LOG_WARNING, "This is logged."); 109 | syslog.log(LOG_NOTICE, "This is not logged."); 110 | syslog.log(LOG_INFO, "This is not logged."); 111 | 112 | // Return logMask to default 113 | syslog.logMask(LOG_UPTO(LOG_DEBUG)); 114 | 115 | // F() macro is supported too 116 | syslog.log(LOG_INFO, F("End loop")); 117 | 118 | iteration++; 119 | 120 | // wait ten seconds before sending log message again 121 | delay(10000); 122 | } 123 | -------------------------------------------------------------------------------- /examples/SimpleLogging/SimpleLogging.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Syslog client: SimpleLogging example 4 | 5 | Demonstrates logging messages to Syslog server in IETF format (rfc5424) in 6 | combination with the Ethernet library and Arduino Ethernet Shield. 7 | 8 | For more about Syslog see https://en.wikipedia.org/wiki/Syslog 9 | 10 | created 20 Jan 2017 11 | by Martin Sloup 12 | 13 | This code is in the public domain. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // Syslog server connection info 23 | #define SYSLOG_SERVER "syslog-server" 24 | #define SYSLOG_PORT 514 25 | 26 | // This device info 27 | #define DEVICE_HOSTNAME "my-device" 28 | #define APP_NAME "my-app" 29 | 30 | // Enter a MAC address for your controller below. 31 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 32 | byte mac[] = { 33 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 34 | }; 35 | 36 | // A UDP instance to let us send and receive packets over UDP 37 | EthernetUDP udpClient; 38 | 39 | // Create a new syslog instance with LOG_KERN facility 40 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN); 41 | 42 | int iteration = 1; 43 | 44 | void setup() { 45 | // Open serial communications and wait for port to open: 46 | Serial.begin(9600); 47 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for native USB port only 49 | } 50 | 51 | // start Ethernet 52 | if (Ethernet.begin(mac) == 0) { 53 | Serial.println("Failed to configure Ethernet using DHCP"); 54 | // no point in carrying on, so do nothing forevermore: 55 | for (;;) 56 | ; 57 | } 58 | } 59 | 60 | void loop() { 61 | // Severity levels can be found in Syslog.h. They are same like in Linux 62 | // syslog. 63 | syslog.log(LOG_INFO, "Begin loop"); 64 | 65 | // Log message can be formated like with printf function. 66 | syslog.logf(LOG_ERR, "This is error message no. %d", iteration); 67 | syslog.logf(LOG_INFO, "This is info message no. %d", iteration); 68 | 69 | // You can force set facility in pri parameter for this log message. More 70 | // facilities in syslog.h or in Linux syslog documentation. 71 | syslog.logf(LOG_DAEMON | LOG_INFO, "This is daemon info message no. %d", 72 | iteration); 73 | 74 | // F() macro is supported too 75 | syslog.log(LOG_INFO, F("End loop")); 76 | iteration++; 77 | 78 | // wait ten seconds before sending log message again 79 | delay(10000); 80 | } 81 | -------------------------------------------------------------------------------- /examples/SimpleLoggingESP8266/SimpleLoggingESP8266.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Syslog client: SimpleLogging example 4 | 5 | Demonstrates logging messages to Syslog server in IETF format (rfc5424) in 6 | combination with the ESP8266 board/library. 7 | 8 | For more about Syslog see https://en.wikipedia.org/wiki/Syslog 9 | 10 | created 3 Nov 2016 11 | by Martin Sloup 12 | 13 | This code is in the public domain. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | // WIFI credentials 22 | #define WIFI_SSID "**************" 23 | #define WIFI_PASS "**************" 24 | 25 | // Syslog server connection info 26 | #define SYSLOG_SERVER "syslog-server" 27 | #define SYSLOG_PORT 514 28 | 29 | // This device info 30 | #define DEVICE_HOSTNAME "my-device" 31 | #define APP_NAME "my-app" 32 | 33 | // A UDP instance to let us send and receive packets over UDP 34 | WiFiUDP udpClient; 35 | 36 | // Create a new syslog instance with LOG_KERN facility 37 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN); 38 | int iteration = 1; 39 | 40 | void setup() { 41 | Serial.begin(115200); 42 | Serial.println(); 43 | Serial.println(); 44 | 45 | // We start by connecting to a WiFi network 46 | Serial.print("Connecting to "); 47 | Serial.println(WIFI_SSID); 48 | WiFi.begin(WIFI_SSID, WIFI_PASS); 49 | 50 | while (WiFi.status() != WL_CONNECTED) { 51 | delay(500); 52 | Serial.print("."); 53 | } 54 | Serial.println(""); 55 | 56 | Serial.println("WiFi connected"); 57 | Serial.println("IP address: "); 58 | Serial.println(WiFi.localIP()); 59 | } 60 | 61 | void loop() { 62 | // Severity levels can be found in Syslog.h. They are same like in Linux 63 | // syslog. 64 | syslog.log(LOG_INFO, "Begin loop"); 65 | 66 | // Log message can be formated like with printf function. 67 | syslog.logf(LOG_ERR, "This is error message no. %d", iteration); 68 | syslog.logf(LOG_INFO, "This is info message no. %d", iteration); 69 | 70 | // You can force set facility in pri parameter for this log message. More 71 | // facilities in syslog.h or in Linux syslog documentation. 72 | syslog.logf(LOG_DAEMON | LOG_INFO, "This is daemon info message no. %d", 73 | iteration); 74 | 75 | // F() macro is supported too 76 | syslog.log(LOG_INFO, F("End loop")); 77 | iteration++; 78 | 79 | // wait ten seconds before sending log message again 80 | delay(10000); 81 | } 82 | -------------------------------------------------------------------------------- /examples/SimpleLoggingWiFi/SimpleLoggingWiFi.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Syslog client: SimpleLogging example 4 | 5 | Demonstrates logging messages to Syslog server in IETF format (rfc5424) in 6 | combination with the WiFi library on Wifi shield. 7 | 8 | For more about Syslog see https://en.wikipedia.org/wiki/Syslog 9 | 10 | created 22 Jan 2017 11 | by Martin Sloup 12 | 13 | This code is in the public domain. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // WIFI credentials 23 | #define WIFI_SSID "**************" 24 | #define WIFI_PASS "**************" 25 | 26 | // Syslog server connection info 27 | #define SYSLOG_SERVER "syslog-server" 28 | #define SYSLOG_PORT 514 29 | 30 | // This device info 31 | #define DEVICE_HOSTNAME "my-device" 32 | #define APP_NAME "my-app" 33 | 34 | int status = WL_IDLE_STATUS; 35 | 36 | // A UDP instance to let us send and receive packets over UDP 37 | WiFiUDP udpClient; 38 | 39 | // Create a new syslog instance with LOG_KERN facility 40 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN); 41 | 42 | int iteration = 1; 43 | 44 | void setup() { 45 | // Open serial communications and wait for port to open: 46 | Serial.begin(9600); 47 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for native USB port only 49 | } 50 | 51 | // check for the presence of the shield: 52 | if (WiFi.status() == WL_NO_SHIELD) { 53 | Serial.println("WiFi shield not present"); 54 | // don't continue: 55 | while (true); 56 | } 57 | 58 | String fv = WiFi.firmwareVersion(); 59 | if (fv != "1.1.0") { 60 | Serial.println("Please upgrade the firmware"); 61 | } 62 | 63 | // attempt to connect to Wifi network: 64 | while (status != WL_CONNECTED) { 65 | Serial.print("Attempting to connect to SSID: "); 66 | Serial.println(WIFI_SSID); 67 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 68 | status = WiFi.begin(WIFI_SSID, WIFI_PASS); 69 | 70 | // wait 10 seconds for connection: 71 | delay(10000); 72 | } 73 | 74 | Serial.println("Connected to wifi"); 75 | printWifiStatus(); 76 | } 77 | 78 | void loop() { 79 | // Severity levels can be found in Syslog.h. They are same like in Linux 80 | // syslog. 81 | syslog.log(LOG_INFO, "Begin loop"); 82 | 83 | // Log message can be formated like with printf function. 84 | syslog.logf(LOG_ERR, "This is error message no. %d", iteration); 85 | syslog.logf(LOG_INFO, "This is info message no. %d", iteration); 86 | 87 | // You can force set facility in pri parameter for this log message. More 88 | // facilities in syslog.h or in Linux syslog documentation. 89 | syslog.logf(LOG_DAEMON | LOG_INFO, "This is daemon info message no. %d", 90 | iteration); 91 | 92 | // F() macro is supported too 93 | syslog.log(LOG_INFO, F("End loop")); 94 | iteration++; 95 | 96 | // wait ten seconds before sending log message again 97 | delay(10000); 98 | } 99 | 100 | void printWifiStatus() { 101 | // print the SSID of the network you're attached to: 102 | Serial.print("SSID: "); 103 | Serial.println(WiFi.SSID()); 104 | 105 | // print your WiFi shield's IP address: 106 | IPAddress ip = WiFi.localIP(); 107 | Serial.print("IP Address: "); 108 | Serial.println(ip); 109 | 110 | // print the received signal strength: 111 | long rssi = WiFi.RSSI(); 112 | Serial.print("signal strength (RSSI):"); 113 | Serial.print(rssi); 114 | Serial.println(" dBm"); 115 | } 116 | -------------------------------------------------------------------------------- /examples/SimpleLoggingWiFi101_MKR1000/SimpleLoggingWiFi101_MKR1000.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Syslog client: SimpleLogging example 4 | 5 | Demonstrates logging messages to Syslog server in IETF format (rfc5424) in 6 | combination with the WiFi library on Wifi101 shield or Arduino MKR1000. 7 | 8 | For more about Syslog see https://en.wikipedia.org/wiki/Syslog 9 | 10 | created 22 Jan 2017 11 | by Martin Sloup 12 | 13 | This code is in the public domain. 14 | 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // WIFI credentials 23 | #define WIFI_SSID "**************" 24 | #define WIFI_PASS "**************" 25 | 26 | // Syslog server connection info 27 | #define SYSLOG_SERVER "syslog-server" 28 | #define SYSLOG_PORT 514 29 | 30 | // This device info 31 | #define DEVICE_HOSTNAME "my-device" 32 | #define APP_NAME "my-app" 33 | 34 | int status = WL_IDLE_STATUS; 35 | 36 | // A UDP instance to let us send and receive packets over UDP 37 | WiFiUDP udpClient; 38 | 39 | // Create a new syslog instance with LOG_KERN facility 40 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN); 41 | 42 | int iteration = 1; 43 | 44 | void setup() { 45 | // Open serial communications and wait for port to open: 46 | Serial.begin(9600); 47 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for native USB port only 49 | } 50 | 51 | // check for the presence of the shield: 52 | if (WiFi.status() == WL_NO_SHIELD) { 53 | Serial.println("WiFi shield not present"); 54 | // don't continue: 55 | while (true); 56 | } 57 | 58 | // attempt to connect to Wifi network: 59 | while (status != WL_CONNECTED) { 60 | Serial.print("Attempting to connect to SSID: "); 61 | Serial.println(WIFI_SSID); 62 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 63 | status = WiFi.begin(WIFI_SSID, WIFI_PASS); 64 | 65 | // wait 10 seconds for connection: 66 | delay(10000); 67 | } 68 | 69 | Serial.println("Connected to wifi"); 70 | printWifiStatus(); 71 | } 72 | 73 | void loop() { 74 | // Severity levels can be found in Syslog.h. They are same like in Linux 75 | // syslog. 76 | syslog.log(LOG_INFO, "Begin loop"); 77 | 78 | // Log message can be formated like with printf function. 79 | syslog.logf(LOG_ERR, "This is error message no. %d", iteration); 80 | syslog.logf(LOG_INFO, "This is info message no. %d", iteration); 81 | 82 | // You can force set facility in pri parameter for this log message. More 83 | // facilities in syslog.h or in Linux syslog documentation. 84 | syslog.logf(LOG_DAEMON | LOG_INFO, "This is daemon info message no. %d", 85 | iteration); 86 | 87 | // F() macro is supported too 88 | syslog.log(LOG_INFO, F("End loop")); 89 | iteration++; 90 | 91 | // wait ten seconds before sending log message again 92 | delay(10000); 93 | } 94 | 95 | void printWifiStatus() { 96 | // print the SSID of the network you're attached to: 97 | Serial.print("SSID: "); 98 | Serial.println(WiFi.SSID()); 99 | 100 | // print your WiFi shield's IP address: 101 | IPAddress ip = WiFi.localIP(); 102 | Serial.print("IP Address: "); 103 | Serial.println(ip); 104 | 105 | // print the received signal strength: 106 | long rssi = WiFi.RSSI(); 107 | Serial.print("signal strength (RSSI):"); 108 | Serial.print(rssi); 109 | Serial.println(" dBm"); 110 | } 111 | -------------------------------------------------------------------------------- /examples/SimpleLoggingYun/SimpleLoggingYun.ino: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arcao/Syslog/e9c2eea7a91fdda3a55f9df2ebc122f3152da02d/examples/SimpleLoggingYun/SimpleLoggingYun.ino -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map syslog lib 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | Syslog KEYWORD1 9 | 10 | ####################################### 11 | # Methods and Functions (KEYWORD2) 12 | ####################################### 13 | log KEYWORD2 14 | logf KEYWORD2 15 | vlogf KEYWORD2 16 | server KEYWORD2 17 | deviceHostname KEYWORD2 18 | appName KEYWORD2 19 | defaultPriority KEYWORD2 20 | logMask KEYWORD2 21 | 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | LOG_EMERG LITERAL1 31 | LOG_ALERT LITERAL1 32 | LOG_CRIT LITERAL1 33 | LOG_ERR LITERAL1 34 | LOG_WARNING LITERAL1 35 | LOG_NOTICE LITERAL1 36 | LOG_INFO LITERAL1 37 | LOG_DEBUG LITERAL1 38 | 39 | LOG_KERN LITERAL1 40 | LOG_USER LITERAL1 41 | LOG_MAIL LITERAL1 42 | LOG_DAEMON LITERAL1 43 | LOG_AUTH LITERAL1 44 | LOG_SYSLOG LITERAL1 45 | LOG_LPR LITERAL1 46 | LOG_NEWS LITERAL1 47 | LOG_UUCP LITERAL1 48 | LOG_CRON LITERAL1 49 | LOG_AUTHPRIV LITERAL1 50 | LOG_FTP LITERAL1 51 | 52 | LOG_LOCAL0 LITERAL1 53 | LOG_LOCAL1 LITERAL1 54 | LOG_LOCAL2 LITERAL1 55 | LOG_LOCAL3 LITERAL1 56 | LOG_LOCAL4 LITERAL1 57 | LOG_LOCAL5 LITERAL1 58 | LOG_LOCAL6 LITERAL1 59 | LOG_LOCAL7 LITERAL1 60 | 61 | LOG_MASK LITERAL1 62 | LOG_UPTO LITERAL1 63 | 64 | SYSLOG_PROTO_IETF LITERAL1 65 | SYSLOG_PROTO_BSD LITERAL1 66 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Syslog", 3 | "keywords": "syslog,log,rfc5424,rfc3164,udp,ethernet,wifi,logging", 4 | "description": "A library for logging to Syslog server over UDP protocol. Both IETF (RFC 5424) and BSD (RFC 3164) Syslog message formats are supported.", 5 | "repository": 6 | { 7 | "type": "git", 8 | "url": "https://github.com/arcao/Syslog.git" 9 | }, 10 | "version": "2.0.0", 11 | "examples": "examples/*/*.ino", 12 | "frameworks": "arduino", 13 | "platforms": [ 14 | "atmelavr", 15 | "atmelsam", 16 | "espressif8266", 17 | "espressif32" 18 | ] 19 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Syslog 2 | version=2.0.0 3 | author=Martin Sloup 4 | maintainer=Martin Sloup 5 | sentence=A library for logging to Syslog server over UDP protocol. 6 | paragraph=Both IETF (RFC 5424) and BSD (RFC 3164) Syslog message formats are supported. 7 | category=Communication 8 | url=https://github.com/arcao/Syslog.git 9 | architectures=* 10 | includes=Syslog.h -------------------------------------------------------------------------------- /src/Syslog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "Syslog.h" 6 | 7 | // Public Methods ////////////////////////////////////////////////////////////// 8 | 9 | Syslog::Syslog(UDP &client, uint8_t protocol) { 10 | this->_client = &client; 11 | this->_protocol = protocol; 12 | this->_server = NULL; 13 | this->_port = 0; 14 | this->_deviceHostname = SYSLOG_NILVALUE; 15 | this->_appName = SYSLOG_NILVALUE; 16 | this->_priDefault = LOG_KERN; 17 | } 18 | 19 | Syslog::Syslog(UDP &client, const char* server, uint16_t port, const char* deviceHostname, const char* appName, uint16_t priDefault, uint8_t protocol) { 20 | this->_client = &client; 21 | this->_protocol = protocol; 22 | this->_server = server; 23 | this->_port = port; 24 | this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname; 25 | this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName; 26 | this->_priDefault = priDefault; 27 | } 28 | 29 | Syslog::Syslog(UDP &client, IPAddress ip, uint16_t port, const char* deviceHostname, const char* appName, uint16_t priDefault, uint8_t protocol) { 30 | this->_client = &client; 31 | this->_protocol = protocol; 32 | this->_ip = ip; 33 | this->_server = NULL; 34 | this->_port = port; 35 | this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname; 36 | this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName; 37 | this->_priDefault = priDefault; 38 | } 39 | 40 | Syslog &Syslog::server(const char* server, uint16_t port) { 41 | this->_server = server; 42 | this->_port = port; 43 | return *this; 44 | } 45 | 46 | Syslog &Syslog::server(IPAddress ip, uint16_t port) { 47 | this->_ip = ip; 48 | this->_server = NULL; 49 | this->_port = port; 50 | return *this; 51 | } 52 | 53 | Syslog &Syslog::deviceHostname(const char* deviceHostname) { 54 | this->_deviceHostname = (deviceHostname == NULL) ? SYSLOG_NILVALUE : deviceHostname; 55 | return *this; 56 | } 57 | 58 | Syslog &Syslog::appName(const char* appName) { 59 | this->_appName = (appName == NULL) ? SYSLOG_NILVALUE : appName; 60 | return *this; 61 | } 62 | 63 | Syslog &Syslog::defaultPriority(uint16_t pri) { 64 | this->_priDefault = pri; 65 | return *this; 66 | } 67 | 68 | Syslog &Syslog::logMask(uint8_t priMask) { 69 | this->_priMask = priMask; 70 | return *this; 71 | } 72 | 73 | 74 | bool Syslog::log(uint16_t pri, const __FlashStringHelper *message) { 75 | return this->_sendLog(pri, message); 76 | } 77 | 78 | bool Syslog::log(uint16_t pri, const String &message) { 79 | return this->_sendLog(pri, message.c_str()); 80 | } 81 | 82 | bool Syslog::log(uint16_t pri, const char *message) { 83 | return this->_sendLog(pri, message); 84 | } 85 | 86 | 87 | bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args) { 88 | char *message; 89 | size_t initialLen; 90 | size_t len; 91 | bool result; 92 | 93 | initialLen = strlen(fmt); 94 | 95 | message = new char[initialLen + 1]; 96 | 97 | len = vsnprintf(message, initialLen + 1, fmt, args); 98 | if (len > initialLen) { 99 | delete[] message; 100 | message = new char[len + 1]; 101 | 102 | vsnprintf(message, len + 1, fmt, args); 103 | } 104 | 105 | result = this->_sendLog(pri, message); 106 | 107 | delete[] message; 108 | return result; 109 | } 110 | 111 | bool Syslog::vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) { 112 | char *message; 113 | size_t initialLen; 114 | size_t len; 115 | bool result; 116 | 117 | initialLen = strlen_P(fmt_P); 118 | 119 | message = new char[initialLen + 1]; 120 | 121 | len = vsnprintf_P(message, initialLen + 1, fmt_P, args); 122 | if (len > initialLen) { 123 | delete[] message; 124 | message = new char[len + 1]; 125 | 126 | vsnprintf(message, len + 1, fmt_P, args); 127 | } 128 | 129 | result = this->_sendLog(pri, message); 130 | 131 | delete[] message; 132 | return result; 133 | } 134 | 135 | 136 | bool Syslog::logf(uint16_t pri, const char *fmt, ...) { 137 | va_list args; 138 | bool result; 139 | 140 | va_start(args, fmt); 141 | result = this->vlogf(pri, fmt, args); 142 | va_end(args); 143 | return result; 144 | } 145 | 146 | bool Syslog::logf(const char *fmt, ...) { 147 | va_list args; 148 | bool result; 149 | 150 | va_start(args, fmt); 151 | result = this->vlogf(this->_priDefault, fmt, args); 152 | va_end(args); 153 | return result; 154 | } 155 | 156 | bool Syslog::logf_P(uint16_t pri, PGM_P fmt_P, ...) { 157 | va_list args; 158 | bool result; 159 | 160 | va_start(args, fmt_P); 161 | result = this->vlogf_P(pri, fmt_P, args); 162 | va_end(args); 163 | return result; 164 | } 165 | 166 | bool Syslog::logf_P(PGM_P fmt_P, ...) { 167 | va_list args; 168 | bool result; 169 | 170 | va_start(args, fmt_P); 171 | result = this->vlogf_P(this->_priDefault, fmt_P, args); 172 | va_end(args); 173 | return result; 174 | } 175 | 176 | bool Syslog::log(const __FlashStringHelper *message) { 177 | return this->_sendLog(this->_priDefault, message); 178 | } 179 | 180 | bool Syslog::log(const String &message) { 181 | return this->_sendLog(this->_priDefault, message.c_str()); 182 | } 183 | 184 | bool Syslog::log(const char *message) { 185 | return this->_sendLog(this->_priDefault, message); 186 | } 187 | 188 | // Private Methods ///////////////////////////////////////////////////////////// 189 | 190 | inline bool Syslog::_sendLog(uint16_t pri, const char *message) { 191 | int result; 192 | 193 | if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) 194 | return false; 195 | 196 | // Check priority against priMask values. 197 | if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) 198 | return true; 199 | 200 | // Set default facility if none specified. 201 | if ((pri & LOG_FACMASK) == 0) 202 | pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); 203 | 204 | if (this->_server != NULL) { 205 | result = this->_client->beginPacket(this->_server, this->_port); 206 | } else { 207 | result = this->_client->beginPacket(this->_ip, this->_port); 208 | } 209 | 210 | if (result != 1) 211 | return false; 212 | 213 | // IETF Doc: https://tools.ietf.org/html/rfc5424 214 | // BSD Doc: https://tools.ietf.org/html/rfc3164 215 | this->_client->print('<'); 216 | this->_client->print(pri); 217 | if (this->_protocol == SYSLOG_PROTO_IETF) { 218 | this->_client->print(F(">1 - ")); 219 | } else { 220 | this->_client->print(F(">")); 221 | } 222 | this->_client->print(this->_deviceHostname); 223 | this->_client->print(' '); 224 | this->_client->print(this->_appName); 225 | if (this->_protocol == SYSLOG_PROTO_IETF) { 226 | this->_client->print(F(" - - - \xEF\xBB\xBF")); 227 | } else { 228 | this->_client->print(F("[0]: ")); 229 | } 230 | this->_client->print(message); 231 | this->_client->endPacket(); 232 | 233 | return true; 234 | } 235 | 236 | inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message) { 237 | int result; 238 | 239 | if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0) 240 | return false; 241 | 242 | // Check priority against priMask values. 243 | if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0) 244 | return true; 245 | 246 | // Set default facility if none specified. 247 | if ((pri & LOG_FACMASK) == 0) 248 | pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri); 249 | 250 | if (this->_server != NULL) { 251 | result = this->_client->beginPacket(this->_server, this->_port); 252 | } else { 253 | result = this->_client->beginPacket(this->_ip, this->_port); 254 | } 255 | 256 | if (result != 1) 257 | return false; 258 | 259 | // IETF Doc: https://tools.ietf.org/html/rfc5424 260 | // BSD Doc: https://tools.ietf.org/html/rfc3164 261 | this->_client->print('<'); 262 | this->_client->print(pri); 263 | if (this->_protocol == SYSLOG_PROTO_IETF) { 264 | this->_client->print(F(">1 - ")); 265 | } else { 266 | this->_client->print(F(">")); 267 | } 268 | this->_client->print(this->_deviceHostname); 269 | this->_client->print(' '); 270 | this->_client->print(this->_appName); 271 | if (this->_protocol == SYSLOG_PROTO_IETF) { 272 | this->_client->print(F(" - - - \xEF\xBB\xBF")); 273 | } else { 274 | this->_client->print(F("[0]: ")); 275 | } 276 | this->_client->print(message); 277 | this->_client->endPacket(); 278 | 279 | 280 | return true; 281 | } 282 | -------------------------------------------------------------------------------- /src/Syslog.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSLOG_H 2 | #define SYSLOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // undefine ugly logf macro from avr's math.h 11 | // this fix compilation errors on AtmelAVR platforms 12 | #if defined(logf) 13 | #undef logf 14 | #endif 15 | 16 | // compatibility with other platforms 17 | // add missing vsnprintf_P method 18 | #if !defined(ARDUINO_ARCH_AVR) && !defined(ARDUINO_ARCH_ESP8266) && !defined(vsnprintf_P) && !defined(ESP8266) 19 | #define vsnprintf_P(buf, len, fmt, args) vsnprintf((buf), (len), (fmt), (args)) 20 | #endif 21 | 22 | #define SYSLOG_NILVALUE "-" 23 | 24 | // Syslog protocol format 25 | #define SYSLOG_PROTO_IETF 0 // RFC 5424 26 | #define SYSLOG_PROTO_BSD 1 // RFC 3164 27 | 28 | /* 29 | * priorities/facilities are encoded into a single 32-bit quantity, where the 30 | * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility 31 | * (0-big number). Both the priorities and the facilities map roughly 32 | * one-to-one to strings in the syslogd(8) source code. This mapping is 33 | * included in this file. 34 | * 35 | * priorities (these are ordered) 36 | */ 37 | #define LOG_EMERG 0 /* system is unusable */ 38 | #define LOG_ALERT 1 /* action must be taken immediately */ 39 | #define LOG_CRIT 2 /* critical conditions */ 40 | #define LOG_ERR 3 /* error conditions */ 41 | #define LOG_WARNING 4 /* warning conditions */ 42 | #define LOG_NOTICE 5 /* normal but significant condition */ 43 | #define LOG_INFO 6 /* informational */ 44 | #define LOG_DEBUG 7 /* debug-level messages */ 45 | 46 | #define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ 47 | /* extract priority */ 48 | #define LOG_PRI(p) ((p) & LOG_PRIMASK) 49 | #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) 50 | 51 | /* facility codes */ 52 | #define LOG_KERN (0<<3) /* kernel messages */ 53 | #define LOG_USER (1<<3) /* random user-level messages */ 54 | #define LOG_MAIL (2<<3) /* mail system */ 55 | #define LOG_DAEMON (3<<3) /* system daemons */ 56 | #define LOG_AUTH (4<<3) /* security/authorization messages */ 57 | #define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ 58 | #define LOG_LPR (6<<3) /* line printer subsystem */ 59 | #define LOG_NEWS (7<<3) /* network news subsystem */ 60 | #define LOG_UUCP (8<<3) /* UUCP subsystem */ 61 | #define LOG_CRON (9<<3) /* clock daemon */ 62 | #define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ 63 | #define LOG_FTP (11<<3) /* ftp daemon */ 64 | 65 | /* other codes through 15 reserved for system use */ 66 | #define LOG_LOCAL0 (16<<3) /* reserved for local use */ 67 | #define LOG_LOCAL1 (17<<3) /* reserved for local use */ 68 | #define LOG_LOCAL2 (18<<3) /* reserved for local use */ 69 | #define LOG_LOCAL3 (19<<3) /* reserved for local use */ 70 | #define LOG_LOCAL4 (20<<3) /* reserved for local use */ 71 | #define LOG_LOCAL5 (21<<3) /* reserved for local use */ 72 | #define LOG_LOCAL6 (22<<3) /* reserved for local use */ 73 | #define LOG_LOCAL7 (23<<3) /* reserved for local use */ 74 | 75 | #define LOG_NFACILITIES 24 /* current number of facilities */ 76 | #define LOG_FACMASK 0x03f8 /* mask to extract facility part */ 77 | /* facility of pri */ 78 | #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) 79 | 80 | #define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ 81 | #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ 82 | 83 | class Syslog { 84 | private: 85 | UDP* _client; 86 | uint8_t _protocol; 87 | IPAddress _ip; 88 | const char* _server; 89 | uint16_t _port; 90 | const char* _deviceHostname; 91 | const char* _appName; 92 | uint16_t _priDefault; 93 | uint8_t _priMask = 0xff; 94 | 95 | bool _sendLog(uint16_t pri, const char *message); 96 | bool _sendLog(uint16_t pri, const __FlashStringHelper *message); 97 | 98 | public: 99 | Syslog(UDP &client, uint8_t protocol = SYSLOG_PROTO_IETF); 100 | Syslog(UDP &client, const char* server, uint16_t port, const char* deviceHostname = SYSLOG_NILVALUE, const char* appName = SYSLOG_NILVALUE, uint16_t priDefault = LOG_KERN, uint8_t protocol = SYSLOG_PROTO_IETF); 101 | Syslog(UDP &client, IPAddress ip, uint16_t port, const char* deviceHostname = SYSLOG_NILVALUE, const char* appName = SYSLOG_NILVALUE, uint16_t priDefault = LOG_KERN, uint8_t protocol = SYSLOG_PROTO_IETF); 102 | 103 | Syslog &server(const char* server, uint16_t port); 104 | Syslog &server(IPAddress ip, uint16_t port); 105 | Syslog &deviceHostname(const char* deviceHostname); 106 | Syslog &appName(const char* appName); 107 | Syslog &defaultPriority(uint16_t pri = LOG_KERN); 108 | 109 | Syslog &logMask(uint8_t priMask); 110 | 111 | bool log(uint16_t pri, const __FlashStringHelper *message); 112 | bool log(uint16_t pri, const String &message); 113 | bool log(uint16_t pri, const char *message); 114 | 115 | bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); 116 | bool vlogf_P(uint16_t pri, PGM_P fmt_P, va_list args) __attribute__((format(printf, 3, 0))); 117 | 118 | bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4))); 119 | bool logf(const char *fmt, ...) __attribute__((format(printf, 2, 3))); 120 | 121 | bool logf_P(uint16_t pri, PGM_P fmt_P, ...) __attribute__((format(printf, 3, 4))); 122 | bool logf_P(PGM_P fmt_P, ...) __attribute__((format(printf, 2, 3))); 123 | 124 | bool log(const __FlashStringHelper *message); 125 | bool log(const String &message); 126 | bool log(const char *message); 127 | }; 128 | 129 | #endif 130 | --------------------------------------------------------------------------------