2012-07-29 03:05:53 +00:00
|
|
|
/*
|
2012-07-30 03:28:21 +00:00
|
|
|
Copyright (C) 2012 Serval Project Inc.
|
2012-07-29 03:05:53 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-07-30 03:28:21 +00:00
|
|
|
#ifndef __SERVALD_LOG_H
|
|
|
|
#define __SERVALD_LOG_H
|
|
|
|
|
2012-07-29 03:05:53 +00:00
|
|
|
#include <stdio.h>
|
2012-08-03 03:42:54 +00:00
|
|
|
#include <stdarg.h>
|
2012-08-06 06:09:08 +00:00
|
|
|
#include "strbuf_helpers.h"
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-07-30 03:28:21 +00:00
|
|
|
extern unsigned int debug;
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-07-30 03:28:21 +00:00
|
|
|
#define DEBUG_ALL (~0)
|
|
|
|
#define DEBUG_PACKETRX (1 << 0)
|
|
|
|
#define DEBUG_OVERLAYINTERFACES (1 << 1)
|
|
|
|
#define DEBUG_VERBOSE (1 << 2)
|
|
|
|
#define DEBUG_VERBOSE_IO (1 << 3)
|
|
|
|
#define DEBUG_PEERS (1 << 4)
|
|
|
|
#define DEBUG_DNARESPONSES (1 << 5)
|
|
|
|
#define DEBUG_DNAHELPER (1 << 6)
|
2012-08-02 01:59:37 +00:00
|
|
|
#define DEBUG_VOMP (1 << 7)
|
2012-07-30 03:28:21 +00:00
|
|
|
#define DEBUG_RHIZOME_RX (1 << 8)
|
|
|
|
#define DEBUG_PACKETFORMATS (1 << 9)
|
|
|
|
#define DEBUG_GATEWAY (1 << 10)
|
|
|
|
#define DEBUG_KEYRING (1 << 11)
|
|
|
|
#define DEBUG_IO (1 << 12)
|
|
|
|
#define DEBUG_OVERLAYFRAMES (1 << 13)
|
|
|
|
#define DEBUG_OVERLAYABBREVIATIONS (1 << 14)
|
|
|
|
#define DEBUG_OVERLAYROUTING (1 << 15)
|
|
|
|
#define DEBUG_SECURITY (1 << 16)
|
|
|
|
#define DEBUG_RHIZOME (1 << 17)
|
|
|
|
#define DEBUG_OVERLAYROUTEMONITOR (1 << 18)
|
|
|
|
#define DEBUG_QUEUES (1 << 19)
|
|
|
|
#define DEBUG_BROADCASTS (1 << 20)
|
|
|
|
#define DEBUG_RHIZOME_TX (1 << 21)
|
|
|
|
#define DEBUG_PACKETTX (1 << 22)
|
|
|
|
#define DEBUG_PACKETCONSTRUCTION (1 << 23)
|
|
|
|
#define DEBUG_MANIFESTS (1 << 24)
|
|
|
|
#define DEBUG_MDPREQUESTS (1 << 25)
|
|
|
|
#define DEBUG_TIMING (1 << 26)
|
|
|
|
|
|
|
|
#define LOG_LEVEL_SILENT (-1)
|
|
|
|
#define LOG_LEVEL_DEBUG (0)
|
|
|
|
#define LOG_LEVEL_INFO (1)
|
|
|
|
#define LOG_LEVEL_WARN (2)
|
|
|
|
#define LOG_LEVEL_ERROR (3)
|
|
|
|
#define LOG_LEVEL_FATAL (4)
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-08-08 01:26:05 +00:00
|
|
|
struct strbuf;
|
|
|
|
|
2012-08-23 03:01:07 +00:00
|
|
|
struct __sourceloc {
|
|
|
|
const char *file;
|
|
|
|
unsigned int line;
|
|
|
|
const char *function;
|
|
|
|
};
|
|
|
|
|
2012-07-29 03:05:53 +00:00
|
|
|
void set_logging(FILE *f);
|
|
|
|
FILE *open_logging();
|
|
|
|
void close_logging();
|
2012-08-23 03:01:07 +00:00
|
|
|
void logArgv(int level, struct __sourceloc where, const char *label, int argc, const char *const *argv);
|
|
|
|
void logString(int level, struct __sourceloc where, const char *str);
|
|
|
|
void logMessage(int level, struct __sourceloc where, const char *fmt, ...);
|
|
|
|
void vlogMessage(int level, struct __sourceloc where, const char *fmt, va_list);
|
2012-07-29 03:05:53 +00:00
|
|
|
unsigned int debugFlagMask(const char *flagname);
|
2012-08-23 03:01:07 +00:00
|
|
|
int logDump(int level, struct __sourceloc where, char *name, unsigned char *addr, size_t len);
|
2012-08-06 06:09:08 +00:00
|
|
|
char *toprint(char *dstStr, ssize_t dstBufSiz, const char *srcBuf, size_t srcBytes);
|
|
|
|
size_t toprint_strlen(const char *srcBuf, size_t srcBytes);
|
2012-07-29 03:05:53 +00:00
|
|
|
ssize_t get_self_executable_path(char *buf, size_t len);
|
2012-08-23 03:01:07 +00:00
|
|
|
int log_backtrace(struct __sourceloc where);
|
2012-08-08 01:26:05 +00:00
|
|
|
void set_log_implementation(void (*log_function)(int level, struct strbuf *buf));
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-08-06 06:09:08 +00:00
|
|
|
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca((dstlen) == -1 ? toprint_strlen((buf),(len)) + 1 : (dstlen)), (dstlen), (buf), (len))
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-08-23 03:01:07 +00:00
|
|
|
#define __HERE__ ((struct __sourceloc){ .file = __FILE__, .line = __LINE__, .function = __FUNCTION__ })
|
|
|
|
#define __NOWHERE__ ((struct __sourceloc){ .file = NULL, .line = 0, .function = NULL })
|
|
|
|
|
|
|
|
#define LOGF(L,F,...) (logMessage(L, __HERE__, F, ##__VA_ARGS__))
|
|
|
|
#define LOGF_perror(L,F,...) logMessage_perror(L, __HERE__, F, ##__VA_ARGS__)
|
2012-07-29 03:05:53 +00:00
|
|
|
#define LOG_perror(L,X) LOGF_perror(L, "%s", (X))
|
|
|
|
|
2012-08-23 03:01:07 +00:00
|
|
|
#define logMessage_perror(L,where,F,...) (logMessage(L, where, F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno))
|
2012-07-29 03:05:53 +00:00
|
|
|
|
|
|
|
#define FATALF(F,...) do { LOGF(LOG_LEVEL_FATAL, F, ##__VA_ARGS__); exit(-1); } while (1)
|
|
|
|
#define FATAL(X) FATALF("%s", (X))
|
2012-08-21 04:04:08 +00:00
|
|
|
#define FATALF_perror(F,...) FATALF(F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
|
|
|
|
#define FATAL_perror(X) FATALF_perror("%s", (X))
|
2012-07-29 03:05:53 +00:00
|
|
|
|
|
|
|
#define WHYF(F,...) (LOGF(LOG_LEVEL_ERROR, F, ##__VA_ARGS__), -1)
|
|
|
|
#define WHY(X) WHYF("%s", (X))
|
2012-08-20 09:03:34 +00:00
|
|
|
#define WHYFNULL(F,...) (LOGF(LOG_LEVEL_ERROR, F, ##__VA_ARGS__), NULL)
|
|
|
|
#define WHYNULL(X) (WHYFNULL("%s", (X)))
|
2012-07-29 03:05:53 +00:00
|
|
|
#define WHYF_perror(F,...) WHYF(F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
|
|
|
|
#define WHY_perror(X) WHYF("%s: %s [errno=%d]", (X), strerror(errno), errno)
|
|
|
|
|
|
|
|
#define WARNF(F,...) LOGF(LOG_LEVEL_WARN, F, ##__VA_ARGS__)
|
|
|
|
#define WARN(X) WARNF("%s", (X))
|
|
|
|
#define WARN_perror(X) WARNF("%s: %s [errno=%d]", (X), strerror(errno), errno)
|
2012-08-23 03:01:07 +00:00
|
|
|
#define WHY_argv(X,ARGC,ARGV) logArgv(LOG_LEVEL_ERROR, __HERE__, (X), (ARGC), (ARGV))
|
2012-07-29 03:05:53 +00:00
|
|
|
|
|
|
|
#define INFOF(F,...) LOGF(LOG_LEVEL_INFO, F, ##__VA_ARGS__)
|
|
|
|
#define INFO(X) INFOF("%s", (X))
|
|
|
|
|
|
|
|
#define DEBUGF(F,...) LOGF(LOG_LEVEL_DEBUG, F, ##__VA_ARGS__)
|
|
|
|
#define DEBUG(X) DEBUGF("%s", (X))
|
|
|
|
#define DEBUGF_perror(F,...) DEBUGF(F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
|
|
|
|
#define DEBUG_perror(X) DEBUGF("%s: %s [errno=%d]", (X), strerror(errno), errno)
|
|
|
|
#define D DEBUG("D")
|
2012-08-23 03:01:07 +00:00
|
|
|
#define DEBUG_argv(X,ARGC,ARGV) logArgv(LOG_LEVEL_DEBUG, __HERE__, (X), (ARGC), (ARGV))
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-08-23 03:01:07 +00:00
|
|
|
#define dump(X,A,N) logDump(LOG_LEVEL_DEBUG, __HERE__, (X), (A), (N))
|
2012-07-31 06:50:09 +00:00
|
|
|
|
2012-08-23 03:01:07 +00:00
|
|
|
#define BACKTRACE log_backtrace(__HERE__)
|
2012-07-29 03:05:53 +00:00
|
|
|
|
2012-07-30 03:28:21 +00:00
|
|
|
#endif // __SERVALD_LOG_H
|