mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 15:01:03 +08:00
Use int debug level
This commit is contained in:
parent
581a0698af
commit
a468f58128
@ -48,7 +48,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
mg_log_set("3"); // Set log level
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_listen(&mgr, s_listen_url, fn, NULL); // Start DNS server
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Event loop
|
||||
|
@ -8,7 +8,7 @@ void device_dashboard_fn(struct mg_connection *, int, void *, void *);
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("2"); // Set to 3 for debug, to 4 for very verbose level
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, s_listening_url, device_dashboard_fn, &mgr);
|
||||
MG_INFO(("Listening on %s", s_listening_url));
|
||||
|
@ -27,7 +27,7 @@ void app_main(void) {
|
||||
|
||||
// Connected to WiFi, now start HTTP server
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr);
|
||||
MG_INFO(("Mongoose v%s on %s", MG_VERSION, s_listening_url));
|
||||
mg_http_listen(&mgr, s_listening_url, device_dashboard_fn, &mgr);
|
||||
|
@ -71,7 +71,7 @@ void cli(uint8_t input_byte) {
|
||||
} else if (strcmp(buf0, "reboot") == 0) {
|
||||
esp_restart();
|
||||
} else if (strcmp(buf0, "ll") == 0) {
|
||||
mg_log_set(buf1);
|
||||
mg_log_set(atoi(buf1));
|
||||
} else if (strcmp(buf0, "wifi") == 0) {
|
||||
cli_wifi(buf1, buf2);
|
||||
} else {
|
||||
|
@ -42,7 +42,7 @@ void app_main(void) {
|
||||
// Connected to WiFi, now start HTTP server
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
MG_INFO(("Mongoose v%s on %s", MG_VERSION, s_listening_url));
|
||||
mg_http_listen(&mgr, s_listening_url, uart_bridge_fn, &mgr);
|
||||
for (;;) mg_mgr_poll(&mgr, 10); // Infinite event loop
|
||||
|
@ -34,7 +34,7 @@ static void cb2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
// Called after we're connected to WiFi network
|
||||
static void run_mongoose(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, SERVER_URL, cb, &mgr); // Listening server
|
||||
mg_http_connect(&mgr, CLIENT_URL, cb2, &mgr); // Example client
|
||||
|
@ -41,7 +41,7 @@ int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_http_listen(&mgr, "http://localhost:8000", cb, NULL);
|
||||
|
||||
for (;;) mg_mgr_poll(&mgr, 50);
|
||||
|
@ -30,7 +30,7 @@ int main(void) {
|
||||
struct mg_timer t1;
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_http_listen(&mgr, "http://localhost:8000", cb, NULL);
|
||||
|
||||
for (;;) mg_mgr_poll(&mgr, 50);
|
||||
|
@ -37,7 +37,7 @@ int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_http_listen(&mgr, "http://localhost:8000", cb, NULL);
|
||||
|
||||
for (;;) mg_mgr_poll(&mgr, 50);
|
||||
|
@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
bool done = false; // Event handler flips it to true
|
||||
if (argc > 1) s_url = argv[1]; // Use URL provided in the command line
|
||||
mg_log_set(log_level); // Set to 0 to disable debug
|
||||
mg_log_set(atoi(log_level)); // Set to 0 to disable debug
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_connect(&mgr, s_url, fn, &done); // Create client connection
|
||||
while (!done) mg_mgr_poll(&mgr, 50); // Event manager loops until 'done'
|
||||
|
@ -58,7 +58,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_log_set("2"); // Set to 3 to enable debug
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
|
||||
mg_http_listen(&mgr, s_https_addr, fn, (void *) 1); // HTTPS listener
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
static const char *s_backend_url =
|
||||
#if defined(MG_ENABLE_MBEDTLS) || defined(MG_ENABLE_OPENSSL)
|
||||
"https://cesanta.com";
|
||||
"https://cesanta.com";
|
||||
#else
|
||||
"http://info.cern.ch";
|
||||
"http://info.cern.ch";
|
||||
#endif
|
||||
static const char *s_listen_url = "http://localhost:8000";
|
||||
|
||||
@ -75,7 +75,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
mg_log_set("3"); // Set log level
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_listen(&mgr, s_listen_url, fn, NULL); // Start proxy
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Event loop
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <signal.h>
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_debug_level = "2";
|
||||
static int s_debug_level = MG_LL_INFO;
|
||||
static const char *s_root_dir = ".";
|
||||
static const char *s_listening_address = "http://0.0.0.0:8000";
|
||||
static const char *s_enable_hexdump = "no";
|
||||
@ -44,7 +44,7 @@ static void usage(const char *prog) {
|
||||
" -S PAT - SSI filename pattern, default: '%s'\n"
|
||||
" -d DIR - directory to serve, default: '%s'\n"
|
||||
" -l ADDR - listening address, default: '%s'\n"
|
||||
" -v LEVEL - debug level, from 0 to 4, default: '%s'\n",
|
||||
" -v LEVEL - debug level, from 0 to 4, default: %d\n",
|
||||
MG_VERSION, prog, s_enable_hexdump, s_ssi_pattern, s_root_dir,
|
||||
s_listening_address, s_debug_level);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
|
||||
} else if (strcmp(argv[i], "-l") == 0) {
|
||||
s_listening_address = argv[++i];
|
||||
} else if (strcmp(argv[i], "-v") == 0) {
|
||||
s_debug_level = argv[++i];
|
||||
s_debug_level = atoi(argv[++i]);
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ int main(int argc, char *argv[]) {
|
||||
bool done = false; // Event handler flips it to true
|
||||
const char *log_level = getenv("V"); // Log level
|
||||
if (log_level == NULL) log_level = "3"; // If not set, set to DEBUG
|
||||
mg_log_set(log_level); // Set to 0 to disable debug log
|
||||
mg_log_set(atoi(log_level)); // Set to 0 to disable debug log
|
||||
if (argc > 1) s_url = argv[1]; // Use URL from command line
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_connect(&mgr, s_url, fn, &done); // Create client connection
|
||||
|
@ -67,9 +67,9 @@ static void timer_fn(void *arg) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Init event manager
|
||||
mg_log_set("3");
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Init event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT, timer_fn, &mgr); // Init timer
|
||||
|
||||
// Configure JSON-RPC functions we're going to handle
|
||||
|
@ -68,9 +68,9 @@ int main(int argc, char *argv[]) {
|
||||
const char *bpf = NULL; // "host x.x.x.x or ether host ff:ff:ff:ff:ff:ff";
|
||||
char errbuf[PCAP_ERRBUF_SIZE] = "";
|
||||
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set("3"); // Set debug log level
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_timer_add(&mgr, 3000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr);
|
||||
|
||||
// Parse options
|
||||
|
@ -80,10 +80,10 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
bool done = false; // Event handler flips it to true when done
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set("4"); // Set debug log level
|
||||
struct mg_mgr mgr; // Event manager
|
||||
bool done = false; // Event handler flips it to true when done
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_ws_connect(&mgr, s_url, fn, &done, NULL); // Create client connection
|
||||
while (done == false) mg_mgr_poll(&mgr, 1000); // Event loop
|
||||
mg_mgr_free(&mgr); // Finished, cleanup
|
||||
|
@ -78,7 +78,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set("3");
|
||||
mg_log_set(MG_LL_DEBUG); // Set debug log level
|
||||
mg_http_listen(&mgr, "http://localhost:8000", fn, NULL); // Create listener
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Event loop
|
||||
mg_mgr_free(&mgr); // Cleanup
|
||||
|
@ -42,9 +42,9 @@ static void timer_fn(void *arg) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set("3"); // Set debug log level
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr);
|
||||
for (;;) mg_mgr_poll(&mgr, 300); // Infinite event loop
|
||||
mg_mgr_free(&mgr); // Free manager resources
|
||||
|
@ -164,7 +164,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_log_set("3"); // Set to 0 to disable debug
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_listen(&mgr, s_lsn, fn, NULL); // Create client connection
|
||||
while (true) mg_mgr_poll(&mgr, 1000); // Infinite event loop
|
||||
|
@ -124,9 +124,9 @@ int main(void) {
|
||||
RCC->AHB1RSTR |= BIT(25); // ETHMAC force reset
|
||||
RCC->AHB1RSTR &= ~BIT(25); // ETHMAC release reset
|
||||
|
||||
struct mg_mgr mgr; // Initialise Mongoose event manager
|
||||
mg_mgr_init(&mgr); // and attach it to the MIP interface
|
||||
mg_log_set("2");
|
||||
struct mg_mgr mgr; // Initialise Mongoose event manager
|
||||
mg_mgr_init(&mgr); // and attach it to the MIP interface
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_timer_add(&mgr, 1000, MG_TIMER_REPEAT, blink_cb, &mgr);
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT, sntp_cb, &mgr);
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:80", fn, NULL);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "device.h"
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_debug_level = "4";
|
||||
static int s_debug_level = MG_LL_VERBOSE;
|
||||
static const char *s_listening_address = "http://0.0.0.0:80";
|
||||
|
||||
// Event handler for the listening connection.
|
||||
|
@ -79,8 +79,8 @@ int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
struct mg_connection *c;
|
||||
|
||||
mg_log_set("2"); // Set to 0 to disable debug
|
||||
mg_mgr_init(&mgr); // Initialize event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Initialize event manager
|
||||
mg_timer_add(&mgr, 15000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn,
|
||||
&mgr); // Init timer for demo purposes, 15s
|
||||
c = mg_listen(&mgr, s_lsn, sfn, NULL); // Create server connection
|
||||
|
@ -42,12 +42,12 @@ static void timer_fn(void *arg) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set("3"); // Set debug log level
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_timer_add(&mgr, 1000, MG_TIMER_REPEAT, timer_fn, &mgr);
|
||||
mg_http_listen(&mgr, s_listen_on, fn, NULL); // Create HTTP listener
|
||||
for (;;) mg_mgr_poll(&mgr, 500); // Infinite event loop
|
||||
for (;;) mg_mgr_poll(&mgr, 500); // Infinite event loop
|
||||
mg_mgr_free(&mgr); // Free manager resources
|
||||
return 0;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ void uart_bridge_fn(struct mg_connection *, int, void *, void *);
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("2"); // Set to 3 for debug, to 4 for very verbose level
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, s_listening_url, uart_bridge_fn, &mgr);
|
||||
MG_INFO(("Listening on %s", s_listening_url));
|
||||
|
@ -181,7 +181,7 @@ void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data,
|
||||
s_state.mqtt.url = strdup(DEFAULT_MQTT);
|
||||
mg_timer_add(c->mgr, 20, MG_TIMER_REPEAT, timer_fn, c->mgr);
|
||||
uart_init(s_state.tx, s_state.rx, s_state.baud);
|
||||
// mg_log_set("3");
|
||||
// mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
} else if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
if (mg_http_match_uri(hm, "/api/hi")) {
|
||||
|
@ -35,7 +35,7 @@ int main(void) {
|
||||
bool done = false; // Event handler flips it to true
|
||||
struct mg_connection *c; // Client connection
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set("4");
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
c = mg_ws_connect(&mgr, s_url, fn, &done, NULL); // Create client
|
||||
while (c && done == false) mg_mgr_poll(&mgr, 1000); // Wait for echo
|
||||
mg_mgr_free(&mgr); // Deallocate resources
|
||||
|
@ -66,7 +66,7 @@ void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_log_set("2"); // Set to 3 for debug, to 4 for very verbose level
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, s_listening_url, fn, &mgr);
|
||||
while (mgr.conns != NULL) mg_mgr_poll(&mgr, 500);
|
||||
|
@ -54,7 +54,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_log_set("2"); // Set to 3 to enable debug
|
||||
mg_log_set(MG_LL_INFO); // Set to 3 to enable debug
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
|
||||
|
@ -43,9 +43,9 @@ static void timer_fn(void *arg) {
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set("2"); // Set debug log level
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_timer_add(&mgr, 2000, MG_TIMER_REPEAT, timer_fn, &mgr);
|
||||
mg_http_listen(&mgr, s_listen_on, fn, NULL); // Create HTTP listener
|
||||
for (;;) mg_mgr_poll(&mgr, 500); // Infinite event loop
|
||||
|
@ -39,7 +39,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr; // Event manager
|
||||
mg_log_set("2"); // Set to 3 to enable debug
|
||||
mg_log_set(MG_LL_DEBUG); // Set log level
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "certs.h"
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_debug_level = "3";
|
||||
static time_t s_boot_timestamp = 0;
|
||||
static struct mg_connection *s_sntp_conn = NULL;
|
||||
static const char *s_url = "https://example.org/";
|
||||
@ -89,7 +88,7 @@ static void timer_fn(void *arg) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
mg_log_set(s_debug_level);
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
|
||||
mg_mgr_init(&s_mgr);
|
||||
mg_timer_add(&s_mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn,
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "certs.h"
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_debug_level = "3";
|
||||
static const char *s_web_dir = "/";
|
||||
static const char *s_http_addr = "http://0.0.0.0:8000";
|
||||
static const char *s_https_addr = "https://0.0.0.0:8443";
|
||||
@ -72,7 +71,7 @@ static void timer_fn(void *arg) {
|
||||
int main(int argc, char *argv[]) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
mg_log_set(s_debug_level);
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
mg_http_listen(&mgr, s_http_addr, wcb, NULL);
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
struct mg_mgr mgr;
|
||||
|
||||
static const char *s_debug_level = "3";
|
||||
static time_t s_boot_timestamp = 0;
|
||||
static struct mg_connection *s_sntp_conn = NULL;
|
||||
static const char *s_url =
|
||||
@ -87,7 +86,7 @@ static void timer_fn(void *arg) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
mg_log_set(s_debug_level);
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr);
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "certs.h"
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_debug_level = "3";
|
||||
static const char *s_web_dir = "/";
|
||||
static const char *s_ws_addr = "ws://0.0.0.0:8000";
|
||||
static const char *s_wss_addr = "wss://0.0.0.0:8443";
|
||||
@ -66,9 +65,8 @@ static void timer_fn(void *arg) {
|
||||
int main(int argc, char *argv[]) {
|
||||
struct mg_mgr mgr;
|
||||
|
||||
mg_log_set(s_debug_level);
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
mg_http_listen(&mgr, s_ws_addr, fn, NULL);
|
||||
mg_http_listen(&mgr, s_wss_addr, fn, &mgr);
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr);
|
||||
|
36
mongoose.c
36
mongoose.c
@ -2708,7 +2708,7 @@ static void default_logger(unsigned char c) {
|
||||
(void) c;
|
||||
}
|
||||
|
||||
static const char *s_spec = "2";
|
||||
static int s_level = MG_LL_INFO;
|
||||
static void (*s_log_func)(unsigned char) = default_logger;
|
||||
|
||||
void mg_log_set_fn(void (*fn)(unsigned char)) {
|
||||
@ -2724,29 +2724,17 @@ static void logs(const char *buf, size_t len) {
|
||||
for (i = 0; i < len; i++) logc(((unsigned char *) buf)[i]);
|
||||
}
|
||||
|
||||
void mg_log_set(const char *spec) {
|
||||
MG_DEBUG(("Setting log level to %s", spec));
|
||||
s_spec = spec;
|
||||
void mg_log_set(int log_level) {
|
||||
MG_DEBUG(("Setting log level to %d", log_level));
|
||||
s_level = log_level;
|
||||
}
|
||||
|
||||
bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
// static unsigned long seq;
|
||||
int max = MG_LL_INFO;
|
||||
struct mg_str k, v, s = mg_str(s_spec);
|
||||
const char *p = strrchr(file, '/');
|
||||
|
||||
if (p == NULL) p = strrchr(file, '\\');
|
||||
p = p == NULL ? file : p + 1;
|
||||
|
||||
while (mg_commalist(&s, &k, &v)) {
|
||||
if (v.len == 0) max = atoi(k.ptr);
|
||||
if (v.len > 0 && strncmp(p, k.ptr, k.len) == 0) max = atoi(v.ptr);
|
||||
}
|
||||
|
||||
if (level <= max) {
|
||||
if (level <= s_level) {
|
||||
const char *p = strrchr(file, MG_DIRSEP);
|
||||
char buf[41];
|
||||
size_t n = mg_snprintf(buf, sizeof(buf), "%llx %d %s:%d:%s", mg_millis(),
|
||||
level, p, line, fname);
|
||||
level, p == NULL ? fname : p + 1, line, fname);
|
||||
if (n > sizeof(buf) - 2) n = sizeof(buf) - 2;
|
||||
while (n < sizeof(buf)) buf[n++] = ' ';
|
||||
logs(buf, n - 1);
|
||||
@ -4238,8 +4226,9 @@ static void read_conn(struct mg_connection *c) {
|
||||
char *buf = (char *) &c->recv.buf[c->recv.len];
|
||||
size_t len = c->recv.size - c->recv.len;
|
||||
n = c->is_tls ? mg_tls_recv(c, buf, len) : mg_sock_recv(c, buf, len);
|
||||
MG_DEBUG(("%lu %p %d:%d %ld err %d", c->id, c->fd, (int) c->send.len,
|
||||
(int) c->recv.len, n, MG_SOCK_ERRNO));
|
||||
MG_DEBUG(("%lu %p snd %ld/%ld rcv %ld/%ld n=%ld err=%d", c->id, c->fd,
|
||||
(long) c->send.len, (long) c->send.size, (long) c->recv.len,
|
||||
(long) c->recv.size, n, MG_SOCK_ERRNO));
|
||||
iolog(c, buf, n, true);
|
||||
}
|
||||
}
|
||||
@ -4248,8 +4237,9 @@ static void write_conn(struct mg_connection *c) {
|
||||
char *buf = (char *) c->send.buf;
|
||||
size_t len = c->send.len;
|
||||
long n = c->is_tls ? mg_tls_send(c, buf, len) : mg_sock_send(c, buf, len);
|
||||
MG_DEBUG(("%lu %p %d:%d %ld err %d", c->id, c->fd, (int) c->send.len,
|
||||
(int) c->recv.len, n, MG_SOCK_ERRNO));
|
||||
MG_DEBUG(("%lu %p snd %ld/%ld rcv %ld/%ld n=%ld err=%d", c->id, c->fd,
|
||||
(long) c->send.len, (long) c->send.size, (long) c->recv.len,
|
||||
(long) c->recv.size, n, MG_SOCK_ERRNO));
|
||||
iolog(c, buf, n, false);
|
||||
}
|
||||
|
||||
|
@ -775,7 +775,7 @@ char *mg_vmprintf(const char *fmt, va_list ap);
|
||||
enum { MG_LL_NONE, MG_LL_ERROR, MG_LL_INFO, MG_LL_DEBUG, MG_LL_VERBOSE };
|
||||
void mg_log(const char *fmt, ...);
|
||||
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(int log_level);
|
||||
void mg_hexdump(const void *buf, size_t len);
|
||||
void mg_log_set_fn(void (*logfunc)(unsigned char ch));
|
||||
|
||||
|
26
src/log.c
26
src/log.c
@ -8,7 +8,7 @@ static void default_logger(unsigned char c) {
|
||||
(void) c;
|
||||
}
|
||||
|
||||
static const char *s_spec = "2";
|
||||
static int s_level = MG_LL_INFO;
|
||||
static void (*s_log_func)(unsigned char) = default_logger;
|
||||
|
||||
void mg_log_set_fn(void (*fn)(unsigned char)) {
|
||||
@ -24,29 +24,17 @@ static void logs(const char *buf, size_t len) {
|
||||
for (i = 0; i < len; i++) logc(((unsigned char *) buf)[i]);
|
||||
}
|
||||
|
||||
void mg_log_set(const char *spec) {
|
||||
MG_DEBUG(("Setting log level to %s", spec));
|
||||
s_spec = spec;
|
||||
void mg_log_set(int log_level) {
|
||||
MG_DEBUG(("Setting log level to %d", log_level));
|
||||
s_level = log_level;
|
||||
}
|
||||
|
||||
bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
// static unsigned long seq;
|
||||
int max = MG_LL_INFO;
|
||||
struct mg_str k, v, s = mg_str(s_spec);
|
||||
const char *p = strrchr(file, '/');
|
||||
|
||||
if (p == NULL) p = strrchr(file, '\\');
|
||||
p = p == NULL ? file : p + 1;
|
||||
|
||||
while (mg_commalist(&s, &k, &v)) {
|
||||
if (v.len == 0) max = atoi(k.ptr);
|
||||
if (v.len > 0 && strncmp(p, k.ptr, k.len) == 0) max = atoi(v.ptr);
|
||||
}
|
||||
|
||||
if (level <= max) {
|
||||
if (level <= s_level) {
|
||||
const char *p = strrchr(file, MG_DIRSEP);
|
||||
char buf[41];
|
||||
size_t n = mg_snprintf(buf, sizeof(buf), "%llx %d %s:%d:%s", mg_millis(),
|
||||
level, p, line, fname);
|
||||
level, p == NULL ? fname : p + 1, line, fname);
|
||||
if (n > sizeof(buf) - 2) n = sizeof(buf) - 2;
|
||||
while (n < sizeof(buf)) buf[n++] = ' ';
|
||||
logs(buf, n - 1);
|
||||
|
@ -6,7 +6,7 @@
|
||||
enum { MG_LL_NONE, MG_LL_ERROR, MG_LL_INFO, MG_LL_DEBUG, MG_LL_VERBOSE };
|
||||
void mg_log(const char *fmt, ...);
|
||||
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(int log_level);
|
||||
void mg_hexdump(const void *buf, size_t len);
|
||||
void mg_log_set_fn(void (*logfunc)(unsigned char ch));
|
||||
|
||||
|
10
src/sock.c
10
src/sock.c
@ -292,8 +292,9 @@ static void read_conn(struct mg_connection *c) {
|
||||
char *buf = (char *) &c->recv.buf[c->recv.len];
|
||||
size_t len = c->recv.size - c->recv.len;
|
||||
n = c->is_tls ? mg_tls_recv(c, buf, len) : mg_sock_recv(c, buf, len);
|
||||
MG_DEBUG(("%lu %p %d:%d %ld err %d", c->id, c->fd, (int) c->send.len,
|
||||
(int) c->recv.len, n, MG_SOCK_ERRNO));
|
||||
MG_DEBUG(("%lu %p snd %ld/%ld rcv %ld/%ld n=%ld err=%d", c->id, c->fd,
|
||||
(long) c->send.len, (long) c->send.size, (long) c->recv.len,
|
||||
(long) c->recv.size, n, MG_SOCK_ERRNO));
|
||||
iolog(c, buf, n, true);
|
||||
}
|
||||
}
|
||||
@ -302,8 +303,9 @@ static void write_conn(struct mg_connection *c) {
|
||||
char *buf = (char *) c->send.buf;
|
||||
size_t len = c->send.len;
|
||||
long n = c->is_tls ? mg_tls_send(c, buf, len) : mg_sock_send(c, buf, len);
|
||||
MG_DEBUG(("%lu %p %d:%d %ld err %d", c->id, c->fd, (int) c->send.len,
|
||||
(int) c->recv.len, n, MG_SOCK_ERRNO));
|
||||
MG_DEBUG(("%lu %p snd %ld/%ld rcv %ld/%ld n=%ld err=%d", c->id, c->fd,
|
||||
(long) c->send.len, (long) c->send.size, (long) c->recv.len,
|
||||
(long) c->recv.size, n, MG_SOCK_ERRNO));
|
||||
iolog(c, buf, n, false);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *, size_t);
|
||||
#endif
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
mg_log_set("0");
|
||||
mg_log_set(MG_LL_NONE);
|
||||
|
||||
struct mg_dns_message dm;
|
||||
mg_dns_parse(data, size, &dm);
|
||||
|
@ -2483,7 +2483,7 @@ static void test_rpc(void) {
|
||||
int main(void) {
|
||||
const char *debug_level = getenv("V");
|
||||
if (debug_level == NULL) debug_level = "3";
|
||||
mg_log_set(debug_level);
|
||||
mg_log_set(atoi(debug_level));
|
||||
|
||||
test_json();
|
||||
test_rpc();
|
||||
|
Loading…
x
Reference in New Issue
Block a user