Skip to content

Commit

Permalink
dbg: remove support for logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh committed Apr 28, 2024
1 parent 2b3bbaf commit 2267b79
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 43 deletions.
1 change: 0 additions & 1 deletion include/re_dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ typedef void (dbg_print_h)(int level, const char *p, size_t len, void *arg);

void dbg_init(int level, enum dbg_flags flags);
void dbg_close(void);
int dbg_logfile_set(const char *name);
void dbg_handler_set(dbg_print_h *ph, void *arg);
void dbg_printf(int level, const char *fmt, ...);
const char *dbg_level_str(int level);
Expand Down
44 changes: 2 additions & 42 deletions src/dbg/dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ static struct {
enum dbg_flags flags; /**< Debug flags */
dbg_print_h *ph; /**< Optional print handler */
void *arg; /**< Handler argument */
FILE *f; /**< Logfile */
} dbg = {
0,
DBG_INFO,
DBG_ANSI,
NULL,
NULL,
NULL,
};

static once_flag flag = ONCE_FLAG_INIT;
Expand Down Expand Up @@ -82,37 +80,6 @@ void dbg_init(int level, enum dbg_flags flags)
*/
void dbg_close(void)
{
if (dbg.f) {
(void)fclose(dbg.f);
dbg.f = NULL;
}
}


/**
* Set debug logfile
*
* @param name Name of the logfile, NULL to close
*
* @return 0 if success, otherwise errorcode
*/
int dbg_logfile_set(const char *name)
{
int err;

dbg_close();

if (!name)
return 0;

err = fs_fopen(&dbg.f, name, "a+");
if (err)
return err;

(void)re_fprintf(dbg.f, "\n===== Log Started: %H", fmt_gmtime, NULL);
(void)fflush(dbg.f);

return 0;
}


Expand Down Expand Up @@ -180,7 +147,7 @@ static void dbg_vprintf(int level, const char *fmt, va_list ap)
}


/* Formatted output to print handler and/or logfile */
/* Formatted output to print handler */
static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
{
char buf[256];
Expand All @@ -191,10 +158,9 @@ static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
if (level > dbg.level)
goto out;

if (!dbg.ph && !dbg.f)
if (!dbg.ph)
goto out;


len = re_vsnprintf(buf, sizeof(buf), fmt, ap);
if (len <= 0)
goto out;
Expand All @@ -204,12 +170,6 @@ static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap)
dbg.ph(level, buf, len, dbg.arg);
}

/* Output to file */
if (dbg.f) {
if (fwrite(buf, 1, len, dbg.f) > 0)
(void)fflush(dbg.f);
}

out:
dbg_unlock();
}
Expand Down

0 comments on commit 2267b79

Please sign in to comment.