1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-02-02 15:09:23 -05:00

more logging options better output

This commit is contained in:
John Sebastian Peterson 2024-09-09 12:50:21 +03:00
parent 0b9223ea42
commit 657625db40
8 changed files with 53 additions and 32 deletions

View File

@ -14,7 +14,7 @@ inline int operator<(JSValueConst a, JSValueConst b)
extern "C" {
#endif
#ifdef ECMASCRIPT_DEBUG
#ifdef ECMASCRIPT_DEBUG_OBJ
#define RETURN_JS(obj) \
fprintf(stderr, "%s:%d obj=%p\n", __FILE__, __LINE__, JS_VALUE_GET_PTR(obj)); \

View File

@ -25,7 +25,7 @@
* config.h. */
#include "setup.h"
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_MEMLEAK
#define DEBUG_MEMLEAK
#endif

View File

@ -13,7 +13,7 @@ extern "C" {
struct elinks_object {
int refcount;
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_OBJ
char *name;
#endif
};
@ -28,7 +28,7 @@ struct object_head {
#ifdef DEBUG_REFCOUNT
#include "util/error.h"
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_OBJ
#define object_lock_debug(obj, info) \
DBG("object %s[%p] lock %s to %d", (obj)->object.name, obj, \
info, (obj)->object.refcount)
@ -40,7 +40,7 @@ struct object_head {
#define object_lock_debug(obj, info)
#endif /* DEBUG_REFCOUNT */
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_OBJ
#include "util/error.h"
#define object_sanity_check(obj) \
do { \

View File

@ -125,6 +125,16 @@
#define FG_POLL_TIME 500
#define TERMINAL_POLL_TIMEOUT 1000
//#define ECMASCRIPT_DEBUG 1
#ifdef CONFIG_DEBUG
//#define CONFIG_ASSERT
//#define CONFIG_DEBUG_DUMP
//#define CONFIG_DEBUG_LIST
//#define CONFIG_DEBUG_MEMLEAK
//#define CONFIG_DEBUG_MEMLIST
//#define CONFIG_DEBUG_OBJ
//#define CONFIG_DEBUG_STRING
// #define ECMASCRIPT_DEBUG
//#define ECMASCRIPT_DEBUG_OBJ
#endif
#endif

View File

@ -52,6 +52,7 @@ er(int bell, int shall_sleep, const char *fmt, va_list params)
int errline;
const char *errfile;
const char *errfun;
void
elinks_debug(const char *fmt, ...)
@ -110,13 +111,13 @@ elinks_internal(const char *fmt, ...)
va_start(params, fmt);
snprintf(errbuf, sizeof(errbuf),
"\033[1mINTERNAL ERROR\033[0m at %s:%d: %s",
errfile, errline, fmt);
"\033[1mINTERNAL ERROR\033[0m at %s %d %s: %s",
errfile, errline, errfun, fmt);
er(1, 1, errbuf, params);
va_end(params);
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_DUMP
force_dump();
#endif
}
@ -191,25 +192,26 @@ done_log(void)
loctime);
errbuf[len] = '\0';
fprintf(log_file, "[%-5s %-15s %4s]: Log stopped at %s\n\n\n",
fprintf(log_file, "[%-5s %-15s %4s]: Log stopped at %s\n",
"", "", "", errbuf);
fclose(log_file);
}
void
elinks_log(char *msg, char *file, int line,
elinks_log(char *msg, char *file, int line,char*fun,
const char *fmt, ...)
{
static char *log_files = NULL;
static char *log_msg = NULL;
char errbuf[4096];
char tbuf[32];
va_list params;
time_t curtime = time(NULL);
struct tm *loctime = localtime(&curtime);
if (!log_file) {
char *log_name;
time_t curtime = time(NULL);
struct tm *loctime = localtime(&curtime);
int len;
log_files = getenv("ELINKS_FILES");
@ -223,8 +225,7 @@ elinks_log(char *msg, char *file, int line,
loctime);
errbuf[len] = '\0';
fprintf(log_file, "\n\n[%-5s %-15s %4s]: Log started at %s\n",
"type", "file", "line", errbuf);
fprintf(log_file, "Log started at %s\n",errbuf);
atexit(done_log);
}
@ -237,8 +238,9 @@ elinks_log(char *msg, char *file, int line,
va_start(params, fmt);
snprintf(errbuf, sizeof(errbuf), "[%-5s %-15s %4d]: %s",
msg, file, line, fmt);
strftime(tbuf, sizeof(tbuf), "%T", loctime);
snprintf(errbuf, sizeof(errbuf), "[%s %s %s %d %s]: %s",
tbuf, msg, file, line, fun, fmt);
vfprintf(log_file, errbuf, params);
fputc('\n', log_file);

View File

@ -13,10 +13,14 @@
extern "C" {
#endif
#include "main/main.h"
/* This errfile thing is needed, as we don't have var-arg macros in standart,
* only as gcc extension :(. */
extern int errline;
extern const char *errfile;
extern const char *errfun;
/** @c DBG(format_string) is used for printing of debugging information. It
* should not be used anywhere in the official codebase (although it is often
@ -48,7 +52,7 @@ void elinks_error(const char *fmt, ...);
* run. It tries to draw user's attention to the error and dumps core if ELinks
* is running in the CONFIG_DEBUG mode. */
#undef INTERNAL
#define INTERNAL errfile = __FILE__, errline = __LINE__, elinks_internal
#define INTERNAL errfile = __FILE__, errline = __LINE__, errfun = __FUNCTION__, elinks_internal
void elinks_internal(const char *fmt, ...);
@ -74,26 +78,31 @@ void usrerror(const char *fmt, ...);
* </dl>
*/
void
elinks_log(char *msg, char *file, int line,
elinks_log(char *msg, char *file, int line,char*,
const char *fmt, ...);
#undef LOG_JS
#define LOG_JS(args...) \
if (program.testjs)\
elinks_log("js", __FILE__, __LINE__,__FUNCTION__, args)
#undef LOG_ERR
#define LOG_ERR(args...) \
elinks_log("error", __FILE__, __LINE__, args)
elinks_log("error", __FILE__, __LINE__,__FUNCTION__, args)
#undef LOG_WARN
#define LOG_WARN(args...) \
elinks_log("warn", __FILE__, __LINE__, args)
elinks_log("warn", __FILE__, __LINE__,__FUBCTION__, args)
#undef LOG_INFO
#define LOG_INFO(args...) \
elinks_log("info", __FILE__, __LINE__, args)
elinks_log("info", __FILE__, __LINE__,__FUNCTION__, args)
#undef LOG_DBG
#define LOG_DBG(args...) \
elinks_log("debug", __FILE__, __LINE__, args)
elinks_log("debug", __FILE__, __LINE__,__FUNCTION__, args)
#endif
#endif // CONFIG_DEBUG
#endif
@ -104,7 +113,7 @@ elinks_log(char *msg, char *file, int line,
* recovery path, see below ::if_assert_failed. */
#undef assert
#ifdef CONFIG_FASTMEM
#ifndef CONFIG_ASSERT
#define assert(x) /* We don't do anything in CONFIG_FASTMEM mode. */
#else
#define assert(x) \
@ -123,7 +132,7 @@ do { if (!assert_failed && (assert_failed = !(x))) { \
#undef assertm
#ifdef HAVE_VARIADIC_MACROS
#ifdef CONFIG_FASTMEM
#ifndef CONFIG_ASSERT
#define assertm(x,m...) /* We don't do anything in CONFIG_FASTMEM mode. */
#else
#define assertm(x,m...) \
@ -132,7 +141,7 @@ do { if (!assert_failed && (assert_failed = !(x))) { \
} } while (0)
#endif
#else /* HAVE_VARIADIC_MACROS */
#ifdef CONFIG_FASTMEM
#ifndef CONFIG_ASSERT
#define assertm elinks_assertm
#else
#define assertm errfile = __FILE__, errline = __LINE__, elinks_assertm
@ -144,11 +153,11 @@ do { if (!assert_failed && (assert_failed = !(x))) { \
* expression is int (and that's completely fine, I do *NOT* want to see any
* stinking assert((int) pointer) ! ;-)), so CONFIG_DEBUG (-Werror) and
* !HAVE_VARIADIC_MACROS won't play well together. Hrm. --pasky */
#ifdef CONFIG_FASTMEM
#ifndef CONFIG_ASSERT
static inline
#endif
void elinks_assertm(int x, const char *fmt, ...)
#ifdef CONFIG_FASTMEM
#ifndef CONFIG_ASSERT
{
/* We don't do anything in CONFIG_FASTMEM mode. Let's hope that the compiler
* will at least optimize out the @x computation. */
@ -187,7 +196,7 @@ void elinks_assertm(int x, const char *fmt, ...)
extern int assert_failed;
#undef if_assert_failed
#ifdef CONFIG_FASTMEM
#ifndef CONFIG_ASSERT
#define if_assert_failed if (0) /* This should be optimalized away. */
#else
#define if_assert_failed if (assert_failed && !(assert_failed = 0))

View File

@ -11,7 +11,7 @@ struct memory_list {
};
#undef DEBUG_MEMLIST
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_MEMLIST
#define DEBUG_MEMLIST
#endif

View File

@ -152,7 +152,7 @@ int elinks_isspace(int c);
/** String debugging using magic number, it may catch some errors. */
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_STRING
#define DEBUG_STRING
#endif