Skip to content

Commit

Permalink
Keep the houselog API compatible with previous releases
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin committed Jan 18, 2022
1 parent 7ccd05a commit 11f80b5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ This initializes the memory storage for the recent logs and register all the URI

It is possible to force a different history storage path with the "-log=PATH" command line option. This is however not recommended.

This function consumes the same "--portal-host=NAME" option as houseportal_initialize.
```
void houselog_event (const char *category,
const char *object,
Expand Down
2 changes: 1 addition & 1 deletion housediscoverclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int main (int argc, const char **argv) {

echttp_open (optioncount, option);
echttp_background (&background);
houselog_initialize ("discovery", 0, argc, argv);
houselog_initialize ("discovery", argc, argv);
housediscover_initialize (optioncount, option);

echttp_loop();
Expand Down
16 changes: 9 additions & 7 deletions houselog.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* SYNOPSYS:
*
* void houselog_initialize (const char *application,
* const char *portal,
* int argc, const char **argv);
*
* Initialize the environment required to record logs. This must be
Expand Down Expand Up @@ -87,9 +86,9 @@
static const char *LogTypes = "et";
static const char *LogFolder = "/var/lib/house/log";
static const char *LogName = "portal";
static const char *PortalHost = 0;

static char LocalHost[256] = {0};
static char PortalHost[256] = {0};

struct EventHistory {
struct timeval timestamp;
Expand Down Expand Up @@ -287,7 +286,7 @@ static int houselog_getheader (time_t now, char *buffer, int size) {

echttp_content_type_json ();

if (PortalHost[0]) {
if (PortalHost) {
return snprintf (buffer, size,
"{\"host\":\"%s\",\"proxy\":\"%s\",\"apps\":[\"%s\"],"
"\"timestamp\":%ld,\"%s\":{\"latest\":%ld",
Expand Down Expand Up @@ -501,19 +500,22 @@ static void houselog_restore (const struct tm *local, char id) {
}
}

void houselog_initialize (const char *name,
const char *portal, int argc, const char **argv) {
void houselog_initialize (const char *name, int argc, const char **argv) {
int i;
char uri[256];
const char *folder;
const char *portal = 0;

for (i = 1; i < argc; ++i) {
if (echttp_option_match ("-log=", argv[i], &folder))
if (echttp_option_match ("-log=", argv[i], &folder)) {
LogFolder = folder;
continue;
}
if (echttp_option_match("-portal-server=", argv[i], &portal)) continue;
}
if (name) LogName = strdup(name);
gethostname (LocalHost, sizeof(LocalHost));
if (portal) snprintf (PortalHost, sizeof(PortalHost), "%s", portal);
PortalHost = portal ? portal : LocalHost;

snprintf (uri, sizeof(uri), "/%s/log/traces", LogName);
echttp_route_uri (strdup(uri), houselog_webget);
Expand Down
4 changes: 1 addition & 3 deletions houselog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
*/
#include <time.h>

void houselog_initialize (const char *application,
const char *portal,
int argc, const char **argv);
void houselog_initialize (const char *name, int argc, const char **argv);

void houselog_trace (const char *file, int line, const char *level,
const char *object,
Expand Down
2 changes: 1 addition & 1 deletion houseportal.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main (int argc, const char **argv) {
gethostname (HostName, sizeof(HostName));

echttp_open (argc, argv);
houselog_initialize ("portal", 0, argc, argv);
houselog_initialize ("portal", argc, argv);
echttp_cors_allow_method("GET");
echttp_protect (0, hp_portal_protect);

Expand Down

0 comments on commit 11f80b5

Please sign in to comment.