Skip to content

Commit

Permalink
Log to corresponding android log level (shadowsocks#3)
Browse files Browse the repository at this point in the history
* Log to correct android log level.

Log msg to corresponding android log level

* Update BLog.c

Update log level map

* Android build doesn't set netmask

Debug build will crash because Android build doesn't set netmask of tun2socks

* Reformat code

* Change NOTICE map to INFO
  • Loading branch information
made-by-love authored Feb 8, 2020
1 parent 0f89d71 commit 06f7663
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions base/BLog.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ struct _BLog_global blog_global = {0};
// keep in sync with level numbers in BLog.h!
static char *level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" };

#ifdef __ANDROID__
static int android_log_level_map[] = {ANDROID_LOG_FATAL, ANDROID_LOG_ERROR, ANDROID_LOG_WARN,
ANDROID_LOG_INFO, ANDROID_LOG_INFO, ANDROID_LOG_DEBUG
};
#endif

static void stdout_log (int channel, int level, const char *msg)
{
#ifndef __ANDROID__
fprintf(stdout, "%s(%s): %s\n", level_names[level], blog_global.channels[channel].name, msg);
#else
__android_log_print(ANDROID_LOG_DEBUG, "tun2socks",
__android_log_print(android_log_level_map[level], "tun2socks",
"%s(%s): %s\n", level_names[level], blog_global.channels[channel].name, msg);
#endif
}
Expand All @@ -64,7 +70,7 @@ static void stderr_log (int channel, int level, const char *msg)
#ifndef __ANDROID__
fprintf(stderr, "%s(%s): %s\n", level_names[level], blog_global.channels[channel].name, msg);
#else
__android_log_print(ANDROID_LOG_ERROR, "tun2socks",
__android_log_print(android_log_level_map[level], "tun2socks",
"%s(%s): %s\n", level_names[level], blog_global.channels[channel].name, msg);
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions tun2socks/tun2socks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,9 @@ void lwip_init_job_hadler (void *unused)
{
ASSERT(!quitting)
ASSERT(netif_ipaddr.type == BADDR_TYPE_IPV4)
#ifndef __ANDROID__
ASSERT(netif_netmask.type == BADDR_TYPE_IPV4)
#endif
ASSERT(!have_netif)
ASSERT(!listener)
ASSERT(!listener_ip6)
Expand Down

0 comments on commit 06f7663

Please sign in to comment.