Session-specific logging. Added functions

void session_enable_log(SESSION* ses, logfile_id_t id)
and
void session_disable_log(SESSION* ses, logfile_id_t id)

Which switch specific log type on/off if the log type in question is not generally enabled.

Each thread carries a thread-specific struct log_info_t which includes members for current session id and bitfield for enabled log types for the current session. That information is checked before actual log write functions are called.

Each file where session-specific logging is used, must include the following exports:

/** Defined in log_manager.cc */
extern int            lm_enabled_logfiles_bitmask;
extern size_t         log_ses_count[];
extern __thread log_info_t tls_log_info;
This commit is contained in:
VilhoRaatikka
2014-11-19 00:08:59 +02:00
parent 7ef54219a6
commit fd11e6a7f5
39 changed files with 379 additions and 133 deletions

View File

@ -42,17 +42,55 @@ typedef enum {
typedef enum { FILEWRITER_INIT, FILEWRITER_RUN, FILEWRITER_DONE }
filewriter_state_t;
/**
* Thread-specific logging information.
*/
typedef struct log_info_st
{
size_t li_sesid;
int li_enabled_logs;
} log_info_t;
#define LE LOGFILE_ERROR
#define LM LOGFILE_MESSAGE
#define LT LOGFILE_TRACE
#define LD LOGFILE_DEBUG
/**
* Check if specified log type is enabled in general or if it is enabled
* for the current session.
*/
#define LOG_IS_ENABLED(id) (((lm_enabled_logfiles_bitmask & id) || \
(log_ses_count[id] > 0 && \
tls_log_info.li_enabled_logs & id)) ? true : false)
#define LOG_MAY_BE_ENABLED(id) (((lm_enabled_logfiles_bitmask & id) || \
log_ses_count[id] > 0) ? true : false)
/**
* Execute the given command if specified log is enabled in general or
* if there is at least one session for whom the log is enabled.
*/
#define LOGIF_MAYBE(id,cmd) if (LOG_MAY_BE_ENABLED(id)) \
{ \
cmd; \
}
/**
* Execute the given command if specified log is enabled in general or
* if the log is enabled for the current session.
*/
#define LOGIF(id,cmd) if (LOG_IS_ENABLED(id)) \
{ \
cmd; \
}
#if !defined(LOGIF)
#define LOGIF(id,cmd) if (lm_enabled_logfiles_bitmask & id) \
{ \
cmd; \
} \
#define LOG_IS_ENABLED(id) ((lm_enabled_logfiles_bitmask & id) ? true : false)
{ \
cmd; \
}
#endif
/**
* UNINIT means zeroed memory buffer allocated for the struct.