Emits level and subsystem in log output
This commit is contained in:
parent
58ee07587e
commit
451db24c6e
51
src/crypto.c
51
src/crypto.c
@ -690,8 +690,6 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
|
||||
} else
|
||||
if( sqlite3_stricmp(zLeft, "cipher_log_level")==0 ){
|
||||
unsigned int level = SQLCIPHER_LOG_NONE;
|
||||
char *out = NULL;
|
||||
|
||||
if(zRight) {
|
||||
if(sqlite3_stricmp(zRight, "ERROR")==0) level = SQLCIPHER_LOG_ERROR;
|
||||
else if(sqlite3_stricmp(zRight, "WARN" )==0) level = SQLCIPHER_LOG_WARN;
|
||||
@ -702,35 +700,10 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
|
||||
} else {
|
||||
level = sqlcipher_get_log_level();
|
||||
}
|
||||
switch(level) {
|
||||
case SQLCIPHER_LOG_NONE:
|
||||
out = "NONE";
|
||||
break;
|
||||
case SQLCIPHER_LOG_ERROR:
|
||||
out = "ERROR";
|
||||
break;
|
||||
case SQLCIPHER_LOG_WARN:
|
||||
out = "WARN";
|
||||
break;
|
||||
case SQLCIPHER_LOG_INFO:
|
||||
out = "INFO";
|
||||
break;
|
||||
case SQLCIPHER_LOG_DEBUG:
|
||||
out = "DEBUG";
|
||||
break;
|
||||
case SQLCIPHER_LOG_TRACE:
|
||||
out = "TRACE";
|
||||
break;
|
||||
case SQLCIPHER_LOG_ALL:
|
||||
out = "ALL";
|
||||
break;
|
||||
}
|
||||
sqlcipher_vdbe_return_string(pParse, "cipher_log_level", out, P4_TRANSIENT);
|
||||
sqlcipher_vdbe_return_string(pParse, "cipher_log_level", sqlcipher_get_log_subsystem_str(level), P4_TRANSIENT);
|
||||
} else
|
||||
if( sqlite3_stricmp(zLeft, "cipher_log_subsystem")==0 ){
|
||||
unsigned int subsys = SQLCIPHER_LOG_NONE;
|
||||
char *out = NULL;
|
||||
|
||||
if(zRight) {
|
||||
if(sqlite3_stricmp(zRight, "NONE" )==0) subsys = SQLCIPHER_LOG_NONE;
|
||||
else if(sqlite3_stricmp(zRight, "ALL" )==0) subsys = SQLCIPHER_LOG_ALL;
|
||||
@ -742,27 +715,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef
|
||||
} else {
|
||||
subsys = sqlcipher_get_log_subsystem();
|
||||
}
|
||||
switch(subsys) {
|
||||
case SQLCIPHER_LOG_NONE:
|
||||
out = "NONE";
|
||||
break;
|
||||
case SQLCIPHER_LOG_ALL:
|
||||
out = "ALL";
|
||||
break;
|
||||
case SQLCIPHER_LOG_CORE:
|
||||
out = "CORE";
|
||||
break;
|
||||
case SQLCIPHER_LOG_MEMORY:
|
||||
out = "MEMORY";
|
||||
break;
|
||||
case SQLCIPHER_LOG_MUTEX:
|
||||
out = "MUTEX";
|
||||
break;
|
||||
case SQLCIPHER_LOG_PROVIDER:
|
||||
out = "PROVIDER";
|
||||
break;
|
||||
}
|
||||
sqlcipher_vdbe_return_string(pParse, "cipher_log_subsystem", out, P4_TRANSIENT);
|
||||
sqlcipher_vdbe_return_string(pParse, "cipher_log_subsystem", sqlcipher_get_log_subsystem_str(subsys), P4_TRANSIENT);
|
||||
} else
|
||||
if( sqlite3_stricmp(zLeft, "cipher_log")== 0 && zRight ){
|
||||
char *status = sqlite3_mprintf("%d", sqlcipher_set_log(zRight));
|
||||
|
||||
@ -335,6 +335,9 @@ unsigned int sqlcipher_get_log_level();
|
||||
void sqlcipher_set_log_subsystem(unsigned int subsys);
|
||||
unsigned int sqlcipher_get_log_subsystem();
|
||||
|
||||
char *sqlcipher_get_log_level_str(unsigned int);
|
||||
char *sqlcipher_get_log_subsystem_str(unsigned int);
|
||||
|
||||
#define SQLCIPHER_LOG_NONE 0x00
|
||||
#define SQLCIPHER_LOG_ERROR 0x01
|
||||
#define SQLCIPHER_LOG_WARN 0x02
|
||||
|
||||
@ -1733,14 +1733,52 @@ const char* sqlcipher_codec_get_provider_version(codec_ctx *ctx) {
|
||||
return ctx->provider->get_provider_version(ctx->provider_ctx);
|
||||
}
|
||||
|
||||
char *sqlcipher_get_log_level_str(unsigned int level) {
|
||||
switch(level) {
|
||||
case SQLCIPHER_LOG_ERROR:
|
||||
return "ERROR";
|
||||
case SQLCIPHER_LOG_WARN:
|
||||
return "WARN";
|
||||
case SQLCIPHER_LOG_INFO:
|
||||
return "INFO";
|
||||
case SQLCIPHER_LOG_DEBUG:
|
||||
return "DEBUG";
|
||||
case SQLCIPHER_LOG_TRACE:
|
||||
return "TRACE";
|
||||
case SQLCIPHER_LOG_ALL:
|
||||
return "ALL";
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
|
||||
char *sqlcipher_get_log_subsystem_str(unsigned int subsys) {
|
||||
switch(subsys) {
|
||||
case SQLCIPHER_LOG_NONE:
|
||||
return "NONE";
|
||||
case SQLCIPHER_LOG_CORE:
|
||||
return "CORE";
|
||||
case SQLCIPHER_LOG_MEMORY:
|
||||
return "MEMORY";
|
||||
case SQLCIPHER_LOG_MUTEX:
|
||||
return "MUTEX";
|
||||
case SQLCIPHER_LOG_PROVIDER:
|
||||
return "PROVIDER";
|
||||
}
|
||||
return "ALL";
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLCIPHER_OMIT_LOG
|
||||
/* constants from https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-crt/misc/gettimeofday.c */
|
||||
#define FILETIME_1970 116444736000000000ull /* seconds between 1/1/1601 and 1/1/1970 */
|
||||
#define HECTONANOSEC_PER_SEC 10000000ull
|
||||
#define MAX_LOG_LEN 8192
|
||||
void sqlcipher_log(unsigned int level, unsigned int subsys, const char *message, ...) {
|
||||
va_list params;
|
||||
va_start(params, message);
|
||||
char *formatted = NULL;
|
||||
char formatted[MAX_LOG_LEN];
|
||||
char *out = NULL;
|
||||
int len = 0;
|
||||
|
||||
#ifdef CODEC_DEBUG
|
||||
#if defined(SQLCIPHER_OMIT_LOG_DEVICE)
|
||||
@ -1772,15 +1810,17 @@ void sqlcipher_log(unsigned int level, unsigned int subsys, const char *message,
|
||||
goto end;
|
||||
}
|
||||
|
||||
sqlite3_snprintf(MAX_LOG_LEN, formatted, "%s %s |", sqlcipher_get_log_level_str(level), sqlcipher_get_log_subsystem_str(subsys));
|
||||
len = strlen(formatted);
|
||||
sqlite3_vsnprintf(MAX_LOG_LEN - len, formatted + len, message, params);
|
||||
|
||||
#if !defined(SQLCIPHER_OMIT_LOG_DEVICE)
|
||||
if(sqlcipher_log_device) {
|
||||
#if defined(__ANDROID__)
|
||||
__android_log_vprint(ANDROID_LOG_DEBUG, "sqlcipher", message, params);
|
||||
__android_log_vprint(ANDROID_LOG_DEBUG, "sqlcipher", formatted);
|
||||
goto end;
|
||||
#elif defined(__APPLE__)
|
||||
formatted = sqlite3_vmprintf(message, params);
|
||||
#elif defined(__APPLEformattes__)
|
||||
os_log(OS_LOG_DEFAULT, "%{public}s", formatted);
|
||||
sqlite3_free(formatted);
|
||||
goto end;
|
||||
#endif
|
||||
}
|
||||
@ -1807,9 +1847,7 @@ void sqlcipher_log(unsigned int level, unsigned int subsys, const char *message,
|
||||
localtime_r(&sec, &tt);
|
||||
#endif
|
||||
if(strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tt)) {
|
||||
fprintf((FILE*)sqlcipher_log_file, "%s.%03d: ", buffer, ms);
|
||||
vfprintf((FILE*)sqlcipher_log_file, message, params);
|
||||
fprintf((FILE*)sqlcipher_log_file, "\n");
|
||||
fprintf((FILE*)sqlcipher_log_file, "%s.%03d: %s\n", buffer, ms, formatted);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user