Add a logging subsystem and change all DPRINTF to ISCSI_LOG

Add a mechanism where we can set a logging subsystem that libiscsi can use.
Create an example 'log to stderr' that utilities can use for convenience.
This commit is contained in:
Ronnie Sahlberg
2012-11-07 06:34:38 -08:00
parent c10ae3ae3e
commit 50e7c682bb
13 changed files with 134 additions and 51 deletions

View File

@@ -127,7 +127,9 @@ struct iscsi_context {
int lun;
int no_auto_reconnect;
int reconnect_deferred;
int debug;
int log_level;
iscsi_log_fn log_fn;
};
#define ISCSI_PDU_IMMEDIATE 0x40
@@ -284,6 +286,16 @@ struct scsi_task *iscsi_scsi_get_task_from_pdu(struct iscsi_pdu *pdu);
void iscsi_set_noautoreconnect(struct iscsi_context *iscsi, int state);
#define ISCSI_LOG(iscsi, level, format, args...) \
do { \
if (level <= iscsi->log_level && iscsi->log_fn) { \
iscsi_log_message(iscsi, level, format, ## args); \
} \
} while (0)
void
iscsi_log_message(struct iscsi_context *iscsi, int level, const char *format, ...);
#ifdef __cplusplus
}
#endif

View File

@@ -966,18 +966,6 @@ iscsi_scsi_task_cancel(struct iscsi_context *iscsi,
EXTERN void
iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi);
#define DPRINTF(iscsi,level,fmt,args...) \
do { \
if ((iscsi)->debug >= level) { \
fprintf(stderr,"libiscsi: "); \
fprintf(stderr, (fmt), ##args); \
if (iscsi->target_name[0]) { \
fprintf(stderr," [%s]",iscsi->target_name); \
} \
fprintf(stderr,"\n"); \
} \
} while (0);
/*
* This function is to set the debugging level where level is
*
@@ -987,9 +975,18 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi);
* 3 = user set variables
* 4 = function calls
* 5 = ...
* 10 = everything
*/
EXTERN void
iscsi_set_debug(struct iscsi_context *iscsi, int level);
iscsi_set_log_level(struct iscsi_context *iscsi, int level);
typedef void (*iscsi_log_fn)(int level, const char *mesage);
/* Set the logging function to use */
EXTERN void iscsi_set_log_fn(struct iscsi_context *iscsi, iscsi_log_fn fn);
/* predefined log function that just writes to stderr */
EXTERN void iscsi_log_to_stderr(int level, const char *message);
/*
* This function is to set the TCP_USER_TIMEOUT option. It has to be called after iscsi