mirror of
https://git.proxmox.com/git/mirror_corosync
synced 2025-07-24 16:03:05 +00:00
logsys: merge tags into rec_ident
git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2246 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
parent
5facfffb66
commit
5597a2381f
158
exec/logsys.c
158
exec/logsys.c
@ -67,7 +67,7 @@
|
||||
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
/*
|
||||
* syslog tagnames, priorityanmes, facility names to value mapping
|
||||
* syslog prioritynames, facility names to value mapping
|
||||
* Some C libraries build this in to their headers, but it is non-portable
|
||||
* so logsys supplies its own version.
|
||||
*/
|
||||
@ -76,22 +76,6 @@ struct syslog_names {
|
||||
int c_val;
|
||||
};
|
||||
|
||||
struct syslog_names tagnames[] =
|
||||
{
|
||||
{ "log", LOGSYS_TAG_LOG },
|
||||
{ "enter", LOGSYS_TAG_ENTER },
|
||||
{ "leave", LOGSYS_TAG_LEAVE },
|
||||
{ "trace1", LOGSYS_TAG_TRACE1 },
|
||||
{ "trace2", LOGSYS_TAG_TRACE2 },
|
||||
{ "trace3", LOGSYS_TAG_TRACE3 },
|
||||
{ "trace4", LOGSYS_TAG_TRACE4 },
|
||||
{ "trace5", LOGSYS_TAG_TRACE5 },
|
||||
{ "trace6", LOGSYS_TAG_TRACE6 },
|
||||
{ "trace7", LOGSYS_TAG_TRACE7 },
|
||||
{ "trace8", LOGSYS_TAG_TRACE8 },
|
||||
{ NULL, -1 }
|
||||
};
|
||||
|
||||
struct syslog_names prioritynames[] =
|
||||
{
|
||||
{ "alert", LOG_ALERT },
|
||||
@ -156,7 +140,6 @@ struct logsys_logger {
|
||||
FILE *logfile_fp; /* track file descriptor */
|
||||
unsigned int mode; /* subsystem mode */
|
||||
unsigned int debug; /* debug on|off */
|
||||
unsigned int tags; /* trace tags */
|
||||
int syslog_facility; /* facility */
|
||||
int syslog_priority; /* priority */
|
||||
int logfile_priority; /* priority to file */
|
||||
@ -236,23 +219,6 @@ static char *decode_mode(int subsysid, char *buf, size_t buflen)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char *decode_tags(int subsysid, char *buf, size_t buflen)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
memset(buf, 0, buflen);
|
||||
|
||||
for (i = 0; tagnames[i].c_name != NULL; i++) {
|
||||
if (logsys_loggers[subsysid].tags & tagnames[i].c_val) {
|
||||
snprintf(buf+strlen(buf), buflen, "%s,", tagnames[i].c_name);
|
||||
}
|
||||
}
|
||||
|
||||
memset(buf+strlen(buf)-1,0,1);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
static const char *decode_debug(int subsysid)
|
||||
{
|
||||
if (logsys_loggers[subsysid].debug)
|
||||
@ -272,7 +238,6 @@ static const char *decode_status(int subsysid)
|
||||
static void dump_subsys_config(int subsysid)
|
||||
{
|
||||
char modebuf[1024];
|
||||
char tagbuf[1024];
|
||||
|
||||
fprintf(stderr,
|
||||
"ID: %d\n"
|
||||
@ -281,7 +246,6 @@ static void dump_subsys_config(int subsysid)
|
||||
"logfile_fp: %p\n"
|
||||
"mode: %s\n"
|
||||
"debug: %s\n"
|
||||
"tags: %s\n"
|
||||
"syslog_fac: %s\n"
|
||||
"syslog_pri: %s\n"
|
||||
"logfile_pri: %s\n"
|
||||
@ -292,7 +256,6 @@ static void dump_subsys_config(int subsysid)
|
||||
logsys_loggers[subsysid].logfile_fp,
|
||||
decode_mode(subsysid, modebuf, sizeof(modebuf)),
|
||||
decode_debug(subsysid),
|
||||
decode_tags(subsysid, tagbuf, sizeof(tagbuf)),
|
||||
logsys_facility_name_get(logsys_loggers[subsysid].syslog_facility),
|
||||
logsys_priority_name_get(logsys_loggers[subsysid].syslog_priority),
|
||||
logsys_priority_name_get(logsys_loggers[subsysid].logfile_priority),
|
||||
@ -456,7 +419,7 @@ static void log_printf_to_logs (
|
||||
const char *function_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int tag,
|
||||
unsigned int rec_ident,
|
||||
const char *buffer)
|
||||
{
|
||||
char normal_output_buffer[COMBINE_BUFFER_SIZE];
|
||||
@ -470,23 +433,17 @@ static void log_printf_to_logs (
|
||||
size_t cutoff;
|
||||
unsigned int normal_len, syslog_len;
|
||||
int subsysid;
|
||||
int c, i, has_tag = 0;
|
||||
int c;
|
||||
|
||||
if (rec_ident != LOGSYS_RECID_LOG) {
|
||||
return;
|
||||
}
|
||||
|
||||
subsysid = _logsys_config_subsys_get(subsys);
|
||||
if (subsysid <= - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 1; tagnames[i].c_name != NULL; i++) {
|
||||
if (tag & tagnames[i].c_val) {
|
||||
if ((logsys_loggers[subsysid].tags & tag) == 0) {
|
||||
return;
|
||||
} else {
|
||||
has_tag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ((c = format_buffer[format_buffer_idx])) {
|
||||
cutoff = 0;
|
||||
if (c != '%') {
|
||||
@ -579,7 +536,7 @@ static void log_printf_to_logs (
|
||||
*/
|
||||
if ((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_SYSLOG) &&
|
||||
((level <= logsys_loggers[subsysid].syslog_priority) ||
|
||||
(logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
|
||||
(logsys_loggers[subsysid].debug != 0))) {
|
||||
syslog (level | logsys_loggers[subsysid].syslog_facility, "%s", syslog_output_buffer);
|
||||
}
|
||||
|
||||
@ -595,7 +552,7 @@ static void log_printf_to_logs (
|
||||
if (((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_FILE) &&
|
||||
(logsys_loggers[subsysid].logfile_fp != NULL)) &&
|
||||
((level <= logsys_loggers[subsysid].logfile_priority) ||
|
||||
(logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
|
||||
(logsys_loggers[subsysid].debug != 0))) {
|
||||
/*
|
||||
* Output to a file
|
||||
*/
|
||||
@ -627,7 +584,7 @@ static void log_printf_to_logs (
|
||||
*/
|
||||
if ((logsys_loggers[subsysid].mode & LOGSYS_MODE_OUTPUT_STDERR) &&
|
||||
((level <= logsys_loggers[subsysid].logfile_priority) ||
|
||||
(logsys_loggers[subsysid].debug != 0) || (has_tag > 0))) {
|
||||
(logsys_loggers[subsysid].debug != 0))) {
|
||||
if (write (STDERR_FILENO, normal_output_buffer, strlen (normal_output_buffer)) < 0) {
|
||||
char tmpbuffer[1024];
|
||||
/*
|
||||
@ -653,7 +610,7 @@ static void record_print (const char *buf)
|
||||
const int *buf_uint32t = (const int *)buf;
|
||||
unsigned int rec_size = buf_uint32t[0];
|
||||
unsigned int level = buf_uint32t[1];
|
||||
unsigned int tag = buf_uint32t[2];
|
||||
unsigned int rec_ident = buf_uint32t[2];
|
||||
unsigned int file_line = buf_uint32t[3];
|
||||
unsigned int i;
|
||||
unsigned int words_processed;
|
||||
@ -684,24 +641,24 @@ static void record_print (const char *buf)
|
||||
(char *)arguments[2],
|
||||
file_line,
|
||||
level,
|
||||
tag,
|
||||
rec_ident,
|
||||
(char *)arguments[3]);
|
||||
}
|
||||
|
||||
static int record_read (char *buf, int rec_idx, int *log_msg) {
|
||||
unsigned int rec_size;
|
||||
unsigned int level;
|
||||
unsigned int rec_ident;
|
||||
unsigned int tag;
|
||||
int firstcopy, secondcopy;
|
||||
|
||||
rec_size = flt_data[rec_idx];
|
||||
rec_ident = flt_data[(rec_idx + 1) % flt_data_size];
|
||||
tag = flt_data[(rec_idx + 2) % flt_data_size];
|
||||
level = flt_data[(rec_idx + 1) % flt_data_size];
|
||||
rec_ident = flt_data[(rec_idx + 2) % flt_data_size];
|
||||
|
||||
/*
|
||||
* Not a log record
|
||||
*/
|
||||
if ((tag & LOGSYS_TAG_LOG) == 0) {
|
||||
if (rec_ident != LOGSYS_RECID_LOG) {
|
||||
*log_msg = 0;
|
||||
return ((rec_idx + rec_size) % flt_data_size);
|
||||
}
|
||||
@ -991,8 +948,7 @@ int _logsys_system_setup(
|
||||
const char *logfile,
|
||||
int logfile_priority,
|
||||
int syslog_facility,
|
||||
int syslog_priority,
|
||||
unsigned int tags)
|
||||
int syslog_priority)
|
||||
{
|
||||
int i;
|
||||
const char *errstr;
|
||||
@ -1025,8 +981,6 @@ int _logsys_system_setup(
|
||||
logsys_loggers[i].syslog_priority = syslog_priority;
|
||||
syslog_facility_reconf();
|
||||
|
||||
logsys_loggers[i].tags = tags;
|
||||
|
||||
logsys_loggers[i].init_status = LOGSYS_LOGGER_INIT_DONE;
|
||||
|
||||
logsys_system_needs_init = LOGSYS_LOGGER_INIT_DONE;
|
||||
@ -1131,8 +1085,8 @@ void _logsys_log_rec (
|
||||
const char *function_name,
|
||||
const char *file_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int rec_ident,
|
||||
unsigned int tag,
|
||||
...)
|
||||
{
|
||||
va_list ap;
|
||||
@ -1150,7 +1104,7 @@ void _logsys_log_rec (
|
||||
/*
|
||||
* Decode VA Args
|
||||
*/
|
||||
va_start (ap, tag);
|
||||
va_start (ap, rec_ident);
|
||||
arguments = 3;
|
||||
for (;;) {
|
||||
buf_args[arguments] = va_arg (ap, void *);
|
||||
@ -1193,10 +1147,10 @@ void _logsys_log_rec (
|
||||
flt_data[idx++] = 0;
|
||||
idx_word_step(idx);
|
||||
|
||||
flt_data[idx++] = rec_ident;
|
||||
flt_data[idx++] = level;
|
||||
idx_word_step(idx);
|
||||
|
||||
flt_data[idx++] = tag;
|
||||
flt_data[idx++] = rec_ident;
|
||||
idx_word_step(idx);
|
||||
|
||||
flt_data[idx++] = file_line;
|
||||
@ -1273,7 +1227,7 @@ void _logsys_log_rec (
|
||||
* the new head position and commit the new head.
|
||||
*/
|
||||
logsys_lock();
|
||||
if (tag & LOGSYS_TAG_LOG) {
|
||||
if (rec_ident == LOGSYS_RECID_LOG) {
|
||||
log_requests_pending += 1;
|
||||
}
|
||||
if (log_requests_pending == 0) {
|
||||
@ -1290,7 +1244,7 @@ void _logsys_log_vprintf (
|
||||
const char *file_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int tag,
|
||||
unsigned int rec_ident,
|
||||
const char *format,
|
||||
va_list ap)
|
||||
{
|
||||
@ -1321,7 +1275,7 @@ void _logsys_log_vprintf (
|
||||
file_name,
|
||||
file_line,
|
||||
level,
|
||||
tag |= LOGSYS_TAG_LOG,
|
||||
rec_ident,
|
||||
logsys_print_buffer, len + 1,
|
||||
LOGSYS_REC_END);
|
||||
|
||||
@ -1331,7 +1285,7 @@ void _logsys_log_vprintf (
|
||||
* expect the worker thread to output the log data once signaled
|
||||
*/
|
||||
log_printf_to_logs (logsys_loggers[subsysid].subsys,
|
||||
file_name, function_name, file_line, level, tag,
|
||||
file_name, function_name, file_line, level, rec_ident,
|
||||
logsys_print_buffer);
|
||||
} else {
|
||||
/*
|
||||
@ -1347,7 +1301,7 @@ void _logsys_log_printf (
|
||||
const char *file_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int tag,
|
||||
unsigned int rec_ident,
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
@ -1355,7 +1309,7 @@ void _logsys_log_printf (
|
||||
|
||||
va_start (ap, format);
|
||||
_logsys_log_vprintf (subsysid, function_name, file_name, file_line,
|
||||
level, tag, format, ap);
|
||||
level, rec_ident, format, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
@ -1415,40 +1369,6 @@ unsigned int logsys_config_mode_get (const char *subsys)
|
||||
return logsys_loggers[i].mode;
|
||||
}
|
||||
|
||||
unsigned int logsys_config_tags_set (const char *subsys, unsigned int tags)
|
||||
{
|
||||
int i;
|
||||
|
||||
pthread_mutex_lock (&logsys_config_mutex);
|
||||
if (subsys != NULL) {
|
||||
i = _logsys_config_subsys_get_unlocked (subsys);
|
||||
if (i >= 0) {
|
||||
logsys_loggers[i].tags = tags;
|
||||
i = 0;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i <= LOGSYS_MAX_SUBSYS_COUNT; i++) {
|
||||
logsys_loggers[i].tags = tags;
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
pthread_mutex_unlock (&logsys_config_mutex);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
unsigned int logsys_config_tags_get (const char *subsys)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = _logsys_config_subsys_get (subsys);
|
||||
if (i < 0) {
|
||||
return i;
|
||||
}
|
||||
|
||||
return logsys_loggers[i].tags;
|
||||
}
|
||||
|
||||
int logsys_config_file_set (
|
||||
const char *subsys,
|
||||
const char **error_string,
|
||||
@ -1652,30 +1572,6 @@ const char *logsys_priority_name_get (unsigned int priority)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int logsys_tag_id_get (const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; tagnames[i].c_name != NULL; i++) {
|
||||
if (strcasecmp(name, tagnames[i].c_name) == 0) {
|
||||
return (tagnames[i].c_val);
|
||||
}
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
const char *logsys_tag_name_get (unsigned int tag)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; tagnames[i].c_name != NULL; i++) {
|
||||
if (tag == tagnames[i].c_val) {
|
||||
return (tagnames[i].c_name);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int logsys_thread_priority_set (
|
||||
int policy,
|
||||
const struct sched_param *param,
|
||||
|
@ -90,7 +90,6 @@ LOGSYS_DECLARE_SYSTEM ("corosync",
|
||||
LOG_INFO,
|
||||
LOG_DAEMON,
|
||||
LOG_INFO,
|
||||
0,
|
||||
NULL,
|
||||
1000000);
|
||||
|
||||
@ -553,14 +552,14 @@ static void ipc_log_printf (const char *format, ...) {
|
||||
va_start (ap, format);
|
||||
|
||||
_logsys_log_vprintf (ipc_subsys_id, __FUNCTION__,
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, 0, format, ap);
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, LOGSYS_RECID_LOG, format, ap);
|
||||
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
static void ipc_fatal_error(const char *error_msg) {
|
||||
_logsys_log_printf (ipc_subsys_id, __FUNCTION__,
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, 0, "%s", error_msg);
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_ERROR, LOGSYS_RECID_LOG, "%s", error_msg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -251,35 +251,6 @@ parse_error:
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static char * strsep_cs(char **stringp, const char *delim)
|
||||
{
|
||||
char *s;
|
||||
const char *spanp;
|
||||
int c, sc;
|
||||
char *tok;
|
||||
|
||||
if ((s = *stringp) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (tok = s; ; ) {
|
||||
c = *s++;
|
||||
spanp = delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0) {
|
||||
s = NULL;
|
||||
}
|
||||
else {
|
||||
s[-1] = 0;
|
||||
}
|
||||
*stringp = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int corosync_main_config_set (
|
||||
struct objdb_iface_ver0 *objdb,
|
||||
hdb_handle_t object_handle,
|
||||
@ -485,36 +456,6 @@ static int corosync_main_config_set (
|
||||
}
|
||||
}
|
||||
|
||||
if (!objdb_get_string (objdb, object_handle, "tags", &value)) {
|
||||
char *temp, *token;
|
||||
unsigned int tags = 0;
|
||||
|
||||
temp = strdup(value);
|
||||
if (temp == NULL) {
|
||||
error_reason = "exhausted virtual memory";
|
||||
goto parse_error;
|
||||
}
|
||||
|
||||
while ((token = strsep_cs(&temp, "|")) != NULL) {
|
||||
int val;
|
||||
|
||||
val = logsys_tag_id_get(token);
|
||||
if (val < 0) {
|
||||
error_reason = "bad tags value";
|
||||
goto parse_error;
|
||||
}
|
||||
tags |= val;
|
||||
}
|
||||
free(temp);
|
||||
|
||||
tags |= LOGSYS_TAG_LOG;
|
||||
|
||||
if (logsys_config_tags_set (subsys, tags) < 0) {
|
||||
error_reason = "unable to set tags";
|
||||
goto parse_error;
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
parse_error:
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/poll.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <corosync/sq.h>
|
||||
#include <corosync/list.h>
|
||||
@ -158,7 +159,7 @@ struct totemnet_instance {
|
||||
const char *function,
|
||||
const char *file,
|
||||
int line, unsigned int level,
|
||||
unsigned int tag,
|
||||
unsigned int rec_ident,
|
||||
const char *format,
|
||||
...)__attribute__((format(printf, 7, 8)));
|
||||
|
||||
@ -241,11 +242,13 @@ static void totemnet_instance_initialize (struct totemnet_instance *instance)
|
||||
instance->my_memb_entries = 1;
|
||||
}
|
||||
|
||||
#define RECID_LOG UINT_MAX - 1
|
||||
|
||||
#define log_printf(level, format, args...) \
|
||||
do { \
|
||||
instance->totemnet_log_printf (instance->totemnet_subsys_id, \
|
||||
__FUNCTION__, __FILE__, __LINE__, \
|
||||
level, 0, (const char *)format, ##args); \
|
||||
level, RECID_LOG, (const char *)format, ##args); \
|
||||
} while (0);
|
||||
|
||||
|
||||
|
@ -92,6 +92,7 @@
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <corosync/swab.h>
|
||||
#include <corosync/hdb.h>
|
||||
@ -159,7 +160,7 @@ static int totempg_log_level_notice;
|
||||
static int totempg_log_level_debug;
|
||||
static int totempg_subsys_id;
|
||||
static void (*totempg_log_printf) (int subsys_id, const char *function,
|
||||
const char *file, int line, unsigned int level, unsigned int tag,
|
||||
const char *file, int line, unsigned int level, unsigned int rec_ident,
|
||||
const char *format, ...) __attribute__((format(printf, 7, 8)));
|
||||
|
||||
struct totem_config *totempg_totem_config;
|
||||
@ -236,10 +237,12 @@ static pthread_mutex_t callback_token_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static pthread_mutex_t mcast_msg_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#define RECID_LOG UINT_MAX - 1
|
||||
|
||||
#define log_printf(level, format, args...) \
|
||||
do { \
|
||||
totempg_log_printf (totempg_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, level, 0, format, ##args); \
|
||||
__FILE__, __LINE__, level, RECID_LOG, format, ##args); \
|
||||
} while (0);
|
||||
|
||||
static int msg_count_send_ok (int msg_count);
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/poll.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <corosync/sq.h>
|
||||
#include <corosync/list.h>
|
||||
@ -206,7 +207,7 @@ struct totemrrp_instance {
|
||||
int totemrrp_subsys_id;
|
||||
|
||||
void (*totemrrp_log_printf) (int subsys, const char *function,
|
||||
const char *file, int line, unsigned int level, unsigned int tag,
|
||||
const char *file, int line, unsigned int level, unsigned int rec_ident,
|
||||
const char *format, ...)__attribute__((format(printf, 7, 8)));
|
||||
|
||||
hdb_handle_t handle;
|
||||
@ -467,11 +468,13 @@ struct rrp_algo *rrp_algos[] = {
|
||||
*/
|
||||
DECLARE_HDB_DATABASE (totemrrp_instance_database,NULL);
|
||||
|
||||
#define RECID_LOG UINT_MAX - 1
|
||||
|
||||
#define log_printf(level, format, args...) \
|
||||
do { \
|
||||
rrp_instance->totemrrp_log_printf ( \
|
||||
rrp_instance->totemrrp_subsys_id, \
|
||||
__FUNCTION__, __FILE__, __LINE__, level, 0, \
|
||||
__FUNCTION__, __FILE__, __LINE__, level, RECID_LOG, \
|
||||
format, ##args); \
|
||||
} while (0);
|
||||
|
||||
|
@ -69,6 +69,7 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/poll.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <corosync/swab.h>
|
||||
#include <corosync/cs_queue.h>
|
||||
@ -435,7 +436,7 @@ struct totemsrp_instance {
|
||||
|
||||
void (*totemsrp_log_printf) (int subsys,
|
||||
const char *function, const char *file,
|
||||
int line, unsigned int level, unsigned int tag,
|
||||
int line, unsigned int level, unsigned int rec_ident,
|
||||
const char *format, ...)__attribute__((format(printf, 7, 8)));;
|
||||
|
||||
enum memb_state memb_state;
|
||||
@ -621,10 +622,12 @@ struct message_handlers totemsrp_message_handlers = {
|
||||
|
||||
static const char *rundir = NULL;
|
||||
|
||||
#define RECID_LOG UINT_MAX - 1
|
||||
|
||||
#define log_printf(level, format, args...) \
|
||||
do { \
|
||||
instance->totemsrp_log_printf (instance->totemsrp_subsys_id, \
|
||||
__FUNCTION__, __FILE__, __LINE__, level, 0, \
|
||||
__FUNCTION__, __FILE__, __LINE__, level, RECID_LOG, \
|
||||
format, ##args); \
|
||||
} while (0);
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include <pthread.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -70,32 +71,24 @@ extern "C" {
|
||||
#define LOGSYS_LEVEL_DEBUG LOG_DEBUG
|
||||
|
||||
/*
|
||||
* All of the LOGSYS_TAG's can be ORed together for combined behavior
|
||||
* All of the LOGSYS_RECID's are mutually exclusive. Only one RECID at any time
|
||||
* can be specified.
|
||||
*
|
||||
* TAG_LOG controls the behaviour for tracing and it's mostly for internal
|
||||
* use only. Enable it to see tracing messages in normal log output.
|
||||
* Disable to record tracing only in the flight recorder.
|
||||
* logging via log_printf will set TAG_LOG automatically.
|
||||
*
|
||||
* ENTER/LEAVE/TRACE* will not set TAG_LOG.
|
||||
*
|
||||
* All tracing messages have priority set to LOGSYS_LEVEL_DEBUG and cannot
|
||||
* be changed.
|
||||
*
|
||||
* Enabling output for debug will not enable logging of tracing messages
|
||||
* automatically. Tracing has to be enabled explicitly.
|
||||
* RECID_LOG indicates a message that should be sent to log. Anything else
|
||||
* is stored only in the flight recorder.
|
||||
*/
|
||||
#define LOGSYS_TAG_LOG (1<<0)
|
||||
#define LOGSYS_TAG_ENTER (1<<1)
|
||||
#define LOGSYS_TAG_LEAVE (1<<2)
|
||||
#define LOGSYS_TAG_TRACE1 (1<<3)
|
||||
#define LOGSYS_TAG_TRACE2 (1<<4)
|
||||
#define LOGSYS_TAG_TRACE3 (1<<5)
|
||||
#define LOGSYS_TAG_TRACE4 (1<<6)
|
||||
#define LOGSYS_TAG_TRACE5 (1<<7)
|
||||
#define LOGSYS_TAG_TRACE6 (1<<8)
|
||||
#define LOGSYS_TAG_TRACE7 (1<<9)
|
||||
#define LOGSYS_TAG_TRACE8 (1<<10)
|
||||
#define LOGSYS_RECID_LOG UINT_MAX - 1
|
||||
#define LOGSYS_RECID_ENTER UINT_MAX - 2
|
||||
#define LOGSYS_RECID_LEAVE UINT_MAX - 3
|
||||
#define LOGSYS_RECID_TRACE1 UINT_MAX - 4
|
||||
#define LOGSYS_RECID_TRACE2 UINT_MAX - 5
|
||||
#define LOGSYS_RECID_TRACE3 UINT_MAX - 6
|
||||
#define LOGSYS_RECID_TRACE4 UINT_MAX - 7
|
||||
#define LOGSYS_RECID_TRACE5 UINT_MAX - 8
|
||||
#define LOGSYS_RECID_TRACE6 UINT_MAX - 9
|
||||
#define LOGSYS_RECID_TRACE7 UINT_MAX - 10
|
||||
#define LOGSYS_RECID_TRACE8 UINT_MAX - 11
|
||||
|
||||
|
||||
/*
|
||||
* Internal APIs that must be globally exported
|
||||
@ -118,8 +111,7 @@ extern int _logsys_system_setup(
|
||||
const char *logfile,
|
||||
int logfile_priority,
|
||||
int syslog_facility,
|
||||
int syslog_priority,
|
||||
unsigned int tags);
|
||||
int syslog_priority);
|
||||
|
||||
extern int _logsys_config_subsys_get (
|
||||
const char *subsys);
|
||||
@ -134,7 +126,7 @@ extern void _logsys_log_vprintf (
|
||||
const char *file_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int tag,
|
||||
unsigned int rec_ident,
|
||||
const char *format,
|
||||
va_list ap) __attribute__((format(printf, 7, 0)));
|
||||
|
||||
@ -144,7 +136,7 @@ extern void _logsys_log_printf (
|
||||
const char *file_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int tag,
|
||||
unsigned int rec_ident,
|
||||
const char *format,
|
||||
...) __attribute__((format(printf, 7, 8)));
|
||||
|
||||
@ -153,8 +145,8 @@ extern void _logsys_log_rec (
|
||||
const char *function_name,
|
||||
const char *file_name,
|
||||
int file_line,
|
||||
unsigned int level,
|
||||
unsigned int rec_ident,
|
||||
unsigned int tag,
|
||||
...);
|
||||
|
||||
extern int _logsys_wthread_create (void);
|
||||
@ -215,13 +207,6 @@ extern unsigned int logsys_config_mode_set (
|
||||
extern unsigned int logsys_config_mode_get (
|
||||
const char *subsys);
|
||||
|
||||
extern unsigned int logsys_config_tags_set (
|
||||
const char *subsys,
|
||||
unsigned int tags);
|
||||
|
||||
extern unsigned int logsys_config_tags_get (
|
||||
const char *subsys);
|
||||
|
||||
/*
|
||||
* to close a logfile, just invoke this function with a NULL
|
||||
* file or if you want to change logfile, the old one will
|
||||
@ -248,7 +233,7 @@ extern unsigned int logsys_config_debug_set (
|
||||
/*
|
||||
* External API - helpers
|
||||
*
|
||||
* convert facility/priority/tag to/from name/values
|
||||
* convert facility/priority to/from name/values
|
||||
*/
|
||||
extern int logsys_facility_id_get (
|
||||
const char *name);
|
||||
@ -262,12 +247,6 @@ extern int logsys_priority_id_get (
|
||||
extern const char *logsys_priority_name_get (
|
||||
unsigned int priority);
|
||||
|
||||
extern int logsys_tag_id_get (
|
||||
const char *name);
|
||||
|
||||
extern const char *logsys_tag_name_get (
|
||||
unsigned int tag);
|
||||
|
||||
extern int logsys_thread_priority_set (
|
||||
int policy,
|
||||
const struct sched_param *param,
|
||||
@ -281,12 +260,12 @@ extern void *logsys_rec_end;
|
||||
#define LOGSYS_REC_END (&logsys_rec_end)
|
||||
|
||||
#define LOGSYS_DECLARE_SYSTEM(name,mode,debug,file,file_priority, \
|
||||
syslog_facility,syslog_priority,tags,format,rec_size) \
|
||||
syslog_facility,syslog_priority,format,rec_size) \
|
||||
__attribute__ ((constructor)) \
|
||||
static void logsys_system_init (void) \
|
||||
{ \
|
||||
if (_logsys_system_setup (name,mode,debug,file,file_priority, \
|
||||
syslog_facility,syslog_priority,tags) < 0) { \
|
||||
syslog_facility,syslog_priority) < 0) { \
|
||||
fprintf (stderr, \
|
||||
"Unable to setup logging system: %s.\n", name); \
|
||||
exit (-1); \
|
||||
@ -327,75 +306,75 @@ static void logsys_subsys_init (void) \
|
||||
#define log_rec(rec_ident, args...) \
|
||||
do { \
|
||||
_logsys_log_rec (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, rec_ident, 0, ##args); \
|
||||
__FILE__, __LINE__, rec_ident, 0, ##args, \
|
||||
LOGSYS_REC_END); \
|
||||
} while(0)
|
||||
|
||||
#define log_printf(lvl, format, args...) \
|
||||
#define log_printf(level, format, args...) \
|
||||
do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, lvl, 0, format, ##args); \
|
||||
__FILE__, __LINE__, level, LOGSYS_RECID_LOG, \
|
||||
format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define ENTER() do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
_logsys_log_rec (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_ENTER, "ENTERING function [%s] line [%d]\n", \
|
||||
__FUNCTION__, __LINE__); \
|
||||
LOGSYS_RECID_ENTER, LOGSYS_REC_END); \
|
||||
} while(0)
|
||||
|
||||
#define LEAVE() do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
_logsys_log_rec (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_LEAVE, "LEAVING function [%s] line [%d]\n", \
|
||||
__FUNCTION__, __LINE__); \
|
||||
LOGSYS_RECID_LEAVE, LOGSYS_REC_END); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE1(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE1, format, ##args); \
|
||||
LOGSYS_RECID_TRACE1, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE2(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE2, format, ##args); \
|
||||
LOGSYS_RECID_TRACE2, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE3(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE3, format, ##args); \
|
||||
LOGSYS_RECID_TRACE3, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE4(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE4, format, ##args); \
|
||||
LOGSYS_RECID_TRACE4, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE5(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE5, format, ##args); \
|
||||
LOGSYS_RECID_TRACE5, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE6(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE6, format, ##args); \
|
||||
LOGSYS_RECID_TRACE6, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE7(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE7, format, ##args); \
|
||||
LOGSYS_RECID_TRACE7, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#define TRACE8(format, args...) do { \
|
||||
_logsys_log_printf (logsys_subsys_id, __FUNCTION__, \
|
||||
__FILE__, __LINE__, LOGSYS_LEVEL_DEBUG, \
|
||||
LOGSYS_TAG_TRACE8, format, ##args); \
|
||||
LOGSYS_RECID_TRACE8, format, ##args); \
|
||||
} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -46,7 +46,6 @@ LOGSYS_DECLARE_SYSTEM ("logsystestsubsystems",
|
||||
LOGSYS_LEVEL_INFO,
|
||||
LOG_DAEMON,
|
||||
LOGSYS_LEVEL_INFO,
|
||||
0,
|
||||
NULL,
|
||||
1000000);
|
||||
|
||||
|
@ -46,7 +46,6 @@ LOGSYS_DECLARE_SYSTEM ("logsystestNOsubsystems",
|
||||
LOGSYS_LEVEL_DEBUG,
|
||||
LOG_DAEMON,
|
||||
LOGSYS_LEVEL_DEBUG,
|
||||
0,
|
||||
NULL,
|
||||
1000000);
|
||||
|
||||
|
@ -46,7 +46,6 @@ LOGSYS_DECLARE_SYSTEM ("logtest_t2",
|
||||
LOGSYS_LEVEL_INFO,
|
||||
LOG_DAEMON,
|
||||
LOGSYS_LEVEL_INFO,
|
||||
0,
|
||||
NULL,
|
||||
1000000);
|
||||
|
||||
|
@ -48,7 +48,6 @@ LOGSYS_DECLARE_SYSTEM ("logtest_rec",
|
||||
LOGSYS_LEVEL_INFO, /* logfile_priority */
|
||||
LOG_DAEMON, /* syslog facility */
|
||||
LOGSYS_LEVEL_INFO, /* syslog level */
|
||||
0, /* tags */
|
||||
NULL, /* use default format */
|
||||
1000000); /* flight recorder size */
|
||||
|
||||
|
@ -45,7 +45,6 @@ LOGSYS_DECLARE_SYSTEM ("logtest_rec",
|
||||
LOG_INFO,
|
||||
LOG_DAEMON,
|
||||
LOG_INFO,
|
||||
0,
|
||||
NULL,
|
||||
100000);
|
||||
|
||||
|
@ -370,7 +370,7 @@ static void logsys_rec_print (const void *record)
|
||||
const unsigned int *buf_uint32t = record;
|
||||
unsigned int rec_size;
|
||||
unsigned int rec_ident;
|
||||
unsigned int tag;
|
||||
unsigned int level;
|
||||
unsigned int line;
|
||||
unsigned int arg_size_idx;
|
||||
unsigned int i;
|
||||
@ -383,8 +383,8 @@ static void logsys_rec_print (const void *record)
|
||||
int arg_count = 0;
|
||||
|
||||
rec_size = buf_uint32t[rec_idx];
|
||||
rec_ident = buf_uint32t[rec_idx+1];
|
||||
tag = buf_uint32t[rec_idx+2];
|
||||
level = buf_uint32t[rec_idx+1];
|
||||
rec_ident = buf_uint32t[rec_idx+2];
|
||||
line = buf_uint32t[rec_idx+3];
|
||||
record_number = buf_uint32t[rec_idx+4];
|
||||
|
||||
@ -405,31 +405,51 @@ static void logsys_rec_print (const void *record)
|
||||
for (j = 0; j < printer_subsystems[i].record_printers_count; j++) {
|
||||
if (rec_ident == printer_subsystems[i].record_printers[j].ident) {
|
||||
printer_subsystems[i].record_printers[j].print_fn ((const void **)&arguments[3]);
|
||||
found = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tag & LOGSYS_TAG_ENTER) {
|
||||
printf ("ENTERING function [%s] line [%d]\n", arguments[2], line);
|
||||
found = 1;
|
||||
}
|
||||
if (tag & LOGSYS_TAG_LEAVE) {
|
||||
printf ("LEAVING function [%s] line [%d]\n", arguments[2], line);
|
||||
found = 1;
|
||||
}
|
||||
if (found == 1) {
|
||||
tag &= ~LOGSYS_TAG_LOG;
|
||||
}
|
||||
if (tag & LOGSYS_TAG_LOG) {
|
||||
printf ("Log Message=%s\n", arguments[3]);
|
||||
found = 1;
|
||||
}
|
||||
if (found == 0) {
|
||||
printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
|
||||
arguments[0], rec_ident);
|
||||
}
|
||||
|
||||
switch(rec_ident) {
|
||||
case LOGSYS_RECID_LOG:
|
||||
printf ("Log Message=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_ENTER:
|
||||
printf ("ENTERING function [%s] line [%d]\n", arguments[2], line);
|
||||
break;
|
||||
case LOGSYS_RECID_LEAVE:
|
||||
printf ("LEAVING function [%s] line [%d]\n", arguments[2], line);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE1:
|
||||
printf ("Tracing(1) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE2:
|
||||
printf ("Tracing(2) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE3:
|
||||
printf ("Tracing(3) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE4:
|
||||
printf ("Tracing(4) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE5:
|
||||
printf ("Tracing(5) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE6:
|
||||
printf ("Tracing(6) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE7:
|
||||
printf ("Tracing(7) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
case LOGSYS_RECID_TRACE8:
|
||||
printf ("Tracing(8) Messsage=%s\n", arguments[3]);
|
||||
break;
|
||||
default:
|
||||
printf ("Unknown record type found subsys=[%s] ident=[%d]\n",
|
||||
arguments[0], rec_ident);
|
||||
break;
|
||||
}
|
||||
#ifdef COMPILE_OUT
|
||||
printf ("\n");
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user