mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-27 03:03:43 +00:00
Merge pull request #29 from dorentus/patch-syslog
Add a command line option to allow logging to syslog (*NIX platforms only)
This commit is contained in:
@@ -219,11 +219,11 @@ ss-[local|redir|server]
|
||||
[-c <config_file>] json format config file
|
||||
|
||||
[-i <interface>] specific network interface to bind,
|
||||
only avaliable in local and server modes
|
||||
only available in local and server modes
|
||||
[-b <local_address>] specific local address to bind,
|
||||
only avaliable in local and redir modes
|
||||
only available in local and redir modes
|
||||
[-u] udprelay mode to supprot udp traffic
|
||||
only avaliable in local and server modes
|
||||
only available in local and server modes
|
||||
[-v] verbose mode, debug output in console
|
||||
|
||||
notes:
|
||||
|
||||
@@ -896,6 +896,7 @@ int main (int argc, char **argv)
|
||||
|
||||
if (pid_flags)
|
||||
{
|
||||
USE_SYSLOG(argv[0]);
|
||||
demonize(pid_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -749,6 +749,7 @@ int main (int argc, char **argv)
|
||||
|
||||
if (pid_flags)
|
||||
{
|
||||
USE_SYSLOG(argv[0]);
|
||||
demonize(pid_path);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -988,6 +988,7 @@ int main (int argc, char **argv)
|
||||
|
||||
if (pid_flags)
|
||||
{
|
||||
USE_SYSLOG(argv[0]);
|
||||
demonize(pid_path);
|
||||
}
|
||||
|
||||
@@ -1043,7 +1044,7 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
// Setup UDP
|
||||
if (udprelay)
|
||||
if (udprelay)
|
||||
{
|
||||
LOGD("udprelay enabled.");
|
||||
udprelay_init(server_host[0], server_port, asyncns, m, iface);
|
||||
|
||||
+8
-4
@@ -14,6 +14,10 @@
|
||||
|
||||
#define INT_DIGITS 19 /* enough for 64 bit integer */
|
||||
|
||||
#ifdef HAS_SYSLOG
|
||||
int use_syslog = 0;
|
||||
#endif
|
||||
|
||||
#ifndef __MINGW32__
|
||||
void ERROR(const char *s)
|
||||
{
|
||||
@@ -81,7 +85,7 @@ void usage()
|
||||
printf(" maintained by Max Lv <max.c.lv@gmail.com>\n\n");
|
||||
printf(" usage:\n\n");
|
||||
printf(" ss-[local|redir|server]\n");
|
||||
printf(" -s <server_host> host name or ip address of your remote server\n");
|
||||
printf(" -s <server_host> host name or ip address of your remote server\n");
|
||||
printf(" -p <server_port> port number of your remote server\n");
|
||||
printf(" -l <local_port> port number of your local server\n");
|
||||
printf(" -k <password> password of your remote server\n");
|
||||
@@ -96,11 +100,11 @@ void usage()
|
||||
printf(" [-c <config_file>] json format config file\n");
|
||||
printf("\n");
|
||||
printf(" [-i <interface>] specific network interface to bind,\n");
|
||||
printf(" only avaliable in local and server modes\n");
|
||||
printf(" only available in local and server modes\n");
|
||||
printf(" [-b <local_address>] specific local address to bind,\n");
|
||||
printf(" only avaliable in local and redir modes\n");
|
||||
printf(" only available in local and redir modes\n");
|
||||
printf(" [-u] udprelay mode to supprot udp traffic\n");
|
||||
printf(" only avaliable in local and server modes\n");
|
||||
printf(" only available in local and server modes\n");
|
||||
printf(" [-v] verbose mode, debug output in console\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
+30
-9
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#define USE_SYSLOG(ident)
|
||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "shadowsocks", __VA_ARGS__))
|
||||
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "shadowsocks", __VA_ARGS__))
|
||||
|
||||
@@ -20,6 +21,8 @@
|
||||
|
||||
#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
#define USE_SYSLOG(ident)
|
||||
|
||||
#define LOGD(format, ...) do {\
|
||||
time_t now = time(NULL);\
|
||||
char timestr[20];\
|
||||
@@ -36,23 +39,41 @@ while(0)
|
||||
|
||||
#else
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
#define HAS_SYSLOG
|
||||
extern int use_syslog;
|
||||
|
||||
#define TIME_FORMAT "%F %T"
|
||||
|
||||
#define USE_SYSLOG(ident) do {\
|
||||
use_syslog = 1;\
|
||||
openlog((ident), LOG_CONS | LOG_PID, 0);}\
|
||||
while(0)
|
||||
|
||||
#define LOGD(format, ...) do {\
|
||||
time_t now = time(NULL);\
|
||||
char timestr[20];\
|
||||
strftime(timestr, 20, TIME_FORMAT, localtime(&now));\
|
||||
fprintf(stderr, "\e[01;32m %s INFO: \e[0m" format "\n", timestr, ##__VA_ARGS__);}\
|
||||
if (use_syslog) {\
|
||||
syslog(LOG_INFO, format, ##__VA_ARGS__);\
|
||||
} else {\
|
||||
time_t now = time(NULL);\
|
||||
char timestr[20];\
|
||||
strftime(timestr, 20, TIME_FORMAT, localtime(&now));\
|
||||
fprintf(stderr, "\e[01;32m %s INFO: \e[0m" format "\n", timestr, ##__VA_ARGS__);\
|
||||
}}\
|
||||
while(0)
|
||||
|
||||
#define LOGE(format, ...) do {\
|
||||
time_t now = time(NULL);\
|
||||
char timestr[20];\
|
||||
strftime(timestr, 20, TIME_FORMAT, localtime(&now));\
|
||||
fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" format "\n", timestr, ##__VA_ARGS__);}\
|
||||
if (use_syslog) {\
|
||||
syslog(LOG_ERR, format, ##__VA_ARGS__);\
|
||||
} else {\
|
||||
time_t now = time(NULL);\
|
||||
char timestr[20];\
|
||||
strftime(timestr, 20, TIME_FORMAT, localtime(&now));\
|
||||
fprintf(stderr, "\e[01;35m %s ERROR: \e[0m" format "\n", timestr, ##__VA_ARGS__);\
|
||||
}}\
|
||||
while(0)
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/* _WIN32 */
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user