Commit edf56984 authored by Nick Mathewson's avatar Nick Mathewson 🏃
Browse files

Start dividing log messages into logging domains. No, LD_ is not the best of...

Start dividing log messages into logging domains.  No, LD_ is not the best of identifiers.  src/or has not been converted yet. Domains dont do anything yet.


svn:r5284
parent 102df4a9
......@@ -354,7 +354,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
if (listener == -1)
return -tor_socket_errno(-1);
if (!SOCKET_IS_POLLABLE(listener)) {
log_fn(LOG_WARN, "Too many connections; can't open socketpair");
warn(LD_NET, "Too many connections; can't open socketpair");
tor_close_socket(listener);
#ifdef MS_WINDOWS
return -ENFILE;
......@@ -376,7 +376,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
if (connector == -1)
goto tidy_up_and_fail;
if (!SOCKET_IS_POLLABLE(connector)) {
log_fn(LOG_WARN, "Too many connections; can't open socketpair");
warn(LD_NET, "Too many connections; can't open socketpair");
goto tidy_up_and_fail;
}
/* We want to find out the port number to connect to. */
......@@ -394,7 +394,7 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
if (acceptor == -1)
goto tidy_up_and_fail;
if (!SOCKET_IS_POLLABLE(acceptor)) {
log_fn(LOG_WARN, "Too many connections; can't open socketpair");
warn(LD_NET, "Too many connections; can't open socketpair");
goto tidy_up_and_fail;
}
if (size != sizeof(listen_addr))
......@@ -443,9 +443,10 @@ int
set_max_file_descriptors(unsigned long limit, unsigned long cap)
{
#ifndef HAVE_GETRLIMIT
log_fn(LOG_INFO,"This platform is missing getrlimit(). Proceeding.");
log_fn(LOG_INFO, LD_NET,
"This platform is missing getrlimit(). Proceeding.");
if (limit > cap) {
log(LOG_INFO, "ConnLimit must be at most %d. Capping it.", cap);
log(LOG_INFO, LD_CONFIG, "ConnLimit must be at most %d. Capping it.", cap);
limit = cap;
}
#else
......@@ -455,22 +456,22 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap)
tor_assert(cap > 0);
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
log_fn(LOG_WARN, "Could not get maximum number of file descriptors: %s",
warn(LD_NET, "Could not get maximum number of file descriptors: %s",
strerror(errno));
return -1;
}
if (rlim.rlim_max < limit) {
log_fn(LOG_WARN,"We need %lu file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long)rlim.rlim_max);
warn(LD_CONFIG,"We need %lu file descriptors available, and we're limited to %lu. Please change your ulimit -n.", limit, (unsigned long)rlim.rlim_max);
return -1;
}
most = (rlim.rlim_max > cap) ? cap : (unsigned) rlim.rlim_max;
if (most > rlim.rlim_cur) {
log_fn(LOG_INFO,"Raising max file descriptors from %lu to %lu.",
info(LD_NET,"Raising max file descriptors from %lu to %lu.",
(unsigned long)rlim.rlim_cur, most);
}
rlim.rlim_cur = most;
if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
log_fn(LOG_WARN, "Could not set maximum number of file descriptors: %s",
warn(LD_CONFIG, "Could not set maximum number of file descriptors: %s",
strerror(errno));
return -1;
}
......@@ -479,7 +480,7 @@ set_max_file_descriptors(unsigned long limit, unsigned long cap)
#endif
if (limit < ULIMIT_BUFFER) {
log_fn(LOG_WARN,"ConnLimit must be at least %d. Failing.", ULIMIT_BUFFER);
warn(LD_CONFIG,"ConnLimit must be at least %d. Failing.", ULIMIT_BUFFER);
return -1;
}
return limit - ULIMIT_BUFFER;
......@@ -498,7 +499,7 @@ switch_id(char *user, char *group)
if (user) {
pw = getpwnam(user);
if (pw == NULL) {
log_fn(LOG_ERR,"User '%s' not found.", user);
err("User '%s' not found.", user);
return -1;
}
}
......@@ -507,17 +508,17 @@ switch_id(char *user, char *group)
if (group) {
gr = getgrnam(group);
if (gr == NULL) {
log_fn(LOG_ERR,"Group '%s' not found.", group);
err("Group '%s' not found.", group);
return -1;
}
if (setgid(gr->gr_gid) != 0) {
log_fn(LOG_ERR,"Error setting GID: %s", strerror(errno));
err("Error setting GID: %s", strerror(errno));
return -1;
}
} else if (user) {
if (setgid(pw->pw_gid) != 0) {
log_fn(LOG_ERR,"Error setting GID: %s", strerror(errno));
err("Error setting GID: %s", strerror(errno));
return -1;
}
}
......@@ -526,7 +527,7 @@ switch_id(char *user, char *group)
privileges */
if (user) {
if (setuid(pw->pw_uid) != 0) {
log_fn(LOG_ERR,"Error setting UID: %s", strerror(errno));
err("Error setting UID: %s", strerror(errno));
return -1;
}
}
......@@ -534,8 +535,7 @@ switch_id(char *user, char *group)
return 0;
#endif
log_fn(LOG_ERR,
"User or group specified, but switching users is not supported.");
err("User or group specified, but switching users is not supported.");
return -1;
}
......@@ -550,7 +550,7 @@ get_user_homedir(const char *username)
tor_assert(username);
if (!(pw = getpwnam(username))) {
log_fn(LOG_ERR,"User \"%s\" not found.", username);
err("User \"%s\" not found.", username);
return NULL;
}
return tor_strdup(pw->pw_dir);
......@@ -879,7 +879,7 @@ tor_gettimeofday(struct timeval *timeval)
/* number of 100-nsec units since Jan 1, 1601 */
GetSystemTimeAsFileTime(&ft.ft_ft);
if (ft.ft_64 < EPOCH_BIAS) {
log_fn(LOG_ERR, "System time is before 1970; failing.");
err("System time is before 1970; failing.");
exit(1);
}
ft.ft_64 -= EPOCH_BIAS;
......@@ -887,7 +887,7 @@ tor_gettimeofday(struct timeval *timeval)
timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC);
#elif defined(HAVE_GETTIMEOFDAY)
if (gettimeofday(timeval, NULL)) {
log_fn(LOG_ERR, "gettimeofday failed.");
err("gettimeofday failed.");
/* If gettimeofday dies, we have either given a bad timezone (we didn't),
or segfaulted.*/
exit(1);
......@@ -996,7 +996,7 @@ tor_mutex_acquire(tor_mutex_t *m)
tor_assert(0);
break;
case WAIT_FAILED:
log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError());
warn(LD_GENERAL, "Failed to acquire mutex: %d", GetLastError());
}
}
void
......@@ -1005,7 +1005,7 @@ tor_mutex_release(tor_mutex_t *m)
BOOL r;
r = ReleaseMutex(m->handle);
if (!r) {
log_fn(LOG_WARN, "Failed to release mutex: %d", GetLastError());
warn(LD_GENERAL, "Failed to release mutex: %d", GetLastError());
}
}
unsigned long
......@@ -1177,7 +1177,7 @@ network_init(void)
int r;
r = WSAStartup(0x101,&WSAData);
if (r) {
log_fn(LOG_WARN,"Error initializing windows network layer: code was %d",r);
warn(LD_NET,"Error initializing windows network layer: code was %d",r);
return -1;
}
/* WSAData.iMaxSockets might show the max sockets we're allowed to use.
......
......@@ -165,9 +165,9 @@ crypto_log_errors(int severity, const char *doing)
func = (const char*)ERR_func_error_string(err);
if (!msg) msg = "(null)";
if (doing) {
log(severity, "crypto error while %s: %s (in %s:%s)", doing, msg, lib, func);
log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)", doing, msg, lib, func);
} else {
log(severity, "crypto error: %s (in %s:%s)", msg, lib, func);
log(severity, LD_CRYPTO, "crypto error: %s (in %s:%s)", msg, lib, func);
}
}
}
......@@ -180,10 +180,10 @@ log_engine(const char *fn, ENGINE *e)
const char *name, *id;
name = ENGINE_get_name(e);
id = ENGINE_get_id(e);
log(LOG_NOTICE, "Using OpenSSL engine %s [%s] for %s",
log(LOG_NOTICE, LD_CRYPTO, "Using OpenSSL engine %s [%s] for %s",
name?name:"?", id?id:"?", fn);
} else {
log(LOG_INFO, "Using default implementation for %s", fn);
log(LOG_INFO, LD_CRYPTO, "Using default implementation for %s", fn);
}
}
#endif
......@@ -201,8 +201,8 @@ crypto_global_init(int useAccel)
#ifndef NO_ENGINES
if (useAccel) {
if (useAccel < 0)
log_fn(LOG_WARN, "Initializing OpenSSL via tor_tls_init().");
log_fn(LOG_INFO, "Initializing OpenSSL engine support.");
warn(LD_CRYPTO, "Initializing OpenSSL via tor_tls_init().");
info(LD_CRYPTO, "Initializing OpenSSL engine support.");
ENGINE_load_builtin_engines();
if (!ENGINE_register_all_complete())
return -1;
......@@ -342,7 +342,7 @@ crypto_create_init_cipher(const char *key, int encrypt_mode)
crypto_cipher_env_t *crypto = NULL;
if (! (crypto = crypto_new_cipher_env())) {
log_fn(LOG_WARN, "Unable to allocate crypto object");
warn(LD_CRYPTO, "Unable to allocate crypto object");
return NULL;
}
......@@ -452,7 +452,7 @@ crypto_pk_read_private_key_from_filename(crypto_pk_env_t *env, const char *keyfi
/* Read the file into a string. */
contents = read_file_to_str(keyfile, 0);
if (!contents) {
log_fn(LOG_WARN, "Error reading private key from \"%s\"", keyfile);
warn(LD_CRYPTO, "Error reading private key from \"%s\"", keyfile);
return -1;
}
......@@ -592,7 +592,7 @@ crypto_pk_DER64_encode_public_key(crypto_pk_env_t *env, char **out)
}
*out = tor_malloc(len * 2); /* too long, but safe. */
if (base64_encode(*out, len*2, buf, len) < 0) {
log_fn(LOG_WARN, "Error base64-encoding DER-encoded key");
warn(LD_CRYPTO, "Error base64-encoding DER-encoded key");
tor_free(*out);
return -1;
}
......@@ -628,7 +628,7 @@ crypto_pk_DER64_decode_public_key(const char *in)
return NULL;
len = base64_decode(buf, sizeof(buf), partitioned, strlen(partitioned));
if (len<0) {
log_fn(LOG_WARN,"Error base-64 decoding key");
warn(LD_CRYPTO,"Error base-64 decoding key");
return NULL;
}
return crypto_pk_asn1_decode(buf, len);
......@@ -785,16 +785,16 @@ crypto_pk_public_checksig_digest(crypto_pk_env_t *env, const char *data,
tor_assert(sig);
if (crypto_digest(digest,data,datalen)<0) {
log_fn(LOG_WARN, "couldn't compute digest");
warn(LD_CRYPTO, "couldn't compute digest");
return -1;
}
r = crypto_pk_public_checksig(env,buf,sig,siglen);
if (r != DIGEST_LEN) {
log_fn(LOG_WARN, "Invalid signature");
warn(LD_CRYPTO, "Invalid signature");
return -1;
}
if (memcmp(buf, digest, DIGEST_LEN)) {
log_fn(LOG_WARN, "Signature mismatched with digest.");
warn(LD_CRYPTO, "Signature mismatched with digest.");
return -1;
}
......@@ -942,11 +942,13 @@ crypto_pk_private_hybrid_decrypt(crypto_pk_env_t *env,
}
outlen = crypto_pk_private_decrypt(env,buf,from,pkeylen,padding,warnOnFailure);
if (outlen<0) {
log_fn(warnOnFailure?LOG_WARN:LOG_DEBUG, "Error decrypting public-key data");
log_fn(warnOnFailure?LOG_WARN:LOG_DEBUG, LD_CRYPTO,
"Error decrypting public-key data");
return -1;
}
if (outlen < CIPHER_KEY_LEN) {
log_fn(warnOnFailure?LOG_WARN:LOG_INFO, "No room for a symmetric key");
log_fn(warnOnFailure?LOG_WARN:LOG_INFO, LD_CRYPTO,
"No room for a symmetric key");
return -1;
}
cipher = crypto_create_init_cipher(buf, 0);
......@@ -1398,7 +1400,7 @@ crypto_dh_generate_public(crypto_dh_env_t *dh)
return -1;
}
if (tor_check_dh_key(dh->dh->pub_key)<0) {
log_fn(LOG_WARN, "Weird! Our own DH key was invalid. I guess once-in-the-universe chances really do happen. Trying again.");
warn(LD_CRYPTO, "Weird! Our own DH key was invalid. I guess once-in-the-universe chances really do happen. Trying again.");
/* Free and clear the keys, so openssl will actually try again. */
BN_free(dh->dh->pub_key);
BN_free(dh->dh->priv_key);
......@@ -1426,7 +1428,7 @@ crypto_dh_get_public(crypto_dh_env_t *dh, char *pubkey, size_t pubkey_len)
bytes = BN_num_bytes(dh->dh->pub_key);
tor_assert(bytes >= 0);
if (pubkey_len < (size_t)bytes) {
log_fn(LOG_WARN, "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)", (int) pubkey_len, bytes);
warn(LD_CRYPTO, "Weird! pubkey_len (%d) was smaller than DH_BYTES (%d)", (int) pubkey_len, bytes);
return -1;
}
......@@ -1457,11 +1459,11 @@ tor_check_dh_key(BIGNUM *bn)
if (!dh_param_p)
init_dh_param();
if (bn->neg) {
log_fn(LOG_WARN, "Rejecting DH key < 0");
warn(LD_CRYPTO, "Rejecting DH key < 0");
return -1;
}
if (BN_cmp(bn, dh_param_p)>=0) {
log_fn(LOG_WARN, "Rejecting DH key >= p");
warn(LD_CRYPTO, "Rejecting DH key >= p");
return -1;
}
n_bits = BN_num_bits(bn);
......@@ -1471,18 +1473,18 @@ tor_check_dh_key(BIGNUM *bn)
++n_set;
}
if (n_set < MIN_DIFFERING_BITS || n_set >= n_bits-MIN_DIFFERING_BITS) {
log_fn(LOG_WARN, "Too few/many bits in DH key (%d)", n_set);
warn(LD_CRYPTO, "Too few/many bits in DH key (%d)", n_set);
goto err;
}
BN_set_word(x, MIN_DIST_FROM_EDGE);
if (BN_cmp(bn,x)<=0) {
log_fn(LOG_WARN, "DH key is too close to 0");
warn(LD_CRYPTO, "DH key is too close to 0");
goto err;
}
BN_copy(x,dh_param_p);
BN_sub_word(x, MIN_DIST_FROM_EDGE);
if (BN_cmp(bn,x)>=0) {
log_fn(LOG_WARN, "DH key is too close to p");
warn(LD_CRYPTO, "DH key is too close to p");
goto err;
}
BN_free(x);
......@@ -1490,7 +1492,7 @@ tor_check_dh_key(BIGNUM *bn)
err:
BN_free(x);
s = BN_bn2hex(bn);
log_fn(LOG_WARN, "Rejecting invalid DH key [%s]", s);
warn(LD_CRYPTO, "Rejecting invalid DH key [%s]", s);
OPENSSL_free(s);
return -1;
}
......@@ -1525,13 +1527,13 @@ crypto_dh_compute_secret(crypto_dh_env_t *dh,
goto error;
if (tor_check_dh_key(pubkey_bn)<0) {
/* Check for invalid public keys. */
log_fn(LOG_WARN,"Rejected invalid g^x");
warn(LD_CRYPTO,"Rejected invalid g^x");
goto error;
}
secret_tmp = tor_malloc(crypto_dh_get_bytes(dh)+1);
result = DH_compute_key((unsigned char*)secret_tmp, pubkey_bn, dh->dh);
if (result < 0) {
log_fn(LOG_WARN,"DH_compute_key() failed.");
warn(LD_CRYPTO,"DH_compute_key() failed.");
goto error;
}
secret_len = result;
......@@ -1612,7 +1614,7 @@ crypto_seed_rng(void)
* functions. If one succeeds, we'll accept the RNG as seeded. */
rand_poll_status = RAND_poll();
if (rand_poll_status == 0)
log_fn(LOG_WARN, "RAND_poll() failed.");
warn(LD_CRYPTO, "RAND_poll() failed.");
#else
rand_poll_status = 0;
#endif
......@@ -1621,14 +1623,14 @@ crypto_seed_rng(void)
if (!provider_set) {
if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
if (GetLastError() != NTE_BAD_KEYSET) {
log_fn(LOG_WARN, "Can't get CryptoAPI provider [1]");
warn(LD_CRYPTO, "Can't get CryptoAPI provider [1]");
return rand_poll_status ? 0 : -1;
}
}
provider_set = 1;
}
if (!CryptGenRandom(provider, sizeof(buf), buf)) {
log_fn(LOG_WARN, "Can't get entropy from CryptoAPI.");
warn(LD_CRYPTO, "Can't get entropy from CryptoAPI.");
return rand_poll_status ? 0 : -1;
}
RAND_seed(buf, sizeof(buf));
......@@ -1637,18 +1639,18 @@ crypto_seed_rng(void)
for (i = 0; filenames[i]; ++i) {
fd = open(filenames[i], O_RDONLY, 0);
if (fd<0) continue;
log_fn(LOG_INFO, "Seeding RNG from \"%s\"", filenames[i]);
info(LD_CRYPTO, "Seeding RNG from \"%s\"", filenames[i]);
n = read_all(fd, buf, sizeof(buf), 0);
close(fd);
if (n != sizeof(buf)) {
log_fn(LOG_WARN, "Error reading from entropy source");
warn(LD_CRYPTO, "Error reading from entropy source");
return -1;
}
RAND_seed(buf, sizeof(buf));
return 0;
}
log_fn(LOG_WARN, "Cannot seed RNG -- no entropy source found.");
warn(LD_CRYPTO, "Cannot seed RNG -- no entropy source found.");
return rand_poll_status ? 0 : -1;
#endif
}
......
......@@ -38,7 +38,7 @@ typedef struct logfile_t {
char *filename; /**< Filename to open. */
FILE *file; /**< Stream to receive log messages. */
int needs_close; /**< Boolean: true if the stream gets closed on shutdown. */
int loglevel; /**< Lowest severity level to send to this stream. */
int min_loglevel; /**< Lowest severity level to send to this stream. */
int max_loglevel; /**< Highest severity level to send to this stream. */
int is_temporary; /**< Boolean: close after initializing logging subsystem.*/
int is_syslog; /**< Boolean: send messages to syslog. */
......@@ -184,7 +184,8 @@ format_msg(char *buf, size_t buf_len,
* message. The actual message is derived as from tor_snprintf(format,ap).
*/
static void
logv(int severity, const char *funcname, const char *format, va_list ap)
logv(int severity, int domain, const char *funcname, const char *format,
va_list ap)
{
char buf[10024];
int formatted = 0;
......@@ -194,7 +195,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
assert(format);
lf = logfiles;
while (lf) {
if (severity > lf->loglevel || severity < lf->max_loglevel) {
if (severity > lf->min_loglevel || severity < lf->max_loglevel) {
lf = lf->next;
continue;
}
......@@ -215,7 +216,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
lf = lf->next;
continue;
} else if (lf->callback) {
lf->callback(severity, end_of_prefix);
lf->callback(severity, domain, end_of_prefix);
lf = lf->next;
continue;
}
......@@ -233,32 +234,77 @@ logv(int severity, const char *funcname, const char *format, va_list ap)
/** Output a message to the log. */
void
_log(int severity, const char *format, ...)
_log(int severity, int domain, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(severity, NULL, format, ap);
logv(severity, domain, NULL, format, ap);
va_end(ap);
}
/** Output a message to the log, prefixed with a function name <b>fn</b>. */
#ifdef __GNUC__
void
_log_fn(int severity, const char *fn, const char *format, ...)
_log_fn(int severity, int domain, const char *fn, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(severity, fn, format, ap);
logv(severity, domain, fn, format, ap);
va_end(ap);
}
#else
const char *_log_fn_function_name=NULL;
void
_log_fn(int severity, const char *format, ...)
_log_fn(int severity, int domain, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(severity, _log_fn_function_name, format, ap);
logv(severity, domain, _log_fn_function_name, format, ap);
va_end(ap);
_log_fn_function_name = NULL;
}
void
_debug(int domain, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(LOG_DEBUG, domain, _log_fn_function_name, format, ap);
va_end(ap);
_log_fn_function_name = NULL;
}
void
_info(int domain, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(LOG_INFO, domain, _log_fn_function_name, format, ap);
va_end(ap);
_log_fn_function_name = NULL;
}
void
_notice(int domain, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(LOG_NOTICE, domain, _log_fn_function_name, format, ap);
va_end(ap);
_log_fn_function_name = NULL;
}
void
_warn(int domain, const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(LOG_ERR, domain, _log_fn_function_name, format, ap);
va_end(ap);
_log_fn_function_name = NULL;
}
void
_err(const char *format, ...)
{
va_list ap;
va_start(ap,format);
logv(LOG_ERR, LD_GENERAL, _log_fn_function_name, format, ap);
va_end(ap);
_log_fn_function_name = NULL;
}
......@@ -359,7 +405,7 @@ add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream)
logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t));
lf->filename = tor_strdup(name);
lf->loglevel = loglevelMin;
lf->min_loglevel = loglevelMin;
lf->max_loglevel = loglevelMax;
lf->file = stream;
lf->next = logfiles;
......@@ -386,7 +432,7 @@ add_callback_log(int loglevelMin, int loglevelMax, log_callback cb)
{
logfile_t *lf;
lf = tor_malloc_zero(sizeof(logfile_t));
lf->loglevel = loglevelMin;
lf->min_loglevel = loglevelMin;
lf->max_loglevel = loglevelMax;
lf->filename = tor_strdup("<callback>");
lf->callback = cb;
......@@ -402,7 +448,7 @@ change_callback_log_severity(int loglevelMin, int loglevelMax,
logfile_t *lf;
for (lf = logfiles; lf; lf = lf->next) {
if (lf->callback == cb) {
lf->loglevel = loglevelMin;
lf->min_loglevel = loglevelMin;
lf->max_loglevel = loglevelMax;
}
}
......@@ -468,7 +514,7 @@ add_syslog_log(int loglevelMin, int loglevelMax)
openlog("Tor", LOG_NDELAY, LOG_DAEMON);
lf = tor_malloc_zero(sizeof(logfile_t));
lf->loglevel = loglevelMin;
lf->min_loglevel = loglevelMin;
lf->filename = tor_strdup("<syslog>");
lf->max_loglevel = loglevelMax;
lf->is_syslog = 1;
......@@ -510,8 +556,8 @@ get_min_log_level(void)
logfile_t *lf;
int min = LOG_ERR;
for (lf = logfiles; lf; lf = lf->next) {
if (lf->loglevel > min)
min = lf->loglevel;
if (lf->min_loglevel > min)
min = lf->min_loglevel;
}
return min;
}
......@@ -522,7 +568,7 @@ switch_logs_debug(void)
{
logfile_t *lf;
for (lf = logfiles; lf; lf=lf->next) {
lf->loglevel = LOG_DEBUG;
lf->min_loglevel = LOG_DEBUG;
}
}
......@@ -541,19 +587,20 @@ libevent_logging_callback(int severity, const char *msg)
}
switch (severity) {
case _EVENT_LOG_DEBUG:
log(LOG_DEBUG, "Message from libevent: %s", buf);
log(LOG_DEBUG, LD_NET, "Message from libevent: %s", buf);
break;
case _EVENT_LOG_MSG:
log(LOG_INFO, "Message from libevent: %s", buf);
log(LOG_INFO, LD_NET, "Message from libevent: %s", buf);
break;
case _EVENT_LOG_WARN:
log(LOG_WARN, "Warning from libevent: %s", buf);
log(LOG_WARN, LD_GENERAL, "Warning from libevent: %s", buf);
break;
case _EVENT_LOG_ERR:
log(LOG_ERR, "Error from libevent: %s", buf);
log(LOG_ERR, LD_GENERAL, "Error from libevent: %s", buf);
break;
default:
log(LOG_WARN, "Message [%d] from libevent: %s", severity, buf);
log(LOG_WARN, LD_GENERAL, "Message [%d] from libevent: %s",
severity, buf);
break;
}
}
......
......@@ -50,7 +50,15 @@
#define LOG_ERR 3
#endif
typedef void (*log_callback)(int severity, const char *msg);
/* Logging domains */
#define LD_GENERAL 0
#define LD_CRYPTO 1
#define LD_NET 2
#define LD_CONFIG 3
#define LD_FS 4
#define LD_PROTOCOL 5
typedef void (*log_callback)(int severity, int domain, const char *msg);
int parse_log_level(const char *level);
const char *log_level_to_string(int level);
......@@ -73,29 +81,69 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax,
log_callback cb);
/* Outputs a message to stdout */
void _log(int severity, const char *format, ...) CHECK_PRINTF(2,3);
void _log(int severity, int domain, const char *format, ...) CHECK_PRINTF(3,4);
#ifdef __GNUC__
void _log_fn(int severity, const char *funcname, const