diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/global.c | 2 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/printf.c | 22 | ||||
-rw-r--r-- | src/sqlite.h.in | 16 | ||||
-rw-r--r-- | src/sqliteInt.h | 2 |
5 files changed, 51 insertions, 1 deletions
diff --git a/src/global.c b/src/global.c index bdfd1ff29..673a274cc 100644 --- a/src/global.c +++ b/src/global.c @@ -164,6 +164,8 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = { 0, /* isPCacheInit */ 0, /* pInitMutex */ 0, /* nRefInitMutex */ + 0, /* xLog */ + 0, /* pLogArg */ }; diff --git a/src/main.c b/src/main.c index 07fe15ce7..e4419d269 100644 --- a/src/main.c +++ b/src/main.c @@ -378,6 +378,16 @@ int sqlite3_config(int op, ...){ sqlite3GlobalConfig.nLookaside = va_arg(ap, int); break; } + + /* Record a pointer to the logger funcction and its first argument. + ** The default is NULL. Logging is disabled if the function pointer is + ** NULL. + */ + case SQLITE_CONFIG_LOG: { + sqlite3GlobalConfig.xLog = va_arg(ap, void(*)(void*,int,const char*)); + sqlite3GlobalConfig.pLogArg = va_arg(ap, void*); + break; + } default: { rc = SQLITE_ERROR; diff --git a/src/printf.c b/src/printf.c index fdd4793c3..2966946f9 100644 --- a/src/printf.c +++ b/src/printf.c @@ -939,6 +939,28 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ return z; } +/* +** Format and write a message to the log if logging is enabled. +*/ +void sqlite3_log(int iPriority, const char *zFormat, ...){ + void (*xLog)(void*, int, const char*); /* The global logger function */ + void *pLogArg; /* First argument to the logger */ + va_list ap; /* Vararg list */ + char *zMsg; /* Complete log message */ + + xLog = sqlite3GlobalConfig.xLog; + if( xLog ){ + va_start(ap, zFormat); + sqlite3BeginBenignMalloc(); + zMsg = sqlite3_vmprintf(zFormat, ap); + sqlite3EndBenignMalloc(); + va_end(ap); + pLogArg = sqlite3GlobalConfig.pLogArg; + xLog(pLogArg, iPriority, zMsg ? zMsg : zFormat); + sqlite3_free(zMsg); + } +} + #if defined(SQLITE_DEBUG) /* ** A version of printf() that understands %lld. Used for debugging. diff --git a/src/sqlite.h.in b/src/sqlite.h.in index e1b8dc61f..bd610834e 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -914,7 +914,6 @@ int sqlite3_os_end(void); /* ** CAPI3REF: Configuring The SQLite Library -** EXPERIMENTAL ** ** The sqlite3_config() interface is used to make global configuration ** changes to SQLite in order to tune SQLite to the specific needs of @@ -1255,6 +1254,7 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ +#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ /* ** CAPI3REF: Configuration Options @@ -5664,6 +5664,20 @@ int sqlite3_unlock_notify( int sqlite3_strnicmp(const char *, const char *, int); /* +** CAPI3REF: Error Logging Interface +** EXPERIMENTAL +** +** ^The [sqlite3_log()] interface writes a message into the error log +** established by the [SQLITE_CONFIG_ERRORLOG] option to [sqlite3_config()]. +** +** The sqlite3_log() interface is intended for use by extensions such as +** virtual tables, collating functions, and SQL functions. While there is +** nothing to prevent an application from calling sqlite3_log(), doing so +** is considered bad form. +*/ +void sqlite3_log(int iPriority, const char *zFormat, ...); + +/* ** Undo the hack that converts floating point types to integer for ** builds on processors without floating point support. */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index ff90e0307..a576dd682 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2370,6 +2370,8 @@ struct Sqlite3Config { int isPCacheInit; /* True after malloc is initialized */ sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */ int nRefInitMutex; /* Number of users of pInitMutex */ + void (*xLog)(void*,int,const char*); /* Function for logging */ + void *pLogArg; /* First argument to xLog() */ }; /* |