mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 20:30:04 +01:00
Log all debug messages through log callback.
This cahnge allow to redirect all output of library to a log processor.
This commit is contained in:
25
lib/setup.c
25
lib/setup.c
@@ -141,12 +141,17 @@ void crypt_log(struct crypt_device *cd, int level, const char *msg)
|
||||
{
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
if (level < _debug_level)
|
||||
return;
|
||||
|
||||
if (cd && cd->log)
|
||||
cd->log(level, msg, cd->log_usrptr);
|
||||
else if (_default_log)
|
||||
_default_log(level, msg, NULL);
|
||||
else if (_debug_level)
|
||||
printf("%s", msg);
|
||||
/* Default to stdout/stderr if there is no callback. */
|
||||
else
|
||||
fprintf(level == CRYPT_LOG_ERROR ? stderr : stdout, "%s", msg);
|
||||
}
|
||||
|
||||
__attribute__((format(printf, 5, 6)))
|
||||
@@ -159,19 +164,11 @@ void logger(struct crypt_device *cd, int level, const char *file,
|
||||
va_start(argp, format);
|
||||
|
||||
if (vsnprintf(&target[0], LOG_MAX_LEN, format, argp) > 0 ) {
|
||||
if (level >= 0) {
|
||||
/* All verbose and error messages in tools end with EOL. */
|
||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR)
|
||||
strncat(target, "\n", LOG_MAX_LEN);
|
||||
/* All verbose and error messages in tools end with EOL. */
|
||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR)
|
||||
strncat(target, "\n", LOG_MAX_LEN);
|
||||
|
||||
crypt_log(cd, level, target);
|
||||
#ifdef CRYPT_DEBUG
|
||||
} else if (_debug_level)
|
||||
printf("# %s:%d %s\n", file ?: "?", line, target);
|
||||
#else
|
||||
} else if (_debug_level)
|
||||
printf("# %s\n", target);
|
||||
#endif
|
||||
crypt_log(cd, level, target);
|
||||
}
|
||||
|
||||
va_end(argp);
|
||||
|
||||
@@ -2738,7 +2738,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
if (opt_debug) {
|
||||
opt_verbose = 1;
|
||||
crypt_set_debug_level(-1);
|
||||
crypt_set_debug_level(CRYPT_DEBUG_ALL);
|
||||
dbg_version_and_cmd(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,19 +88,11 @@ void clogger(struct crypt_device *cd, int level, const char *file, int line,
|
||||
va_start(argp, format);
|
||||
|
||||
if (vsnprintf(&target[0], LOG_MAX_LEN, format, argp) > 0) {
|
||||
if (level >= 0) {
|
||||
/* All verbose and error messages in tools end with EOL. */
|
||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR)
|
||||
strncat(target, "\n", LOG_MAX_LEN);
|
||||
/* All verbose and error messages in tools end with EOL. */
|
||||
if (level == CRYPT_LOG_VERBOSE || level == CRYPT_LOG_ERROR)
|
||||
strncat(target, "\n", LOG_MAX_LEN);
|
||||
|
||||
crypt_log(cd, level, target);
|
||||
#ifdef CRYPT_DEBUG
|
||||
} else if (opt_debug)
|
||||
printf("# %s:%d %s\n", file ?: "?", line, target);
|
||||
#else
|
||||
} else if (opt_debug)
|
||||
printf("# %s\n", target);
|
||||
#endif
|
||||
crypt_log(cd, level, target);
|
||||
}
|
||||
|
||||
va_end(argp);
|
||||
@@ -111,21 +103,18 @@ void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)))
|
||||
switch(level) {
|
||||
|
||||
case CRYPT_LOG_NORMAL:
|
||||
fputs(msg, stdout);
|
||||
fprintf(stdout, "%s", msg);
|
||||
break;
|
||||
case CRYPT_LOG_VERBOSE:
|
||||
if (opt_verbose)
|
||||
fputs(msg, stdout);
|
||||
fprintf(stdout, "%s", msg);
|
||||
break;
|
||||
case CRYPT_LOG_ERROR:
|
||||
fputs(msg, stderr);
|
||||
fprintf(stderr, "%s", msg);
|
||||
break;
|
||||
case CRYPT_LOG_DEBUG:
|
||||
if (opt_debug)
|
||||
printf("# %s\n", msg);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Internal error on logging class for msg: %s", msg);
|
||||
fprintf(stdout, "# %s\n", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,8 +256,16 @@ void global_log_callback(int level, const char *msg, void *usrptr)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (_debug)
|
||||
printf("LOG: %s", msg);
|
||||
if (_debug) {
|
||||
if (level == CRYPT_LOG_DEBUG)
|
||||
fprintf(stdout, "# %s\n", msg);
|
||||
else
|
||||
fprintf(stdout, "%s", msg);
|
||||
}
|
||||
|
||||
if (level == CRYPT_LOG_DEBUG)
|
||||
return;
|
||||
|
||||
strncat(global_log, msg, sizeof(global_log) - strlen(global_log));
|
||||
global_lines++;
|
||||
if (level == CRYPT_LOG_ERROR) {
|
||||
|
||||
Reference in New Issue
Block a user