From d3239fc44487dea3f6ec6447b9f16b23cfa5d51d Mon Sep 17 00:00:00 2001 From: Rich Prohaska Date: Fri, 11 Jan 2008 16:14:54 +0000 Subject: [PATCH] implement DbEnv::set_error_stream closes #255 git-svn-id: file:///svn/tokudb@1603 c7de825b-a66e-492c-adef-691d508d4ae1 --- cxx/dbenv.cpp | 13 ++++++++++++- include/db_cxx.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cxx/dbenv.cpp b/cxx/dbenv.cpp index 7c57a487f9b..0a047826e16 100644 --- a/cxx/dbenv.cpp +++ b/cxx/dbenv.cpp @@ -12,7 +12,7 @@ DbEnv::DbEnv (u_int32_t flags) } DbEnv::DbEnv(DB_ENV *env, u_int32_t flags) - : do_no_exceptions((flags&DB_CXX_NO_EXCEPTIONS)!=0) + : do_no_exceptions((flags&DB_CXX_NO_EXCEPTIONS)!=0), _error_stream(0) { the_env = env; if (env == 0) { @@ -126,6 +126,17 @@ void DbEnv::set_errcall(void (*db_errcall_fcn)(const DbEnv *, const char *, cons the_env->set_errcall(the_env, toku_db_env_errcall_c); } +extern "C" void toku_db_env_error_stream_c(const DB_ENV *dbenv_c, const char *errpfx, const char *msg) { + DbEnv *dbenv = (DbEnv *) dbenv_c->api1_internal; + if (dbenv->_error_stream) + *dbenv->_error_stream << errpfx << ":" << msg << "\n"; +} + +void DbEnv::set_error_stream(std::ostream *new_error_stream) { + _error_stream = new_error_stream; + the_env->set_errcall(the_env, toku_db_env_error_stream_c); +} + // locking not yet implemented int DbEnv::set_lk_max_locks(u_int32_t max_locks) { diff --git a/include/db_cxx.h b/include/db_cxx.h index 2cd645ef07c..e4be684432c 100644 --- a/include/db_cxx.h +++ b/include/db_cxx.h @@ -1,4 +1,5 @@ #include +#include #include #include #ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." @@ -161,6 +162,7 @@ class DbEnv { void err(int error, const char *fmt, ...); void set_errfile(FILE *errfile); void set_errcall(void (*)(const DbEnv *, const char *, const char *)); + void set_error_stream(std::ostream *); int get_flags(u_int32_t *flagsp); // locking @@ -178,6 +180,7 @@ class DbEnv { // somewhat_private: int do_no_exceptions; // This should be private!!! void (*errcall)(const DbEnv *, const char *, const char *); + std::ostream *_error_stream; private: DB_ENV *the_env;