mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
treewide: improve logging
Provide multi-priority syslog() based logging to improve user and developer experience. Add dawnlog_* functions and macros to convert printf() family and perror() logging to syslog() family. Removed unnecessary sprintf() for building log strings (embed format directly). Add local config settings for log level. Add command line parameters for log level and destination. Set default log level to suppress a lot of previously noisy messages. Restore some previously removed noisy messages as DEBUG level in case they help in future. Eliminate DAWN_NO_OUTPUT static code checks which are no longer used. Signed-off-by: Ian Clowes <clowes_ian@hotmail.com>
This commit is contained in:
parent
ddc007e32c
commit
4df0c986f1
18 changed files with 922 additions and 396 deletions
|
|
@ -127,6 +127,10 @@ struct time_config_s {
|
|||
time_t update_beacon_reports;
|
||||
};
|
||||
|
||||
struct local_config_s {
|
||||
int loglevel;
|
||||
};
|
||||
|
||||
#define MAX_IP_LENGTH 46
|
||||
#define MAX_KEY_LENGTH 65
|
||||
|
||||
|
|
@ -145,12 +149,10 @@ struct network_config_s {
|
|||
|
||||
extern struct network_config_s network_config;
|
||||
extern struct time_config_s timeout_config;
|
||||
extern struct local_config_s local_config;
|
||||
extern struct probe_metric_s dawn_metric;
|
||||
|
||||
/*** Core DAWN data structures for tracking network devices and status ***/
|
||||
// Define this to remove printing / reporing of fields, and hence observe
|
||||
// which fields are evaluated in use at compile time.
|
||||
// #define DAWN_NO_OUTPUT
|
||||
|
||||
// TODO notes:
|
||||
// Never used? = No code reference
|
||||
|
|
@ -174,11 +176,9 @@ typedef struct probe_entry_s {
|
|||
uint8_t vht_capabilities; // eval_probe_metric()
|
||||
time_t time; // remove_old...entries
|
||||
int counter;
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
int deny_counter; // TODO: Never used?
|
||||
uint8_t max_supp_datarate; // TODO: Never used?
|
||||
uint8_t min_supp_datarate; // TODO: Never used?
|
||||
#endif
|
||||
uint32_t rcpi;
|
||||
uint32_t rsni;
|
||||
} probe_entry;
|
||||
|
|
@ -316,7 +316,7 @@ void remove_old_probe_entries(time_t current_time, long long int threshold);
|
|||
|
||||
void print_probe_array();
|
||||
|
||||
void print_probe_entry(probe_entry *entry);
|
||||
void print_probe_entry(int level, probe_entry *entry);
|
||||
|
||||
int eval_probe_metric(struct probe_entry_s * probe_entry, ap *ap_entry);
|
||||
|
||||
|
|
@ -326,7 +326,7 @@ auth_entry *insert_to_denied_req_array(auth_entry*entry, int inc_counter, time_t
|
|||
|
||||
void remove_old_denied_req_entries(time_t current_time, long long int threshold, int logmac);
|
||||
|
||||
void print_auth_entry(auth_entry *entry);
|
||||
void print_auth_entry(int level, auth_entry *entry);
|
||||
|
||||
// ---------------- Functions ----------------
|
||||
|
||||
|
|
@ -350,7 +350,7 @@ client *client_array_delete(client *entry, int unlink_only);
|
|||
|
||||
void print_client_array();
|
||||
|
||||
void print_client_entry(client *entry);
|
||||
void print_client_entry(int level, client *entry);
|
||||
|
||||
int is_connected_somehwere(struct dawn_mac client_addr);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ struct probe_metric_s uci_get_dawn_metric();
|
|||
*/
|
||||
struct time_config_s uci_get_time_config();
|
||||
|
||||
/**
|
||||
* Function that returns a struct with all the local config values.
|
||||
* @return the local config values.
|
||||
*/
|
||||
struct local_config_s uci_get_local_config();
|
||||
|
||||
/**
|
||||
* Function that returns all the network informations.
|
||||
* @return the network config values.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define __DAWN_UTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <syslog.h>
|
||||
|
||||
/**
|
||||
* Check if a string is greater than another one.
|
||||
|
|
@ -11,4 +12,91 @@
|
|||
*/
|
||||
int string_is_greater(char *str, char *str_2);
|
||||
|
||||
|
||||
/*
|
||||
** Log handling for dawn process
|
||||
*/
|
||||
#define DAWNLOG_DEST_SYSLOG 0 // Send log output to syslog...
|
||||
#define DAWNLOG_DEST_STDIO 1 // ... or stdout / stderr as appropriate
|
||||
|
||||
#define DAWNLOG_PERROR 0x08 // Bit flag to signal inclusion of errno from system calls
|
||||
|
||||
#define DAWNLOG_PRIMASK 0x07 // Bitmask to obtain only priority value
|
||||
|
||||
#define DAWNLOG_ERROR 5 // Serious malfunction / unexpected behaviour - eg: OS resource exhaustion
|
||||
#define DAWNLOG_WARNING 4 // Something appears wrong, but recoverable - eg: data structures inconsistent
|
||||
#define DAWNLOG_ALWAYS 3 // Standard behaviour always worth reporting - should be very low frequency messages
|
||||
#define DAWNLOG_INFO 2 // Reporting on standard behaviour - should be comprehensible to user
|
||||
#define DAWNLOG_TRACE 1 // More info to help trace where algorithms may be going wrong
|
||||
#define DAWNLOG_DEBUG 0 // Deeper tracing to fix bugs
|
||||
|
||||
#define DAWNLOG_COMPILE_MIN DAWNLOG_DEBUG // Messages lower than this priority are not compiled
|
||||
#define DAWNLOG_COMPILING(level) (level >= DAWNLOG_COMPILE_MIN)
|
||||
|
||||
#define dawnlog_perror(s, ...) dawnlog(DAWNLOG_ERROR|DAWNLOG_PERROR, "%s()=%s@%d %s - " s, __func__, dawnlog_basename(__FILE__), __LINE__, dawnlog_pbuf, ##__VA_ARGS__)
|
||||
#define dawnlog_error(fmt, ...) dawnlog(DAWNLOG_ERROR, "%s()=%s@%d " fmt, __func__, dawnlog_basename(__FILE__), __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define dawnlog_warning(fmt, ...) dawnlog(DAWNLOG_WARNING, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define dawnlog_always(fmt, ...) dawnlog(DAWNLOG_ALWAYS, fmt, ##__VA_ARGS__)
|
||||
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_INFO)
|
||||
#define dawnlog_info(fmt, ...) dawnlog(DAWNLOG_INFO, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dawnlog_info(fmt, ...)
|
||||
#endif
|
||||
|
||||
// Use the ..._func variants to get source code position added automatically: function, filename, line
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_TRACE)
|
||||
#define dawnlog_trace(fmt, ...) dawnlog(DAWNLOG_TRACE, fmt, ##__VA_ARGS__)
|
||||
#define dawnlog_trace_func(fmt, ...) dawnlog(DAWNLOG_TRACE, "%s()=%s@%d " fmt, __func__, dawnlog_basename(__FILE__), __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dawnlog_trace(fmt, ...)
|
||||
#define dawnlog_trace_func(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_DEBUG)
|
||||
#define dawnlog_debug(fmt, ...) dawnlog(DAWNLOG_DEBUG, fmt, ##__VA_ARGS__)
|
||||
#define dawnlog_debug_func(fmt, ...) dawnlog(DAWNLOG_DEBUG, "%s()=%s@%d " fmt, __func__, dawnlog_basename(__FILE__), __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dawnlog_debug(fmt, ...)
|
||||
#define dawnlog_debug_func(fmt, ...)
|
||||
#endif
|
||||
|
||||
extern char dawnlog_pbuf[]; // Buffer for errno conversion for dawnlog_perror()
|
||||
|
||||
/**
|
||||
* Set the output target for dawnlog()
|
||||
* @param logdest: DAWNLOG_DEST_*
|
||||
*/
|
||||
void dawnlog_dest(int logdest);
|
||||
|
||||
/**
|
||||
* Minimum priority level to be logged
|
||||
* @param level: A priority level
|
||||
*/
|
||||
void dawnlog_minlevel(int level);
|
||||
|
||||
/**
|
||||
* Check whether a priority level would be actually logged to allow callers
|
||||
* to skip "expensive" preparation such as string manipulation or loops
|
||||
* @param level
|
||||
* @return TRUE if the priority level would be logged
|
||||
*/
|
||||
int dawnlog_showing(int level);
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
* @param level
|
||||
* @param fmt
|
||||
* @return
|
||||
*/
|
||||
void dawnlog(int level, const char* fmt, ...);
|
||||
|
||||
/**
|
||||
* Return pointer to filename part of full path.
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
const char* dawnlog_basename(const char* file);
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue