mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-23 11:44:53 +00:00
Remove mg_log_set_callback. Use MG_PUTCHAR macro instead
This commit is contained in:
1 parent
7c17c806ad
commit
7e2ca72310
15 files changed
+124
-188
No files matched your search
@@ -15,8 +15,6 @@
|
||||
|
||||
#include <rl_net.h>
|
||||
|
||||
#define MG_IO_SIZE 512
|
||||
#define MG_SOCK_LISTEN_BACKLOG_SIZE 1
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
typedef int socklen_t;
|
||||
#define closesocket(x) closesocket(x)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MG_PUTCHAR(x) printk("%c", x)
|
||||
#define strerror(x) zsock_gai_strerror(x)
|
||||
#define FD_CLOEXEC 0
|
||||
#define F_SETFD 0
|
||||
|
||||
@@ -98,3 +98,7 @@
|
||||
#define MG_ENABLE_FILE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MG_PUTCHAR
|
||||
#define MG_PUTCHAR(x) putchar(x)
|
||||
#endif
|
||||
@@ -1,24 +1,17 @@
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
|
||||
static void logc(int c) {
|
||||
putchar(c);
|
||||
static const char *s_spec = "2";
|
||||
|
||||
static void logc(unsigned char c) {
|
||||
MG_PUTCHAR(c);
|
||||
}
|
||||
|
||||
static void logs(const char *buf, size_t len) {
|
||||
size_t i;
|
||||
for (i = 0; i < len; i++) logc(buf[i]);
|
||||
for (i = 0; i < len; i++) logc(((unsigned char *) buf)[i]);
|
||||
}
|
||||
|
||||
static void mg_log_stdout(const void *buf, size_t len, void *userdata) {
|
||||
(void) userdata, (void) buf, (void) len;
|
||||
logs((const char *) buf, len);
|
||||
}
|
||||
|
||||
static const char *s_spec = "2";
|
||||
static void (*s_fn)(const void *, size_t, void *) = mg_log_stdout;
|
||||
static void *s_fn_param = NULL;
|
||||
|
||||
void mg_log_set(const char *spec) {
|
||||
MG_DEBUG(("Setting log level to %s", spec));
|
||||
s_spec = spec;
|
||||
@@ -30,8 +23,6 @@ bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
struct mg_str k, v, s = mg_str(s_spec);
|
||||
const char *p = strrchr(file, '/');
|
||||
|
||||
if (s_fn == NULL) return false;
|
||||
|
||||
if (p == NULL) p = strrchr(file, '\\');
|
||||
p = p == NULL ? file : p + 1;
|
||||
|
||||
@@ -46,8 +37,7 @@ bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
level, p, line, fname);
|
||||
if (n > sizeof(buf) - 2) n = sizeof(buf) - 2;
|
||||
while (n < sizeof(buf)) buf[n++] = ' ';
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
s_fn(buf, n - 1, s_fn_param);
|
||||
logs(buf, n - 1);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -61,16 +51,11 @@ void mg_log(const char *fmt, ...) {
|
||||
va_start(ap, fmt);
|
||||
len = mg_vasprintf(&buf, sizeof(mem), fmt, ap);
|
||||
va_end(ap);
|
||||
s_fn(buf, len, s_fn_param);
|
||||
s_fn("\n", 1, s_fn_param);
|
||||
logs(buf, len);
|
||||
logc((unsigned char) '\n');
|
||||
if (buf != mem) free(buf);
|
||||
}
|
||||
|
||||
void mg_log_set_callback(void (*fn)(const void *, size_t, void *), void *fnd) {
|
||||
s_fn = fn;
|
||||
s_fn_param = fnd;
|
||||
}
|
||||
|
||||
static unsigned char nibble(unsigned c) {
|
||||
return (unsigned char) (c < 10 ? c + '0' : c + 'W');
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ enum { MG_LL_NONE, MG_LL_ERROR, MG_LL_INFO, MG_LL_DEBUG, MG_LL_VERBOSE };
|
||||
void mg_log(const char *fmt, ...) PRINTF_LIKE(1, 2);
|
||||
bool mg_log_prefix(int ll, const char *file, int line, const char *fname);
|
||||
void mg_log_set(const char *spec);
|
||||
void mg_log_set_callback(void (*fn)(const void *, size_t, void *), void *param);
|
||||
void mg_hexdump(const void *buf, size_t len);
|
||||
|
||||
#define MG_LOG(level, args) \
|
||||
|
||||
Reference in new issue
Block a user