[ctxt] add logging
This commit is contained in:
parent
f2b0c145a0
commit
d964f03b0b
2
src/ax.h
2
src/ax.h
|
@ -18,7 +18,7 @@ void ax_free(struct ax_ctxt* ax);
|
||||||
|
|
||||||
const char* ax_get_error(struct ax_ctxt* ax);
|
const char* ax_get_error(struct ax_ctxt* ax);
|
||||||
|
|
||||||
void ax_set_logger_fd(struct ax_ctxt* ax, int fd);
|
void ax_set_logger(struct ax_ctxt* ax, int fd, bool auto_close);
|
||||||
void ax_log(struct ax_ctxt* ax, const char* string);
|
void ax_log(struct ax_ctxt* ax, const char* string);
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "util/region.h"
|
#include "util/region.h"
|
||||||
|
|
||||||
struct ax_theme;
|
struct ax_theme;
|
||||||
|
@ -8,6 +10,10 @@ struct ax_theme_builder;
|
||||||
struct ax_ctxt {
|
struct ax_ctxt {
|
||||||
struct rgn* init_rgn;
|
struct rgn* init_rgn;
|
||||||
|
|
||||||
|
// logging
|
||||||
|
FILE* log_out;
|
||||||
|
bool log_auto_close;
|
||||||
|
|
||||||
// errors
|
// errors
|
||||||
struct rgn err_rgn;
|
struct rgn err_rgn;
|
||||||
const char* err;
|
const char* err;
|
||||||
|
|
|
@ -38,6 +38,9 @@ void ax__ctxt_init(struct ax_ctxt* ax, struct rgn* init_rgn)
|
||||||
{
|
{
|
||||||
ax->init_rgn = init_rgn;
|
ax->init_rgn = init_rgn;
|
||||||
|
|
||||||
|
ax->log_out = NULL;
|
||||||
|
ax->log_auto_close = false;
|
||||||
|
|
||||||
rgn_init(&ax->err_rgn, SMALL);
|
rgn_init(&ax->err_rgn, SMALL);
|
||||||
ax->err = "";
|
ax->err = "";
|
||||||
|
|
||||||
|
@ -52,6 +55,26 @@ void ax__ctxt_cleanup(struct ax_ctxt* ax)
|
||||||
rgn_cleanup(&ax->err_rgn);
|
rgn_cleanup(&ax->err_rgn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* API functions :: logging
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void ax_set_logger(struct ax_ctxt* ax, int fd, bool auto_close)
|
||||||
|
{
|
||||||
|
if (ax->log_auto_close) {
|
||||||
|
fclose(ax->log_out);
|
||||||
|
}
|
||||||
|
ax->log_out = fdopen(fd, "w");
|
||||||
|
ax->log_auto_close = auto_close;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ax_log(struct ax_ctxt* ax, const char* string)
|
||||||
|
{
|
||||||
|
if (ax->log_out != NULL) {
|
||||||
|
fprintf(ax->log_out, "[LOG] %s\n", string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* API functions :: themes
|
* API functions :: themes
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
|
@ -116,5 +139,6 @@ int ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm)
|
||||||
}
|
}
|
||||||
// TODO: see if font is loaded
|
// TODO: see if font is loaded
|
||||||
ax->sel_theme = thm;
|
ax->sel_theme = thm;
|
||||||
|
ax_log(ax, "theme selected");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
struct ax_ctxt* ax = ax_new();
|
struct ax_ctxt* ax = ax_new();
|
||||||
|
ax_set_logger(ax, 0, false);
|
||||||
|
|
||||||
int rv;
|
int rv;
|
||||||
#define GUARD(f, ...) if ((rv = f(__VA_ARGS__)) != 0) goto cleanup
|
#define GUARD(f, ...) if ((rv = f(__VA_ARGS__)) != 0) goto cleanup
|
||||||
|
|
||||||
|
@ -17,7 +19,7 @@ int main(void)
|
||||||
struct ax_theme* thm;
|
struct ax_theme* thm;
|
||||||
ax_end_theme(ax, &thm);
|
ax_end_theme(ax, &thm);
|
||||||
|
|
||||||
printf("----\ngot here\n----\n");
|
ax_log(ax, "got here");
|
||||||
|
|
||||||
if ((rv = ax_select_theme(ax, thm)) != 0) {
|
if ((rv = ax_select_theme(ax, thm)) != 0) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
Loading…
Reference in New Issue