1
0
mirror of https://github.com/rtbrick/bngblaster.git synced 2024-05-06 15:54:57 +00:00

add log message buffer

The log message buffer is used to display in
the ncurses log window even those messages
logged before ncurses has started.
This commit is contained in:
Christian Giese
2022-10-19 13:39:21 +00:00
committed by Christian Giese
parent 842d0103e4
commit b41d4947ab
5 changed files with 87 additions and 8 deletions

View File

@@ -20,7 +20,8 @@ char *g_log_file = NULL;
* Format the logging timestamp.
*/
char *
log_format_timestamp(void) {
log_format_timestamp(void)
{
static char ts_str[sizeof("Jun 19 08:07:13.711541")];
struct timespec now;
struct tm tm;
@@ -39,7 +40,8 @@ log_format_timestamp(void) {
* Enable logging.
*/
void
log_enable(char *log_name) {
log_enable(char *log_name)
{
int idx;
if(!log_name) {
return;
@@ -57,7 +59,8 @@ log_enable(char *log_name) {
* Open log file.
*/
void
log_open() {
log_open()
{
if(!g_log_file) {
return;
}
@@ -68,7 +71,8 @@ log_open() {
* Close log file.
*/
void
log_close() {
log_close()
{
if(g_log_fp) {
fclose(g_log_fp);
g_log_fp = NULL;
@@ -79,7 +83,8 @@ log_close() {
* Return log usage string.
*/
char *
log_usage() {
log_usage()
{
static char buf[128];
struct keyval_ *ptr;
int len = 0;
@@ -90,4 +95,4 @@ log_usage() {
ptr++;
}
return buf;
}
}

View File

@@ -13,6 +13,7 @@
#include "common.h"
extern char *g_log_file;
extern FILE *g_log_fp;
extern keyval_t log_names[];
@@ -55,6 +56,12 @@ struct __attribute__((__packed__)) log_id_
#ifdef NCURSES_ENABLED
extern bool g_interactive; /* interactive mode using ncurses */
#define LOG_BUF_STR_LEN 256
#define LOG_BUF_LINES 128
extern char *g_log_buf;
extern uint8_t g_log_buf_cur;
#define LOG(log_id_, fmt_, ...) \
do { \
if(g_log_fp) { \
@@ -65,11 +72,17 @@ extern bool g_interactive; /* interactive mode using ncurses */
if(g_interactive) { \
if (log_id[log_id_].enable) { \
wprintw(log_win, "%s "fmt_, log_format_timestamp(), ##__VA_ARGS__); \
wrefresh(log_win); \
wrefresh(log_win); \
} \
} else { \
if (log_id[log_id_].enable) { \
fprintf(stdout, "%s "fmt_, log_format_timestamp(), ##__VA_ARGS__); \
if(g_log_buf) { \
snprintf(g_log_buf+((g_log_buf_cur++)*LOG_BUF_STR_LEN), LOG_BUF_STR_LEN, "%s "fmt_, log_format_timestamp(), ##__VA_ARGS__); \
if(g_log_buf_cur >= LOG_BUF_LINES) { \
g_log_buf_cur = 0; \
} \
} \
} \
} \
} while(0)
@@ -89,9 +102,16 @@ extern bool g_interactive; /* interactive mode using ncurses */
} else { \
if (log_id[log_id_].enable) { \
fprintf(stdout, "%s "fmt_, log_format_timestamp()); \
if(g_log_buf) { \
snprintf(g_log_buf+((g_log_buf_cur++)*LOG_BUF_STR_LEN), LOG_BUF_STR_LEN, "%s "fmt_, log_format_timestamp()); \
if(g_log_buf_cur >= LOG_BUF_LINES) { \
g_log_buf_cur = 0; \
} \
} \
} \
} \
} while(0)
#else
#define LOG(log_id_, fmt_, ...) \
do { \