Skip to content

Commit 53bd4a0

Browse files
committed
Refactor host stuff
1 parent 0d51252 commit 53bd4a0

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

Diff for: keywords.txt

-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ encode KEYWORD2
2121
# Constants (LITERAL1)
2222
#######################################
2323

24-
GRAYLOG_DEFAULT_HOST LITERAL1
2524
GRAYLOG_UDP_DEFAULT_PORT LITERAL1

Diff for: src/Message.h

+6-10
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@
77
// TODO: different amounts of memory depending on the platform!
88

99
#ifdef ESP8266
10-
#include <ESP8266WiFi.h>
10+
#include <ESP8266WiFi.h>
11+
#define _GELF_HOST (WiFi.hostname())
12+
#else
13+
#define _GELF_HOST ("graylog-default-host")
1114
#endif
1215

13-
#define GRAYLOG_DEFAULT_HOST "graylog-default-host"
14-
1516
class Message
1617
{
1718
public:
1819
explicit Message(const char *short_message) {
19-
2020
_json["version"] = "1.1";
21-
#ifdef ESP8266
22-
_json["host"] = WiFi.hostname();
23-
#else
24-
_json["host"] = GRAYLOG_DEFAULT_HOST;
25-
#endif
21+
_json["host"] = _GELF_HOST;
2622
_json["short_message"] = short_message;
2723
}
2824

2925
template<typename T>
30-
void set(const char *field, T value) {
26+
void set(const char *field, const T value) {
3127
if (strncmp("id", field, 2) == 0 || strncmp("_id", field, 3) == 0) {
3228
return;
3329
}

Diff for: src/UDPTransport.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ class UDPTransport : public Transport
1515
public:
1616
explicit UDPTransport(char *host, int port = GRAYLOG_UDP_DEFAULT_PORT);
1717
explicit UDPTransport(IPAddress ip_address, int port = GRAYLOG_UDP_DEFAULT_PORT);
18-
19-
void send(Message *message) override;
2018
private:
19+
void send(Message *message) override;
20+
void beginPacket();
21+
2122
char *_host = nullptr;
2223
IPAddress _ip_address;
2324
int _port = 0;
2425

2526
WiFiUDP _udp = WiFiUDP();
26-
27-
void beginPacket();
2827
};
2928

3029
#endif

0 commit comments

Comments
 (0)