commit 0d201bff6df2eeffb8aab25db6b9ec487d51181c Author: Karsten Loesing karsten.loesing@gmx.net Date: Sun Feb 12 10:03:17 2012 +0100
Add a notice log level and make it the default. --- doc/HACKING | 4 ++-- src/main.c | 12 +++++++----- src/util.c | 32 ++++++++++++++++++++++++-------- src/util.h | 12 +++++++++--- 4 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/doc/HACKING b/doc/HACKING index c9197fb..b1134bf 100644 --- a/doc/HACKING +++ b/doc/HACKING @@ -37,8 +37,8 @@ obfsproxy currently provides the following functions for protocols according to your protocol. Note that (*handshake) and (*destroy) are optional.
-For all your logging needs you can use the functions log_{warn,info,debug} -defined in src/util.h. +For all your logging needs you can use the functions +log_{warn,notice,info,debug} defined in src/util.h.
[1]: For example: 'your_protocol --additional-parameter=yes server 127.0.0.1:666' diff --git a/src/main.c b/src/main.c index 7ebdd51..e7671c8 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,8 @@ usage(void) fprintf(stderr,"[%s] ", supported_protocols[i]->name); fprintf(stderr, "\n* obfsproxy_args:\n" "--log-file=<file> ~ set logfile\n" - "--log-min-severity=warn|info|debug ~ set minimum logging severity\n" + "--log-min-severity=warn|notice|info|debug ~ " + "set minimum logging severity\n" "--no-log ~ disable logging\n");
exit(1); @@ -78,16 +79,16 @@ handle_signal_cb(evutil_socket_t fd, short what, void *arg) case SIGINT: close_all_listeners(); if (!got_sigint) { - log_info("Got SIGINT. Preparing shutdown."); + log_notice("Got SIGINT. Preparing shutdown."); start_shutdown(0); got_sigint++; } else { - log_info("Got SIGINT for the second time. Terminating."); + log_notice("Got SIGINT for the second time. Terminating."); start_shutdown(1); } break; case SIGTERM: - log_info("Got SIGTERM. Terminating."); + log_notice("Got SIGTERM. Terminating."); start_shutdown(1); break; } @@ -236,7 +237,7 @@ void obfsproxy_cleanup() { /* We have landed. */ - log_info("Exiting."); + log_notice("Exiting.");
close_all_listeners(); evdns_base_free(get_evdns_base(), 0); @@ -257,6 +258,7 @@ obfs_main(int argc, const char *const *argv)
/* Handle optional obfsproxy arguments. */ begin = argv + handle_obfsproxy_args(argv); + log_notice("Starting.");
if (is_external_proxy) { if (launch_external_proxy(begin) < 0) diff --git a/src/util.c b/src/util.c index f2089df..ee1766b 100644 --- a/src/util.c +++ b/src/util.c @@ -352,15 +352,16 @@ ascii_strlower(char *s)
/** Logging severities */
-#define LOG_SEV_ERR 4 -#define LOG_SEV_WARN 3 +#define LOG_SEV_ERR 5 +#define LOG_SEV_WARN 4 +#define LOG_SEV_NOTICE 3 #define LOG_SEV_INFO 2 #define LOG_SEV_DEBUG 1
/* logging method */ static int logging_method=LOG_METHOD_STDERR; /* minimum logging severity */ -static int logging_min_sev=LOG_SEV_INFO; +static int logging_min_sev=LOG_SEV_NOTICE; /* logfile fd */ static int logging_logfile=-1;
@@ -371,6 +372,7 @@ sev_to_string(int severity) switch (severity) { case LOG_SEV_ERR: return "error"; case LOG_SEV_WARN: return "warn"; + case LOG_SEV_NOTICE: return "notice"; case LOG_SEV_INFO: return "info"; case LOG_SEV_DEBUG: return "debug"; default: @@ -385,8 +387,10 @@ string_to_sev(const char *string) { if (!strcasecmp(string, "error")) return LOG_SEV_ERR; - if (!strcasecmp(string, "warn")) + else if (!strcasecmp(string, "warn")) return LOG_SEV_WARN; + else if (!strcasecmp(string, "notice")) + return LOG_SEV_NOTICE; else if (!strcasecmp(string, "info")) return LOG_SEV_INFO; else if (!strcasecmp(string, "debug")) @@ -402,9 +406,10 @@ string_to_sev(const char *string) static int sev_is_valid(int severity) { - return (severity == LOG_SEV_ERR || - severity == LOG_SEV_WARN || - severity == LOG_SEV_INFO || + return (severity == LOG_SEV_ERR || + severity == LOG_SEV_WARN || + severity == LOG_SEV_NOTICE || + severity == LOG_SEV_INFO || severity == LOG_SEV_DEBUG); }
@@ -450,7 +455,6 @@ log_set_method(int method, const char *filename) }
logging_method = method; - log_info("Starting.");
return 0; } @@ -584,6 +588,18 @@ log_warn(const char *format, ...) va_end(ap); }
+/** Public function for logging a notice message. */ +void +log_notice(const char *format, ...) +{ + va_list ap; + va_start(ap,format); + + logv(LOG_SEV_NOTICE, format, ap); + + va_end(ap); +} + /** Public function for logging an informative message. */ void log_info(const char *format, ...) diff --git a/src/util.h b/src/util.h index 3396abf..9197c8c 100644 --- a/src/util.h +++ b/src/util.h @@ -157,7 +157,8 @@ int obfs_snprintf(char *str, size_t size, int log_set_method(int method, const char *filename);
/** Set the minimum severity that will be logged. - 'sev_string' may be "warn", "info", or "debug" (case-insensitively). */ + 'sev_string' may be "warn", "notice", "info", or "debug" + (case-insensitively). */ int log_set_min_severity(const char* sev_string);
/** True if debug messages are being logged. */ @@ -181,8 +182,13 @@ void log_error_abort(const char *format, ...) void log_warn(const char *format, ...) ATTR_PRINTF_1;
-/** Info-level severity: for messages that should be sent to the user - during normal operation. */ +/** Notice-level severity: for messages that most users would like to + learn about during normal operation. */ +void log_notice(const char *format, ...) + ATTR_PRINTF_1; + +/** Info-level severity: for rather verbose messages of some interest to + users during normal operation. */ void log_info(const char *format, ...) ATTR_PRINTF_1;